Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mix firmware fails on Nix due to hardcoded lib paths #136

Open
danifv opened this issue May 31, 2023 · 2 comments
Open

mix firmware fails on Nix due to hardcoded lib paths #136

danifv opened this issue May 31, 2023 · 2 comments

Comments

@danifv
Copy link

danifv commented May 31, 2023

Environment

  • Elixir version (elixir -v):
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]

Elixir 1.14.4 (compiled with Erlang/OTP 25)
  • Nerves environment: (mix nerves.env --info)
==> nerves
==> hello_nerves
|nerves_bootstrap| Environment Package List

  Pkg:         nerves_system_br
  Vsn:         1.22.5
  Type:        system_platform
  BuildRunner: {nil, []}

  Pkg:         nerves_system_x86_64
  Vsn:         1.22.2
  Type:        system
  BuildRunner: {Nerves.Artifact.BuildRunners.Docker, [make_args: ["source", "all", "legal-info"]]}

  Pkg:         nerves_toolchain_ctng
  Vsn:         1.9.3
  Type:        toolchain_platform
  BuildRunner: {nil, []}

  Pkg:         nerves_toolchain_x86_64_nerves_linux_musl
  Vsn:         1.8.0
  Type:        toolchain
  BuildRunner: {Nerves.Artifact.BuildRunners.Local, []}

|nerves_bootstrap| Loadpaths Start

|nerves_bootstrap| Precompile Start

==> nerves_toolchain_x86_64_nerves_linux_musl
|nerves_bootstrap| Compile.NervesPackage start

|nerves_bootstrap| Compile.NervesPackage end

==> nerves_system_x86_64
|nerves_bootstrap| Compile.NervesPackage start

|nerves_bootstrap| Compile.NervesPackage end

==> hello_nerves
|nerves_bootstrap| Precompile End


Nerves environment
  MIX_TARGET:   x86_64
  MIX_ENV:      dev

|nerves_bootstrap| Environment Variable List
  target:     x86_64
  toolchain:  /Users/d/.nerves/artifacts/nerves_toolchain_x86_64_nerves_linux_musl-darwin_x86_64-1.8.0
  system:     /Users/d/.nerves/artifacts/nerves_system_x86_64-portable-1.22.2
  app:        .

|nerves_bootstrap| Loadpaths End
  • Additional information about your host, target hardware or environment that
    may help
    macOS 11.7.7 using nix 2.13.3 for package management

Current behavior

CT_EXTRA_LDFLAGS_FOR_BUILD and CT_EXTRA_CFLAGS_FOR_BUILD are currently set to /usr/local/opt/... which might be incorrect, depending on user setup, e.g. on Nix. See

CT_EXTRA_LDFLAGS_FOR_BUILD="-L/usr/local/opt/gettext/lib -lintl"

Of course it could be hardcoded in other places as well.

This results in mix firmware being unable to compile dependencies, due to libraries being searched in an incorrect location

==> one_dhcpd
 CC arp_set.o
dyld: Library not loaded: /usr/local/opt/gettext/lib/libintl.8.dylib

Expected behaviour

Buildscripts detect the correct location and firmware is built correctly.

@fhunleth
Copy link
Member

fhunleth commented Jun 1, 2023

Hi @danifv,

I am not a Nix user. If you know how to make a relocatable toolchain that will work with Nix on MacOS too, please submit a PR and I will include it in the next toolchain build. GCC 13 is out now, so publishing new toolchains is on the to do list.

Also, could you take a look at nerves-project/nerves#868? I think that @cloud8421 got farther somehow.

@danifv
Copy link
Author

danifv commented Jun 1, 2023

Hi @fhunleth ,
I was able to reproduce my error even on @cloud8421's nix flake based setup - the difference lies in that I set MIX_TARGET=x86_64.
I also looked at Nix's description [1] on how CFLAGS and LDFLAGS variables are set. It appears, that clang (from macOS) and gcc (when added with Nix) will come as wrappers which have these variables configured with the locations where other nix-managed libraries, like gettext are installed. This suggests, the wrappers should work, regardless of variables like CT_EXTRA_LDFLAGS_FOR_BUILD.
I then proceeded to verify if the wrappers or the underlying compiler and linker are used, found that this bug could rather relate to https://github.com/nerves-project/nerves_system_br/tree/main and got stuck for now.
Do you have any places in mind, which could be worth looking into?
Thank you!

[1] https://nixos.wiki/wiki/C#pkg-config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants