saleyn / erlexec

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

Compile failure on OSX M1 mac #168

Closed ewildgoose closed 1 year ago

ewildgoose commented 1 year ago

Hi, I've bumped to version 1.21.0, inside an elixir project. Trying to compile with mix deps.compile erlexec leads to error messages:

mix deps.compile erlexec

20:36:07.373 [info] Skylink modem missing, using Mock skylink
===> Fetching pc v1.13.0
===> Analyzing applications...
===> Compiling pc
===> Compiling c_src/ei++.cpp
===> Compiling c_src/exec.cpp
===> Compiling c_src/exec_impl.cpp
===> Linking /Users/edward/Documents/src/elixir/tpb_sys/deps/erlexec/priv/aarch64-apple-darwin21.5.0/exec-port
** (Mix) Could not compile dependency :erlexec, "/Users/edward/.mix/elixir/1-14/rebar3 bare compile --paths /Users/edward/Documents/src/elixir/tpb_sys/_build/dev/lib/*/ebin" command failed. Errors may have been logged above. You can recompile this dependency with "mix deps.compile erlexec", update it with "mix deps.update erlexec" or clean it with "mix deps.clean erlexec"

However, I don't see that the "exec-port" directory has been created:

ls -al /Users/edward/Documents/src/elixir/tpb_sys/deps/erlexec/priv/aarch64-apple-darwin21.5.0/
total 0
drwxr-xr-x  2 edward  staff  64 Sep 13 20:36 .
drwxr-xr-x  3 edward  staff  96 Sep 13 20:36 ..

I concede I'm a bit lost in the flow of what should be happening to know how to give better debug info. I suspect a pathing issue?

ewildgoose commented 1 year ago

Actually, I rolled back to the previous version I was using (1.20.0) and see the same error.

I suspect that the actual change is that I have upgraded to Erlang OTP25, elixir 1.14.0 and possibly updated rebar. Unclear which is causing this issue?

ewildgoose commented 1 year ago

OK, sorry, this is looking like an issue on my system. Mac OSX M1, and it seems like homebrew might have put a mixed arch version of erlang/elixir into place.

Running with DEBUG=1 I see:

DEBUG=1 mix deps.compile erlexec

===> Compile (apps)
===> Expanded command sequence to be run: []
===> Running provider: do
===> Expanded command sequence to be run: [app_discovery,{bare,compile}]
===> Running provider: app_discovery
===> Found top-level apps: [erlexec]
        using config: [{src_dirs,["src"]},{lib_dirs,["apps/*","lib/*","."]}]
===> Compile (apps)
===> Not adding provider pc compile from module pc_prv_compile because it already exists from module pc_prv_compile
===> Not adding provider pc clean from module pc_prv_clean because it already exists from module pc_prv_clean
===> Running provider: {bare,compile}
===> Compile (untagged)
===> Running hooks for compile in app erlexec (/Users/edward/Documents/src/elixir/tpb_sys/deps/erlexec) with configuration:
===>    {provider_hooks, [{pre, [{pc,compile}]}]}.
===> Running provider: {pc,compile}
===> Running hooks for {pc,compile} with configuration:
===>    {provider_hooks, []}.
===>    {pre_hooks, []}.
===> Linking /Users/edward/Documents/src/elixir/tpb_sys/deps/erlexec/priv/aarch64-apple-darwin21.5.0/exec-port
===> sh(g++ c_src/ei++.o c_src/exec.o c_src/exec_impl.o   -L"/opt/homebrew/Cellar/erlang/25.0.4/lib/erlang/lib/erl_interface-5.3/lib" -lei -o /Users/edward/Documents/src/elixir/tpb_sys/deps/erlexec/priv/aarch64-apple-darwin21.5.0/exec-port)
failed with return code 1 and the following output:
ld: warning: ignoring file /opt/homebrew/Cellar/erlang/25.0.4/lib/erlang/lib/erl_interface-5.3/lib/libei.a, building for macOS-x86_64 but attempting to link with file built for macOS-arm64
Undefined symbols for architecture x86_64:

I guess if anyone has solutions for this then I'm interested, but closing this as it's clearly not an erlexec issue

saleyn commented 1 year ago

Could not reproduce it on the Mac, and the CI/CD builds fine on MacOS as well.

ewildgoose commented 1 year ago

Thanks for investigating further. I can confirm that it was a mixed amd64/arm build issue.

For the benefit of anyone else who arrives here through google: It seems as though homebrew and visual studio have gradually migrated from running under rosetta to being native. At various points things seem to be tending to switch to native, but upgrades seem to sometimes leave you on an old channel. etc. Seems like you can get further problems running through shells started from a native app as the shell is then running under rosetta emulation, so wrong builds could get pulled in, etc, etc

In my case I must have had something switch either to native, or back to amd64. I resolved this with a simple:

brew uninstall erlang elixir; brew install erlang elixir

And checked that it referenced native arm builds being pulled in. All is now well

Sorry for the noise