Skip to content

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

Description

@zhaofengli

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.

Metadata

Metadata

Assignees

Labels

0.kind: bugSomething is broken6.topic: darwinRunning or building packages on Darwin6.topic: staticStatic builds (e.g. pkgsStatic)

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions