about summary refs log tree commit diff
path: root/pkgs/build-support
diff options
context:
space:
mode:
Diffstat (limited to 'pkgs/build-support')
-rw-r--r--pkgs/build-support/rust/rustc-wrapper/default.nix20
-rw-r--r--pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh2
2 files changed, 21 insertions, 1 deletions
diff --git a/pkgs/build-support/rust/rustc-wrapper/default.nix b/pkgs/build-support/rust/rustc-wrapper/default.nix
index d6034c08af47..2b4a84e72b24 100644
--- a/pkgs/build-support/rust/rustc-wrapper/default.nix
+++ b/pkgs/build-support/rust/rustc-wrapper/default.nix
@@ -8,6 +8,26 @@ runCommand "${rustc-unwrapped.pname}-wrapper-${rustc-unwrapped.version}" {
   env = {
     prog = "${rustc-unwrapped}/bin/rustc";
     sysroot = lib.optionalString (sysroot != null) "--sysroot ${sysroot}";
+
+    # Upstream rustc still assumes that musl = static[1].  The fix for
+    # this is to disable crt-static by default for non-static musl
+    # targets.
+    #
+    # Even though Cargo will build build.rs files for the build platform,
+    # cross-compiling _from_ musl appears to work fine, so we only need
+    # to do this when rustc's target platform is dynamically linked musl.
+    #
+    # [1]: https://github.com/rust-lang/compiler-team/issues/422
+    #
+    # WARNING: using defaultArgs is dangerous, as it will apply to all
+    # targets used by this compiler (host and target).  This means
+    # that it can't be used to set arguments that should only be
+    # applied to the target.  It's fine to do this for -crt-static,
+    # because rustc does not support +crt-static host platforms
+    # anyway.
+    defaultArgs = lib.optionalString
+      (with rustc-unwrapped.stdenv.targetPlatform; isMusl && !isStatic)
+      "-C target-feature=-crt-static";
   };
 
   passthru = {
diff --git a/pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh b/pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh
index 4a90e30652fe..63e18be2e131 100644
--- a/pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh
+++ b/pkgs/build-support/rust/rustc-wrapper/rustc-wrapper.sh
@@ -13,7 +13,7 @@ for arg; do
     esac
 done
 
-extraBefore=("${defaultSysroot[@]}")
+extraBefore=(@defaultArgs@ "${defaultSysroot[@]}")
 extraAfter=($NIX_RUSTFLAGS)
 
 # Optionally print debug info.