oxalica / rust-overlay

Pure and reproducible nix overlay of binary distributed rust toolchains
MIT License
934 stars 53 forks source link

Linking fails on macOS: framework not found #51

Closed veehaitch closed 3 years ago

veehaitch commented 3 years ago

We're using rust-overlay in our project ragenix together with naersk. A recent flake update fails to link on macOS with the following error:

ragenix> error: could not compile `ragenix` due to 2 previous errors
ragenix> error: linking with `cc` failed: exit status: 1
[...]
ragenix>   = note: ld: framework not found Security
ragenix>           collect2: error: ld returned 1 exit status
ragenix>
ragenix> error: aborting due to previous error

The full log is available in the CI run of the PR: https://github.com/yaxitech/ragenix/pull/24/checks?check_run_id=3643619398. Building on Linux works fine.

I have pinpointed c7ed82b2317b6b0d3d3a55ce4d12561f868858d0 to introduce the error. I'm not too familiar with the internals; therefore, I cannot tell why this commit makes a difference. Do we have to adapt our flake?

I'd appreciate if you could look into this. Thanks!

oxalica commented 3 years ago

Our CI builds the hello world program successfully: https://github.com/oxalica/rust-overlay/runs/3647583821?check_suite_focus=true

I'm not familiar with darwin. It might because you your package links to Security somehow, but usually it's not required (at least for a hello world program). I'm not sure why it works before but I think you need to add Security to your buildInputs. There are also many rust programs in nixpkgs have this dependency, so I don't think it's an issue of rust-overlay. But we're still sorry about the breakage. https://github.com/NixOS/nixpkgs/blob/4467663aaa4d20b329e53ebe631bd3092497c527/pkgs/development/interpreters/evcxr/default.nix#L20-L21

veehaitch commented 3 years ago

Thanks for your response!

I'm not familiar with darwin. It might because you your package links to Security somehow, but usually it's not required (at least for a hello world program). I'm not sure why it works before but I think you need to add Security to your buildInputs.

That's correct, the Security framework is not always required. In our case, however, it has been required since the very beginning. It's already part of our buildInputs for darwin builds:

https://github.com/yaxitech/ragenix/blob/acd6bef157f967fa7ed266a0f8e4ea8949afeaf4/flake.nix#L75-L81

As I said before, I'm not sure what's the reason but it has worked before c7ed82b2317b6b0d3d3a55ce4d12561f868858d0 and apparently is not related to any other inputs of our flake.

veehaitch commented 3 years ago

Apparently, it's caused by propagatedBuildInputs VS propagatedNativeBuildInputs. With the following rust-overlay change building works again:

diff --git a/rust-overlay.nix b/rust-overlay.nix
index 287f282..1dbbd14 100644
--- a/rust-overlay.nix
+++ b/rust-overlay.nix
@@ -328,7 +328,7 @@ let

       # Ourselves have offset -1. In order to make these offset -1 dependencies of downstream derivation,
       # they are offset 0 propagated.
-      propagatedBuildInputs = [ self.gcc self.buildPackages.gcc ] ++
+      propagatedNativeBuildInputs = [ self.gcc self.buildPackages.gcc ] ++
         self.lib.optional (self.stdenv.targetPlatform.isDarwin) self.targetPackages.libiconv;

       meta.platforms = self.lib.platforms.all;
oxalica commented 3 years ago

it's caused by propagatedBuildInputs VS propagatedNativeBuildInputs

No. The latter one is incorrect and is simply ignored by stdenv (native build inputs' propagated native build inputs are out of offset range (-1, 0, 1) and are discarded).

It's caused by gcc v.s. stdenv.cc: darwin use clang stdenv. So introducing gcc breaks things. It's now fixed in master.

https://github.com/yaxitech/ragenix/blob/acd6bef157f967fa7ed266a0f8e4ea8949afeaf4/flake.nix#L75-L81

] ++ lib.optionals stdenv.isDarwin [
  libiconv
  darwin.Security
];

This should be darwin.apple_sdk.frameworks.Security. But I'm not sure if darwin.Security also work.

veehaitch commented 3 years ago

Thanks for addressing this so quickly!

henry-hz commented 2 years ago

@oxalica hi! pls, I am having the liconv issue when trying to compile the https://github.com/rust-blockchain/evm on macOS monterey 12.1

The rust-overlay is working well in scenarios that liconv is unecessary.

   Compiling proc-macro-error v1.0.4
   Compiling impl-rlp v0.3.0
   Compiling triehash v0.8.4
error: linking with `cc` failed: exit status: 1
  |..../store/xdibsr6bja51170dyad1ifh8bmvdxida-rust-default-1.57.0/lib/rustlib/x86_64-apple-darwin/lib" "-o" "/Users/henry/code/evm/target/release/build/tiny-keccak-1171e6a0c19b2d36/build_script_build-1171e6a0c19b2d36" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: library not found for -liconv
          collect2: error: ld returned 1 exit status
oxalica commented 2 years ago

@oxalica hi! pls, I am having the liconv issue when trying to compile the https://github.com/rust-blockchain/evm on macOS monterey 12.1

The rust-overlay is working well in scenarios that liconv is unecessary.

   Compiling proc-macro-error v1.0.4
   Compiling impl-rlp v0.3.0
   Compiling triehash v0.8.4
error: linking with `cc` failed: exit status: 1
  |..../store/xdibsr6bja51170dyad1ifh8bmvdxida-rust-default-1.57.0/lib/rustlib/x86_64-apple-darwin/lib" "-o" "/Users/henry/code/evm/target/release/build/tiny-keccak-1171e6a0c19b2d36/build_script_build-1171e6a0c19b2d36" "-Wl,-dead_strip" "-nodefaultlibs"
  = note: ld: library not found for -liconv
          collect2: error: ld returned 1 exit status

Please open a new issue since it's an unrelated one, the commit of rust-overlay you are using, and how you introduce rust-overlay in your environment (the content of shell.nix, CI or the system configuration).