|
68 | 68 | # The `.nativeDrv` stanza works like nativeBuildInputs and ensures cross-compiling has the right version available. |
69 | 69 | diff = "${diffutils.nativeDrv or diffutils}/bin/diff"; |
70 | 70 |
|
71 | | - # Target platform |
72 | | - rustTarget = '' |
73 | | - [target."${rust.toRustTarget stdenv.buildPlatform}"] |
| 71 | + # We want to specify the correct crt-static flag for both |
| 72 | + # the build and host platforms. This is important when the wanted |
| 73 | + # value for crt-static does not match the defaults in the rustc target, |
| 74 | + # like for pkgsMusl or pkgsCross.musl64; Upstream rustc still assumes |
| 75 | + # that musl = static[1]. |
| 76 | + # |
| 77 | + # By default, Cargo doesn't apply RUSTFLAGS when building build.rs |
| 78 | + # if --target is passed, so the only good way to set crt-static for |
| 79 | + # build.rs files is to use the unstable -Zhost-config Cargo feature. |
| 80 | + # This allows us to specify flags that should be passed to rustc |
| 81 | + # when building for the build platform. We also need to use |
| 82 | + # -Ztarget-applies-to-host, because using -Zhost-config requires it. |
| 83 | + # |
| 84 | + # When doing this, we also have to specify the linker, or cargo |
| 85 | + # won't pass a -C linker= argument to rustc. This will make rustc |
| 86 | + # try to use its default value of "cc", which won't be available |
| 87 | + # when cross-compiling. |
| 88 | + # |
| 89 | + # [1]: https://github.com/rust-lang/compiler-team/issues/422 |
| 90 | + cargoConfig = '' |
| 91 | + [host] |
74 | 92 | "linker" = "${ccForBuild}" |
75 | | - ${lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) '' |
76 | | - [target."${shortTarget}"] |
77 | | - "linker" = "${ccForHost}" |
78 | | - ''} |
| 93 | + "rustflags" = [ "-C", "target-feature=${if stdenv.buildPlatform.isStatic then "+" else "-"}crt-static" ] |
| 94 | +
|
| 95 | + [target."${shortTarget}"] |
| 96 | + "linker" = "${ccForHost}" |
79 | 97 | "rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ] |
| 98 | +
|
| 99 | + [unstable] |
| 100 | + host-config = true |
| 101 | + target-applies-to-host = true |
80 | 102 | ''; |
81 | 103 | }; |
82 | 104 | } ./cargo-setup-hook.sh) {}; |
|
0 commit comments