Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions pkgs/build-support/rust/hooks/cargo-setup-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ cargoSetupPostUnpackHook() {
--subst-var-by vendor "$cargoDepsCopy"
cat ${tmp_config} >> .cargo/config

cat >> .cargo/config <<'EOF'
@cargoConfig@
EOF

echo "Finished cargoSetupPostUnpackHook"
}
Expand Down
19 changes: 8 additions & 11 deletions pkgs/build-support/rust/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ let
shortTarget = if targetIsJSON then
(lib.removeSuffix ".json" (builtins.baseNameOf "${target}"))
else target;
shortTargetEnv = lib.replaceStrings ["-"] ["_"] (lib.toUpper shortTarget);
ccForBuild = "${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc";
cxxForBuild = "${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}c++";
ccForHost = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
Expand Down Expand Up @@ -95,18 +96,14 @@ in {
# when cross-compiling.
#
# [1]: https://github.com/rust-lang/compiler-team/issues/422
cargoConfig = ''
[host]
"linker" = "${ccForBuild}"
"rustflags" = [ "-C", "target-feature=${if stdenv.buildPlatform.isStatic then "+" else "-"}crt-static" ]

[target."${shortTarget}"]
"linker" = "${ccForHost}"
"rustflags" = [ "-C", "target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static" ]

[unstable]
host-config = true
target-applies-to-host = true
cargoConfig = ''
export CARGO_UNSTABLE_HOST_CONFIG=true
export CARGO_UNSTABLE_TARGET_APPLIES_TO_HOST=true
export CARGO_HOST_LINKER="${ccForBuild}"
export CARGO_HOST_RUSTFLAGS="-C target-feature=${if stdenv.buildPlatform.isStatic then "+" else "-"}crt-static"
export CARGO_TARGET_${shortTargetEnv}_LINKER="${ccForHost}"
export CARGO_TARGET_${shortTargetEnv}_RUSTFLAGS="-C target-feature=${if stdenv.hostPlatform.isStatic then "+" else "-"}crt-static"
'';

# https://github.com/NixOS/nixpkgs/issues/201254
Expand Down