@@ -11,7 +11,7 @@
1111}:
1212
1313let
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}"