Skip to content

Commit 5a923e5

Browse files
committed
rustc: add host platform to --target when building cross-compiler
As of 1.48, std is only built for platforms in --target. If the host platform is not included, the resulting rustc can't compile build.rs scripts.
1 parent f947634 commit 5a923e5

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

pkgs/development/compilers/rust/rustc.nix

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
}:
1212

1313
let
14-
inherit (stdenv.lib) optionals optional optionalString;
14+
inherit (stdenv.lib) optionals optional optionalString concatStringsSep;
1515
inherit (darwin.apple_sdk.frameworks) Security;
1616

1717
llvmSharedForBuild = pkgsBuildBuild.llvm_10.override { enableSharedLibraries = true; };
@@ -72,7 +72,14 @@ in stdenv.mkDerivation rec {
7272
"--enable-vendor"
7373
"--build=${rust.toRustTargetSpec stdenv.buildPlatform}"
7474
"--host=${rust.toRustTargetSpec stdenv.hostPlatform}"
75-
"--target=${rust.toRustTargetSpec stdenv.targetPlatform}"
75+
# std is built for all platforms in --target. When building a cross-compiler
76+
# we need to add the host platform as well so rustc can compile build.rs
77+
# scripts.
78+
"--target=${concatStringsSep "," ([
79+
(rust.toRustTargetSpec stdenv.targetPlatform)
80+
] ++ optionals (stdenv.hostPlatform != stdenv.targetPlatform) [
81+
(rust.toRustTargetSpec stdenv.hostPlatform)
82+
])}"
7683

7784
"${setBuild}.cc=${ccForBuild}"
7885
"${setHost}.cc=${ccForHost}"

0 commit comments

Comments
 (0)