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

Correct CC/CXX variables are clobbered for almost-static Rust package builds on Darwin #356783

Closed
zhaofengli opened this issue Nov 17, 2024 · 2 comments · Fixed by #358989
Closed
Assignees
Labels
0.kind: bug Something is broken 6.topic: darwin Running or building packages on Darwin 6.topic: static

Comments

@zhaofengli
Copy link
Member

Describe the bug

The "static" variant of a Darwin platform has the same cargoShortTarget as its regular, non-static counterpart (e.g., aarch64-apple-darwin). This causes an issue in rust.envVars.setEnv which sets environment variables for cargo invocations in the following order:

  1. CC_AARCH64_APPLE_DARWIN: "Static" host CC
  2. CXX_AARCH64_APPLE_DARWIN: "Static" host CXX
  3. CC_AARCH64_APPLE_DARWIN: Regular build CC <- Incorrect!
  4. CXX_AARCH64_APPLE_DARWIN: Regular build CXX <- Incorrect!

As a result, the correct host CC/CXX variables are clobbered:

$ nix-instantiate --eval --json -A pkgsStatic.rust.envVars.setEnv | jq -r
env \
"CC_AARCH64_APPLE_DARWIN=/nix/store/gsn92905sn6zqslsa9asljic1bglx4hl-aarch64-apple-darwin-clang-wrapper-16.0.6/bin/aarch64-apple-darwin-cc" \
"CXX_AARCH64_APPLE_DARWIN=/nix/store/gsn92905sn6zqslsa9asljic1bglx4hl-aarch64-apple-darwin-clang-wrapper-16.0.6/bin/aarch64-apple-darwin-c++" \
"CARGO_TARGET_AARCH64_APPLE_DARWIN_LINKER=/nix/store/gsn92905sn6zqslsa9asljic1bglx4hl-aarch64-apple-darwin-clang-wrapper-16.0.6/bin/aarch64-apple-darwin-cc" \
"CC_AARCH64_APPLE_DARWIN=/nix/store/700a0ayy1s1h7zg9dqiqy0xvmhfr26l6-clang-wrapper-16.0.6/bin/cc" \
"CXX_AARCH64_APPLE_DARWIN=/nix/store/700a0ayy1s1h7zg9dqiqy0xvmhfr26l6-clang-wrapper-16.0.6/bin/c++" \
...

Here gsn92... (pkgsStatic.stdenv.cc) should be used instead of 700a0...-clang-wrapper-16.0.6 (stdenv.cc) for hostPlatform builds. This causes Rust packages like rtrtr to fail linking:

$ nix-build -A pkgsStatic.rtrtr
...
warning: `rtrtr` (lib) generated 1 warning
error: linking with `/nix/store/700a0ayy1s1h7zg9dqiqy0xvmhfr26l6-clang-wrapper-16.0.6/bin/cc` failed: exit status: 1
  |
  = note: env -u IPHONEOS_DEPLOYMENT_TARGET -u TVOS_DEPLOYMENT_TARGET -u XROS_DEPLOYMENT_TARGET LC_ALL="C" (...) "/nix/store/700a0ayy1s1h7zg9dqiqy0xvmhfr26l6-clang-wrapper-16.0.6/bin/cc" (...)
  = note: ld: library not found for -liconv
          clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

(libiconv-static is present)

Ref: #346043 which enabled building almost-static packages on macOS/Darwin 🎊

Steps To Reproduce

Steps to reproduce the behavior:

  1. nix-build -A pkgsStatic.rtrtr on aarch64-darwin

Expected behavior

Screenshots

Additional context

Metadata

Notify maintainers

Darwin people:
@reckenrode
@emilazy
@toonn

Rust people:
@figsoda
@Mic92
@winterqt


Note for maintainers: Please tag this issue in your PR.


Add a 👍 reaction to issues you find important.

@zhaofengli zhaofengli added the 0.kind: bug Something is broken label Nov 17, 2024
@soywod
Copy link
Contributor

soywod commented Nov 25, 2024

I encounter the same issue. The issue occurs only when build = host. Switching order to build > host > target would be enough?

@soywod
Copy link
Contributor

soywod commented Nov 25, 2024

I tried to switch order and it worked for me: #358989

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: darwin Running or building packages on Darwin 6.topic: static
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants