I have a dependency on a library that lives in a subdirectory: libtailscale/elixir/libtailscale at elixir · Munksgaard/libtailscale · GitHub.
The library itself is a NIF interface to some C-files from the grandparent directory. Things work when I do mix compile
in the elixir/libtailscale directory, but now I’m trying to import the library in an erlang project using rebar3 and it doesn’t work.
Here is my rebar3 config:
{erl_opts, [debug_info]}.
{deps, [
{libtailscale, {git_subdir, "https://github.com/Munksgaard/libtailscale.git", {branch, "elixir"}, "elixir"}}
]}.
{plugins, [rebar_mix]}.
{provider_hooks, [{post, [{compile, {mix, consolidate_protocols}}]}]}.
{overlay, [{copy, "{{base_dir}}/consolidated", "releases/{{release_version}}/consolidated"}]}.
It seems like when I use git_subdir, it only gets the subdir specified, and not any of the contents of the parent (or grandparent) directories. As a result, the tailscale.h
file from the grandparent is not available. Here is the full output of running rebar3 compile
:
$ rebar3 compile
===> Fetching rebar_mix v0.5.1
===> Analyzing applications...
===> Compiling rebar_mix
===> Verifying dependencies...
===> Fetching libtailscale (from {git_subdir,"https://github.com/Munksgaard/libtailscale.git",
{branch,"elixir"},
"elixir/libtailscale"})
===> Compiling libtailscale
Resolving Hex dependencies...
Resolution completed in 0.013s
Unchanged:
elixir_make 0.9.0
* Getting elixir_make (Hex package)
==> elixir_make
Compiling 8 files (.ex)
Generated elixir_make app
==> libtailscale
gcc -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes -fPIC -I /nix/store/bz0kzfh2rd6ls1y8pd60pbs3nc4wr5nx-erlang-27.3/lib/erlang/erts-15.2.3/include -I /nix/store/bz0kzfh2rd6ls1y8pd60pbs3nc4wr5nx-erlang-27.3/lib/erlang/usr/include -I /home/munksgaard/src/gen_tailscale/_build/default/lib/libtailscale -c -o /home/munksgaard/src/gen_tailscale/_build/default/lib/libtailscale/elixir/libtailscale/native/libtailscale_nif.o /home/munksgaard/src/gen_tailscale/_build/default/lib/libtailscale/elixir/libtailscale/native/libtailscale_nif.c
/home/munksgaard/src/gen_tailscale/_build/default/lib/libtailscale/elixir/libtailscale/native/libtailscale_nif.c:5:10: fatal error: tailscale.h: No such file or directory
5 | #include "tailscale.h"
| ^~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:65: /home/munksgaard/src/gen_tailscale/_build/default/lib/libtailscale/elixir/libtailscale/native/libtailscale_nif.o] Error 1
** (Mix) Could not compile with "make" (exit status: 2).
You need to have gcc and make installed. If you are using
Ubuntu or any other Debian-based system, install the packages
"build-essential". Also install "erlang-dev" package if not
included in your Erlang/OTP version. If you're on Fedora, run
"dnf group install 'Development Tools'".
===> sh(mix compile)
failed with return code 1 and the following output:
==> elixir_make
Compiling 8 files (.ex)
Generated elixir_make app
==> libtailscale
gcc -O3 -std=c99 -finline-functions -Wall -Wmissing-prototypes -fPIC -I /nix/store/bz0kzfh2rd6ls1y8pd60pbs3nc4wr5nx-erlang-27.3/lib/erlang/erts-15.2.3/include -I /nix/store/bz0kzfh2rd6ls1y8pd60pbs3nc4wr5nx-erlang-27.3/lib/erlang/usr/include -I /home/munksgaard/src/gen_tailscale/_build/default/lib/libtailscale -c -o /home/munksgaard/src/gen_tailscale/_build/default/lib/libtailscale/elixir/libtailscale/native/libtailscale_nif.o /home/munksgaard/src/gen_tailscale/_build/default/lib/libtailscale/elixir/libtailscale/native/libtailscale_nif.c
/home/munksgaard/src/gen_tailscale/_build/default/lib/libtailscale/elixir/libtailscale/native/libtailscale_nif.c:5:10: fatal error: tailscale.h: No such file or directory
5 | #include "tailscale.h"
| ^~~~~~~~~~~~~
compilation terminated.
make: *** [Makefile:65: /home/munksgaard/src/gen_tailscale/_build/default/lib/libtailscale/elixir/libtailscale/native/libtailscale_nif.o] Error 1
** (Mix) Could not compile with "make" (exit status: 2).
You need to have gcc and make installed. If you are using
Ubuntu or any other Debian-based system, install the packages
"build-essential". Also install "erlang-dev" package if not
included in your Erlang/OTP version. If you're on Fedora, run
"dnf group install 'Development Tools'".
Is there any way to get rebar3 to check out the entire repository instead of just the subdir specified, while still specifying that the elixir-app used resides in the subdir?
Alternatively, is there some other way I should be structuring my projects in order to rely on a C-library in a repo I don’t control?