From 5a923e552cba2bb56fca22ee6c01482635c5b908 Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Sat, 12 Dec 2020 15:18:30 -0500 Subject: [PATCH] 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. --- pkgs/development/compilers/rust/rustc.nix | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/pkgs/development/compilers/rust/rustc.nix b/pkgs/development/compilers/rust/rustc.nix index dab1f2a6bd8..a290eb11755 100644 --- a/pkgs/development/compilers/rust/rustc.nix +++ b/pkgs/development/compilers/rust/rustc.nix @@ -11,7 +11,7 @@ }: let - inherit (stdenv.lib) optionals optional optionalString; + inherit (stdenv.lib) optionals optional optionalString concatStringsSep; inherit (darwin.apple_sdk.frameworks) Security; llvmSharedForBuild = pkgsBuildBuild.llvm_10.override { enableSharedLibraries = true; }; @@ -72,7 +72,14 @@ in stdenv.mkDerivation rec { "--enable-vendor" "--build=${rust.toRustTargetSpec stdenv.buildPlatform}" "--host=${rust.toRustTargetSpec stdenv.hostPlatform}" - "--target=${rust.toRustTargetSpec stdenv.targetPlatform}" + # std is built for all platforms in --target. When building a cross-compiler + # we need to add the host platform as well so rustc can compile build.rs + # scripts. + "--target=${concatStringsSep "," ([ + (rust.toRustTargetSpec stdenv.targetPlatform) + ] ++ optionals (stdenv.hostPlatform != stdenv.targetPlatform) [ + (rust.toRustTargetSpec stdenv.hostPlatform) + ])}" "${setBuild}.cc=${ccForBuild}" "${setHost}.cc=${ccForHost}"