saleyn / erlexec

Execute and control OS processes from Erlang/OTP
https://hexdocs.pm/erlexec/readme.html
Other
527 stars 139 forks source link

Cross compiling doesn't work when part of a larger build #102

Closed electricshaman closed 7 years ago

electricshaman commented 7 years ago

When I try to build erlexec with a tool such as Buildroot, it doesn't seem to recognize the toolchain environment variables like CXX. The compiler fails when trying to find the soft stubs header file. What's odd though is that it works great when I supply the CXX path directly on the command line as a prefix.

I love this library and was hoping to use it with the Elixir project Nerves. Unfortunately I'm not familiar with rebar or else I'd submit a PR.

saleyn commented 7 years ago

This hasn't come up before, and I am not familiar with Buildroot, so unless you could address this in the PR form, I wouldn't be able to help.

electricshaman commented 7 years ago

Maybe you could point me in the right direction. I didn't give you much context. This is the sequence of steps to reproduce, once Elixir and Nerves are installed:

$ mix nerves.new erlexec_test
$ cd erlexec_test
$ export MIX_TARGET=rpi3
$ # Add erlexec 1.7 to mix.exs deps: {:erlexec, "~> 1.7"}
$ mix deps.get
$ mix firmware

Result

===> Fetching pc ({pkg,<<"pc">>,<<"1.6.0">>})
===> Downloaded package, caching at /home/jeff/.cache/rebar3/hex/default/packages/pc-1.6.0.tar
===> Compiling pc
===> Compiling erlexec
===> Compiling /home/jeff/Code/erlexec_test/deps/rpi3/erlexec/c_src/ei++.cpp
===> In file included from /home/jeff/.nerves/artifacts/nerves_system_rpi3-0.15.0.arm_unknown_linux_gnueabihf/staging/usr/include/features.h:389:0,
                 from /home/jeff/.nerves/artifacts/nerves_system_rpi3-0.15.0.arm_unknown_linux_gnueabihf/staging/usr/include/unistd.h:25,
                 from /home/jeff/Code/erlexec_test/deps/rpi3/erlexec/c_src/ei++.cpp:1:
/home/jeff/.nerves/artifacts/nerves_system_rpi3-0.15.0.arm_unknown_linux_gnueabihf/staging/usr/include/gnu/stubs.h:7:29: fatal error: gnu/stubs-soft.h: No such file or directory
 # include <gnu/stubs-soft.h>
                             ^
compilation terminated.

Works fine if I pass CXX to that mix firmware step manually:

CXX=/home/jeff/.nerves/artifacts/nerves_toolchain_arm_unknown_linux_gnueabihf-0.10.0.linux-x86_64/bin/arm-unknown-linux-gnueabihf-g++ mix firmware
electricshaman commented 7 years ago

I should clarify that it turns out Buildroot is not involved here in this part of the build. The Nerves app is the one who sets the CXX variable so the issue is likely somewhere in the rebar or erlexec side. We've verified that CXX is being set by Nerves to the proper cross compiler path (identical to the path given manually) so it appears there is some rebar magic happening somewhere.

electricshaman commented 7 years ago

This was due to mix using rebar3 instead of rebar.

electricshaman commented 6 years ago

Follow up note for anyone running into this issue later - this issue is actually still outstanding, but we are going to address it in Nerves.

See here for more information: https://github.com/nerves-project/nerves_bootstrap/pull/11