cross stdenv adaptor: Support --host --build --target across the board
Packages get --host and --target by default, but can explicitly request any subset to be passed as needed. See docs for more info. rustc: Avoid hash breakage by using the old (ignored) dontSetConfigureCross when not cross building
This commit is contained in:
committed by
John Ericson
parent
9bfd03eff7
commit
594d264205
@@ -56,8 +56,15 @@ rec {
|
||||
|
||||
# Return a modified stdenv that adds a cross compiler to the
|
||||
# builds.
|
||||
makeStdenvCross = stdenvOrig: cross: cc: let
|
||||
stdenv = stdenvOrig.override {
|
||||
makeStdenvCross = { stdenv
|
||||
, cc
|
||||
, buildPlatform, hostPlatform, targetPlatform
|
||||
} @ overrideArgs: let
|
||||
stdenv = overrideArgs.stdenv.override {
|
||||
# TODO(@Ericson2314): Cannot do this for now because then Nix thinks the
|
||||
# resulting derivation should be built on the host platform.
|
||||
#hostPlatform = buildPlatform;
|
||||
#targetPlatform = hostPlatform;
|
||||
inherit cc;
|
||||
|
||||
allowedRequisites = null;
|
||||
@@ -70,7 +77,12 @@ rec {
|
||||
mkDerivation =
|
||||
{ name ? "", buildInputs ? [], nativeBuildInputs ? []
|
||||
, propagatedBuildInputs ? [], propagatedNativeBuildInputs ? []
|
||||
, selfNativeBuildInput ? false, ...
|
||||
, configureFlags ? []
|
||||
, # Target is not included by default because most programs don't care.
|
||||
# Including it then would cause needless massive rebuilds.
|
||||
configurePlatforms ? args.crossAttrs.configurePlatforms or [ "build" "host" ]
|
||||
, selfNativeBuildInput ? args.crossAttrs.selfNativeBuildInput or false
|
||||
, ...
|
||||
} @ args:
|
||||
|
||||
let
|
||||
@@ -93,16 +105,23 @@ rec {
|
||||
nativeInputsFromBuildInputs = stdenv.lib.filter hostAsNativeDrv buildInputsNotNull;
|
||||
in
|
||||
stdenv.mkDerivation (args // {
|
||||
name = name + "-" + cross.config;
|
||||
name = name + "-" + hostPlatform.config;
|
||||
nativeBuildInputs = nativeBuildInputs
|
||||
++ nativeInputsFromBuildInputs
|
||||
++ stdenv.lib.optional selfNativeBuildInput nativeDrv
|
||||
# without proper `file` command, libtool sometimes fails
|
||||
# to recognize 64-bit DLLs
|
||||
++ stdenv.lib.optional (cross.config == "x86_64-w64-mingw32") pkgs.file
|
||||
++ stdenv.lib.optional (cross.config == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook
|
||||
++ stdenv.lib.optional (hostPlatform.config == "x86_64-w64-mingw32") pkgs.file
|
||||
++ stdenv.lib.optional (hostPlatform.config == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook
|
||||
;
|
||||
|
||||
# This parameter is sometimes a string and sometimes a list, yuck
|
||||
configureFlags = let inherit (stdenv.lib) optional elem; in
|
||||
(if stdenv.lib.isString configureFlags then [configureFlags] else configureFlags)
|
||||
++ optional (elem "build" configurePlatforms) "--build=${buildPlatform.config}"
|
||||
++ optional (elem "host" configurePlatforms) "--host=${hostPlatform.config}"
|
||||
++ optional (elem "target" configurePlatforms) "--target=${targetPlatform.config}";
|
||||
|
||||
# Cross-linking dynamic libraries, every buildInput should
|
||||
# be propagated because ld needs the -rpath-link to find
|
||||
# any library needed to link the program dynamically at
|
||||
@@ -111,7 +130,7 @@ rec {
|
||||
propagatedBuildInputs = propagatedBuildInputs ++ buildInputs;
|
||||
propagatedNativeBuildInputs = propagatedNativeBuildInputs;
|
||||
|
||||
crossConfig = cross.config;
|
||||
crossConfig = hostPlatform.config;
|
||||
} // args.crossAttrs or {});
|
||||
};
|
||||
|
||||
|
||||
@@ -31,12 +31,15 @@ in bootStages ++ [
|
||||
targetPlatform = crossSystem;
|
||||
inherit config overlays;
|
||||
selfBuild = false;
|
||||
stdenv = buildPackages.makeStdenvCross
|
||||
buildPackages.stdenv
|
||||
crossSystem
|
||||
(if crossSystem.useiOSCross or false
|
||||
then buildPackages.darwin.ios-cross
|
||||
else buildPackages.gccCrossStageFinal);
|
||||
stdenv = buildPackages.makeStdenvCross {
|
||||
inherit (buildPackages) stdenv;
|
||||
buildPlatform = localSystem;
|
||||
hostPlatform = crossSystem;
|
||||
targetPlatform = crossSystem;
|
||||
cc = if crossSystem.useiOSCross or false
|
||||
then buildPackages.darwin.ios-cross
|
||||
else buildPackages.gccCrossStageFinal;
|
||||
};
|
||||
})
|
||||
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user