Merge pull request #283239 from alyssais/rust-lld

rust.envVars: use wrapped LLD for aarch64 musl
This commit is contained in:
Jörg Thalheim 2024-01-25 16:16:48 +01:00 committed by GitHub
commit c8758686ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 27 additions and 25 deletions

View file

@ -1,7 +1,8 @@
{ lib
, stdenv
, buildPackages
, targetPackages
, pkgsBuildHost
, pkgsBuildTarget
, pkgsTargetTarget
}:
rec {
@ -16,26 +17,26 @@ rec {
# As a workaround for https://github.com/rust-lang/rust/issues/89626 use lld on pkgsStatic aarch64
shouldUseLLD = platform: platform.isAarch64 && platform.isStatic && !stdenv.isDarwin;
ccForBuild = "${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}cc";
cxxForBuild = "${buildPackages.stdenv.cc}/bin/${buildPackages.stdenv.cc.targetPrefix}c++";
ccForBuild = "${pkgsBuildHost.stdenv.cc}/bin/${pkgsBuildHost.stdenv.cc.targetPrefix}cc";
cxxForBuild = "${pkgsBuildHost.stdenv.cc}/bin/${pkgsBuildHost.stdenv.cc.targetPrefix}c++";
linkerForBuild = ccForBuild;
ccForHost = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}cc";
cxxForHost = "${stdenv.cc}/bin/${stdenv.cc.targetPrefix}c++";
linkerForHost = if shouldUseLLD stdenv.targetPlatform
&& !stdenv.cc.bintools.isLLVM
then "${buildPackages.lld}/bin/ld.lld"
then "${pkgsBuildHost.llvmPackages.bintools}/bin/${stdenv.cc.targetPrefix}ld.lld"
else ccForHost;
# Unfortunately we must use the dangerous `targetPackages` here
# Unfortunately we must use the dangerous `pkgsTargetTarget` here
# because hooks are artificially phase-shifted one slot earlier
# (they go in nativeBuildInputs, so the hostPlatform looks like
# a targetPlatform to them).
ccForTarget = "${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}cc";
cxxForTarget = "${targetPackages.stdenv.cc}/bin/${targetPackages.stdenv.cc.targetPrefix}c++";
linkerForTarget = if shouldUseLLD targetPackages.stdenv.targetPlatform
&& !targetPackages.stdenv.cc.bintools.isLLVM # whether stdenv's linker is lld already
then "${buildPackages.lld}/bin/ld.lld"
ccForTarget = "${pkgsTargetTarget.stdenv.cc}/bin/${pkgsTargetTarget.stdenv.cc.targetPrefix}cc";
cxxForTarget = "${pkgsTargetTarget.stdenv.cc}/bin/${pkgsTargetTarget.stdenv.cc.targetPrefix}c++";
linkerForTarget = if shouldUseLLD pkgsTargetTarget.stdenv.targetPlatform
&& !pkgsTargetTarget.stdenv.cc.bintools.isLLVM # whether stdenv's linker is lld already
then "${pkgsBuildTarget.llvmPackages.bintools}/bin/${pkgsTargetTarget.stdenv.cc.targetPrefix}ld.lld"
else ccForTarget;
rustBuildPlatform = stdenv.buildPlatform.rust.rustcTarget;
@ -56,9 +57,9 @@ rec {
setEnv = ''
env \
''
# Due to a bug in how splicing and targetPackages works, in
# situations where targetPackages is irrelevant
# targetPackages.stdenv.cc is often simply wrong. We must omit
# Due to a bug in how splicing and pkgsTargetTarget works, in
# situations where pkgsTargetTarget is irrelevant
# pkgsTargetTarget.stdenv.cc is often simply wrong. We must omit
# the following lines when rustTargetPlatform collides with
# rustHostPlatform.
+ lib.optionalString (rustTargetPlatform != rustHostPlatform) ''
@ -74,8 +75,8 @@ rec {
"CXX_${stdenv.buildPlatform.rust.cargoEnvVarTarget}=${cxxForBuild}" \
"CARGO_TARGET_${stdenv.buildPlatform.rust.cargoEnvVarTarget}_LINKER=${linkerForBuild}" \
"CARGO_BUILD_TARGET=${rustBuildPlatform}" \
"HOST_CC=${buildPackages.stdenv.cc}/bin/cc" \
"HOST_CXX=${buildPackages.stdenv.cc}/bin/c++" \
"HOST_CC=${pkgsBuildHost.stdenv.cc}/bin/cc" \
"HOST_CXX=${pkgsBuildHost.stdenv.cc}/bin/c++" \
'';
};
} // lib.mapAttrs (old: new: platform:

View file

@ -10,11 +10,9 @@
# 3. Firefox and Thunderbird should still build on x86_64-linux.
{ stdenv, lib
, buildPackages
, targetPackages
, newScope, callPackage
, CoreFoundation, Security, SystemConfiguration
, pkgsBuildTarget, pkgsBuildBuild, pkgsBuildHost
, pkgsBuildTarget, pkgsBuildBuild, pkgsBuildHost, pkgsTargetTarget
, makeRustPlatform
, wrapRustcWith
, llvmPackages_17, llvm_17
@ -58,4 +56,4 @@ import ./default.nix {
rustcPatches = [ ];
}
(builtins.removeAttrs args [ "pkgsBuildTarget" "pkgsBuildHost" "llvmPackages_17" "llvm_17"])
(builtins.removeAttrs args [ "llvmPackages_17" "llvm_17"])

View file

@ -12,18 +12,21 @@
, llvmPackages # Exposed through rustc for LTO in Firefox
}:
{ stdenv, lib
, buildPackages
, targetPackages
, newScope, callPackage
, CoreFoundation, Security, SystemConfiguration
, pkgsBuildBuild
, pkgsBuildHost
, pkgsBuildTarget
, pkgsTargetTarget
, makeRustPlatform
, wrapRustcWith
}:
let
# Use `import` to make sure no packages sneak in here.
lib' = import ../../../build-support/rust/lib { inherit lib stdenv buildPackages targetPackages; };
lib' = import ../../../build-support/rust/lib {
inherit lib stdenv pkgsBuildHost pkgsBuildTarget pkgsTargetTarget;
};
# Allow faster cross compiler generation by reusing Build artifacts
fastCross = (stdenv.buildPlatform == stdenv.hostPlatform) && (stdenv.hostPlatform != stdenv.targetPlatform);
in
@ -58,11 +61,11 @@ in
else
self.buildRustPackages.overrideScope (_: _:
lib.optionalAttrs (stdenv.buildPlatform == stdenv.hostPlatform)
(selectRustPackage buildPackages).packages.prebuilt);
(selectRustPackage pkgsBuildHost).packages.prebuilt);
bootRustPlatform = makeRustPlatform bootstrapRustPackages;
in {
# Packages suitable for build-time, e.g. `build.rs`-type stuff.
buildRustPackages = (selectRustPackage buildPackages).packages.stable // { __attrsFailEvaluation = true; };
buildRustPackages = (selectRustPackage pkgsBuildHost).packages.stable // { __attrsFailEvaluation = true; };
# Analogous to stdenv
rustPlatform = makeRustPlatform self.buildRustPackages;
rustc-unwrapped = self.callPackage ./rustc.nix ({