mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-26 00:43:20 +00:00
cargoSetupHook: pass host config flags
This commit is contained in:
parent
8b31b52853
commit
c2eaaae50d
@ -27,7 +27,7 @@ cargoSetupPostUnpackHook() {
|
|||||||
cat ${tmp_config} >> .cargo/config
|
cat ${tmp_config} >> .cargo/config
|
||||||
|
|
||||||
cat >> .cargo/config <<'EOF'
|
cat >> .cargo/config <<'EOF'
|
||||||
@rustTarget@
|
@cargoConfig@
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo "Finished cargoSetupPostUnpackHook"
|
echo "Finished cargoSetupPostUnpackHook"
|
||||||
|
@ -68,15 +68,37 @@ in {
|
|||||||
# The `.nativeDrv` stanza works like nativeBuildInputs and ensures cross-compiling has the right version available.
|
# The `.nativeDrv` stanza works like nativeBuildInputs and ensures cross-compiling has the right version available.
|
||||||
diff = "${diffutils.nativeDrv or diffutils}/bin/diff";
|
diff = "${diffutils.nativeDrv or diffutils}/bin/diff";
|
||||||
|
|
||||||
# Target platform
|
# We want to specify the correct crt-static flag for both
|
||||||
rustTarget = ''
|
# the build and host platforms. This is important when the wanted
|
||||||
[target."${rust.toRustTarget stdenv.buildPlatform}"]
|
# value for crt-static does not match the defaults in the rustc target,
|
||||||
|
# like for pkgsMusl or pkgsCross.musl64; Upstream rustc still assumes
|
||||||
|
# that musl = static[1].
|
||||||
|
#
|
||||||
|
# By default, Cargo doesn't apply RUSTFLAGS when building build.rs
|
||||||
|
# if --target is passed, so the only good way to set crt-static for
|
||||||
|
# build.rs files is to use the unstable -Zhost-config Cargo feature.
|
||||||
|
# This allows us to specify flags that should be passed to rustc
|
||||||
|
# when building for the build platform. We also need to use
|
||||||
|
# -Ztarget-applies-to-host, because using -Zhost-config requires it.
|
||||||
|
#
|
||||||
|
# When doing this, we also have to specify the linker, or cargo
|
||||||
|
# won't pass a -C linker= argument to rustc. This will make rustc
|
||||||
|
# try to use its default value of "cc", which won't be available
|
||||||
|
# when cross-compiling.
|
||||||
|
#
|
||||||
|
# [1]: https://github.com/rust-lang/compiler-team/issues/422
|
||||||
|
cargoConfig = ''
|
||||||
|
[host]
|
||||||
"linker" = "${ccForBuild}"
|
"linker" = "${ccForBuild}"
|
||||||
${lib.optionalString (stdenv.buildPlatform.config != stdenv.hostPlatform.config) ''
|
"rustflags" = [ "-C", "target-feature=${if stdenv.buildPlatform.isStatic then "+" else "-"}crt-static" ]
|
||||||
[target."${shortTarget}"]
|
|
||||||
"linker" = "${ccForHost}"
|
[target."${shortTarget}"]
|
||||||
''}
|
"linker" = "${ccForHost}"
|
||||||
"rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ]
|
"rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ]
|
||||||
|
|
||||||
|
[unstable]
|
||||||
|
host-config = true
|
||||||
|
target-applies-to-host = true
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
} ./cargo-setup-hook.sh) {};
|
} ./cargo-setup-hook.sh) {};
|
||||||
|
Loading…
Reference in New Issue
Block a user