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:
John Ericson 2017-04-26 00:06:11 -04:00 committed by John Ericson
parent 9bfd03eff7
commit 594d264205
15 changed files with 66 additions and 29 deletions

View file

@ -640,6 +640,16 @@ script) if it exists.</para>
true.</para></listitem> true.</para></listitem>
</varlistentry> </varlistentry>
<varlistentry>
<term><varname>configurePlatforms</varname></term>
<listitem><para>
By default, when cross compiling, the configure script has <option>--build=...</option> and <option>--host=...</option> passed.
Packages can instead pass <literal>[ "build" "host" "target" ]</literal> or a subset to control exactly which platform flags are passed.
Compilers and other tools should use this to also pass the target platform, for example.
Note eventually these will be passed when in native builds too, to improve determinism: build-time guessing, as is done today, is a risk of impurity.
</para></listitem>
</varlistentry>
<varlistentry> <varlistentry>
<term><varname>preConfigure</varname></term> <term><varname>preConfigure</varname></term>
<listitem><para>Hook executed at the start of the configure <listitem><para>Hook executed at the start of the configure

View file

@ -25,6 +25,7 @@
, libjpegSupport ? true, libjpeg ? null , libjpegSupport ? true, libjpeg ? null
, useUnfreeCodecs ? false , useUnfreeCodecs ? false
, darwin ? null , darwin ? null
, hostPlatform
}: }:
assert fontconfigSupport -> (fontconfig != null); assert fontconfigSupport -> (fontconfig != null);
@ -185,13 +186,14 @@ stdenv.mkDerivation rec {
''; '';
crossAttrs = { crossAttrs = {
dontSetConfigureCross = true; configurePlatforms = [];
# Some things (vidix) are nanonote specific. Once someone cares, we can make options from them. # Some things (vidix) are nanonote specific. Once someone cares, we can make options from them.
# Note, the `target` vs `host` confusion is intensional.
preConfigure = '' preConfigure = ''
configureFlags="`echo $configureFlags | configureFlags="`echo $configureFlags |
sed -e 's/--codecsdir[^ ]\+//' \ sed -e 's/--codecsdir[^ ]\+//' \
-e 's/--enable-runtime-cpudetection//' `" -e 's/--enable-runtime-cpudetection//' `"
configureFlags="$configureFlags --target=${stdenv.cross.arch}-linux configureFlags="$configureFlags --target=${hostPlatform.arch}-linux
--enable-cross-compile --cc=$crossConfig-gcc --as=$crossConfig-as --enable-cross-compile --cc=$crossConfig-gcc --as=$crossConfig-as
--disable-vidix-pcidb --with-vidix-drivers=no --host-cc=gcc" --disable-vidix-pcidb --with-vidix-drivers=no --host-cc=gcc"
''; '';

View file

@ -44,7 +44,7 @@ let
enableParallelBuilding = true; enableParallelBuilding = true;
crossAttrs = { crossAttrs = {
dontSetConfigureCross = true; configurePlatforms = [];
configureFlags = configureFlags ++ [ configureFlags = configureFlags ++ [
"--cross-prefix=${stdenv.cross.config}-" "--cross-prefix=${stdenv.cross.config}-"
"--enable-cross-compile" "--enable-cross-compile"

View file

@ -114,7 +114,7 @@ in stdenv.mkDerivation (rec {
buildInputs = commonBuildInputs ++ [ stdenv.ccCross stdenv.binutils ]; buildInputs = commonBuildInputs ++ [ stdenv.ccCross stdenv.binutils ];
dontSetConfigureCross = true; configurePlatforms = [];
passthru = { passthru = {
inherit bootPkgs cross; inherit bootPkgs cross;

View file

@ -10,6 +10,7 @@
, targetPatches , targetPatches
, targetToolchains , targetToolchains
, doCheck ? true , doCheck ? true
, buildPlatform, hostPlatform
} @ args: } @ args:
let let
@ -137,7 +138,8 @@ stdenv.mkDerivation {
inherit doCheck; inherit doCheck;
dontSetConfigureCross = true; ${if buildPlatform == hostPlatform then "dontSetConfigureCross" else null} = true;
${if buildPlatform != hostPlatform then "configurePlatforms" else null} = [];
# https://github.com/NixOS/nixpkgs/pull/21742#issuecomment-272305764 # https://github.com/NixOS/nixpkgs/pull/21742#issuecomment-272305764
# https://github.com/rust-lang/rust/issues/30181 # https://github.com/rust-lang/rust/issues/30181

View file

@ -446,7 +446,7 @@ stdenv.mkDerivation rec {
fi fi
''; '';
in { in {
dontSetConfigureCross = true; configurePlatforms = [];
configureFlags = configureFlags ++ [ configureFlags = configureFlags ++ [
"--cross-prefix=${stdenv.cross.config}-" "--cross-prefix=${stdenv.cross.config}-"
"--enable-cross-compile" "--enable-cross-compile"

View file

@ -187,7 +187,7 @@ stdenv.mkDerivation rec {
fi fi
''; '';
in { in {
dontSetConfigureCross = true; configurePlatforms = [];
configureFlags = configureFlags ++ [ configureFlags = configureFlags ++ [
"--cross-prefix=${stdenv.cross.config}-" "--cross-prefix=${stdenv.cross.config}-"
"--enable-cross-compile" "--enable-cross-compile"

View file

@ -105,7 +105,7 @@ let
installCheckTarget = "check"; # tests need to be run *after* installation installCheckTarget = "check"; # tests need to be run *after* installation
crossAttrs = { crossAttrs = {
dontSetConfigureCross = true; configurePlatforms = [];
configureFlags = configureFlags ++ [ configureFlags = configureFlags ++ [
"--cross-prefix=${stdenv.cross.config}-" "--cross-prefix=${stdenv.cross.config}-"
"--enable-cross-compile" "--enable-cross-compile"

View file

@ -148,7 +148,7 @@ stdenv.mkDerivation rec {
isCygwin = stdenv.cross.libc == "msvcrt"; isCygwin = stdenv.cross.libc == "msvcrt";
isDarwin = stdenv.cross.libc == "libSystem"; isDarwin = stdenv.cross.libc == "libSystem";
in { in {
dontSetConfigureCross = true; configurePlatforms = [];
configureFlags = configureFlags ++ [ configureFlags = configureFlags ++ [
#"--extra-cflags=" #"--extra-cflags="
#"--extra-cxxflags=" #"--extra-cxxflags="

View file

@ -156,7 +156,7 @@ stdenv.mkDerivation rec {
isCygwin = stdenv.cross.libc == "msvcrt"; isCygwin = stdenv.cross.libc == "msvcrt";
isDarwin = stdenv.cross.libc == "libSystem"; isDarwin = stdenv.cross.libc == "libSystem";
in { in {
dontSetConfigureCross = true; configurePlatforms = [];
configureFlags = configureFlags ++ [ configureFlags = configureFlags ++ [
#"--extra-cflags=" #"--extra-cflags="
#"--prefix=" #"--prefix="

View file

@ -209,7 +209,7 @@ stdenv.mkDerivation rec {
postInstall = '' postInstall = ''
cp bin/qmake* $out/bin cp bin/qmake* $out/bin
''; '';
dontSetConfigureCross = true; configurePlatforms = [];
dontStrip = true; dontStrip = true;
} // optionalAttrs isMingw { } // optionalAttrs isMingw {
propagatedBuildInputs = [ ]; propagatedBuildInputs = [ ];

View file

@ -53,7 +53,7 @@ stdenv.mkDerivation rec {
crossAttrs = { crossAttrs = {
dontStrip = static; dontStrip = static;
dontSetConfigureCross = true; configurePlatforms = [];
} // stdenv.lib.optionalAttrs (stdenv.cross.libc == "msvcrt") { } // stdenv.lib.optionalAttrs (stdenv.cross.libc == "msvcrt") {
installFlags = [ installFlags = [
"BINARY_PATH=$(out)/bin" "BINARY_PATH=$(out)/bin"

View file

@ -56,8 +56,15 @@ rec {
# Return a modified stdenv that adds a cross compiler to the # Return a modified stdenv that adds a cross compiler to the
# builds. # builds.
makeStdenvCross = stdenvOrig: cross: cc: let makeStdenvCross = { stdenv
stdenv = stdenvOrig.override { , 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; inherit cc;
allowedRequisites = null; allowedRequisites = null;
@ -70,7 +77,12 @@ rec {
mkDerivation = mkDerivation =
{ name ? "", buildInputs ? [], nativeBuildInputs ? [] { name ? "", buildInputs ? [], nativeBuildInputs ? []
, propagatedBuildInputs ? [], propagatedNativeBuildInputs ? [] , 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: } @ args:
let let
@ -93,16 +105,23 @@ rec {
nativeInputsFromBuildInputs = stdenv.lib.filter hostAsNativeDrv buildInputsNotNull; nativeInputsFromBuildInputs = stdenv.lib.filter hostAsNativeDrv buildInputsNotNull;
in in
stdenv.mkDerivation (args // { stdenv.mkDerivation (args // {
name = name + "-" + cross.config; name = name + "-" + hostPlatform.config;
nativeBuildInputs = nativeBuildInputs nativeBuildInputs = nativeBuildInputs
++ nativeInputsFromBuildInputs ++ nativeInputsFromBuildInputs
++ stdenv.lib.optional selfNativeBuildInput nativeDrv ++ stdenv.lib.optional selfNativeBuildInput nativeDrv
# without proper `file` command, libtool sometimes fails # without proper `file` command, libtool sometimes fails
# to recognize 64-bit DLLs # to recognize 64-bit DLLs
++ stdenv.lib.optional (cross.config == "x86_64-w64-mingw32") pkgs.file ++ stdenv.lib.optional (hostPlatform.config == "x86_64-w64-mingw32") pkgs.file
++ stdenv.lib.optional (cross.config == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook ++ 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 # Cross-linking dynamic libraries, every buildInput should
# be propagated because ld needs the -rpath-link to find # be propagated because ld needs the -rpath-link to find
# any library needed to link the program dynamically at # any library needed to link the program dynamically at
@ -111,7 +130,7 @@ rec {
propagatedBuildInputs = propagatedBuildInputs ++ buildInputs; propagatedBuildInputs = propagatedBuildInputs ++ buildInputs;
propagatedNativeBuildInputs = propagatedNativeBuildInputs; propagatedNativeBuildInputs = propagatedNativeBuildInputs;
crossConfig = cross.config; crossConfig = hostPlatform.config;
} // args.crossAttrs or {}); } // args.crossAttrs or {});
}; };

View file

@ -31,12 +31,15 @@ in bootStages ++ [
targetPlatform = crossSystem; targetPlatform = crossSystem;
inherit config overlays; inherit config overlays;
selfBuild = false; selfBuild = false;
stdenv = buildPackages.makeStdenvCross stdenv = buildPackages.makeStdenvCross {
buildPackages.stdenv inherit (buildPackages) stdenv;
crossSystem buildPlatform = localSystem;
(if crossSystem.useiOSCross or false hostPlatform = crossSystem;
then buildPackages.darwin.ios-cross targetPlatform = crossSystem;
else buildPackages.gccCrossStageFinal); cc = if crossSystem.useiOSCross or false
then buildPackages.darwin.ios-cross
else buildPackages.gccCrossStageFinal;
};
}) })
] ]

View file

@ -7802,10 +7802,11 @@ with pkgs;
installLocales = config.glibc.locales or false; installLocales = config.glibc.locales or false;
# Can't just overrideCC, because then the stdenv-cross mkDerivation will be # Can't just overrideCC, because then the stdenv-cross mkDerivation will be
# thrown away. TODO: find a better solution for this. # thrown away. TODO: find a better solution for this.
stdenv = buildPackages.makeStdenvCross stdenv = buildPackages.makeStdenvCross {
buildPackages.buildPackages.stdenv inherit (buildPackages.buildPackages) stdenv;
buildPackages.targetPlatform inherit buildPlatform hostPlatform targetPlatform;
buildPackages.gccCrossStageStatic; cc = buildPackages.gccCrossStageStatic;
};
}; };
# We can choose: # We can choose: