top-level: {build,host,target}Platform are defined in the stdenv instead

See #27069 for a discussion of this
This commit is contained in:
John Ericson 2017-07-05 21:47:48 -04:00
parent afc2023993
commit a302d7360f
12 changed files with 90 additions and 124 deletions

View File

@ -10,7 +10,6 @@
, zlib ? null, extraPackages ? [], extraBuildCommands ? ""
, dyld ? null # TODO: should this be a setup-hook on dyld?
, isGNU ? false, isClang ? cc.isClang or false, gnugrep ? null
, hostPlatform, targetPlatform
, runCommand ? null
}:
@ -22,12 +21,14 @@ assert !nativeTools ->
assert !(nativeLibc && noLibc);
assert (noLibc || nativeLibc) == (libc == null);
assert targetPlatform != hostPlatform -> runCommand != null;
assert stdenv.targetPlatform != stdenv.hostPlatform -> runCommand != null;
# For ghdl (the vhdl language provider to gcc) we need zlib in the wrapper.
assert cc.langVhdl or false -> zlib != null;
let
inherit (stdenv) hostPlatform targetPlatform;
# Prefix for binaries. Customarily ends with a dash separator.
#
# TODO(@Ericson2314) Make unconditional, or optional but always true by

View File

@ -61,11 +61,9 @@ rec {
, 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
buildPlatform hostPlatform targetPlatform
cc;
allowedRequisites = null;

View File

@ -14,21 +14,18 @@ in bootStages ++ [
# Build Packages
(vanillaPackages: {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = crossSystem;
inherit config overlays;
selfBuild = false;
stdenv =
assert vanillaPackages.hostPlatform == localSystem;
assert vanillaPackages.targetPlatform == localSystem;
vanillaPackages.stdenv.override { targetPlatform = crossSystem; };
# It's OK to change the built-time dependencies
allowCustomOverrides = true;
inherit (vanillaPackages) stdenv;
})
# Run Packages
(buildPackages: {
buildPlatform = localSystem;
hostPlatform = crossSystem;
targetPlatform = crossSystem;
inherit config overlays;
selfBuild = false;
stdenv = buildPackages.makeStdenvCross {

View File

@ -15,11 +15,11 @@ in bootStages ++ [
# Additional stage, built using custom stdenv
(vanillaPackages: {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config overlays;
stdenv = config.replaceStdenv { pkgs = vanillaPackages; };
stdenv =
assert vanillaPackages.hostPlatform == localSystem;
assert vanillaPackages.targetPlatform == localSystem;
config.replaceStdenv { pkgs = vanillaPackages; };
})
]

View File

@ -65,6 +65,10 @@ in rec {
name = "stdenv-darwin-boot-${toString step}";
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
cc = if isNull last then "/dev/null" else import ../../build-support/cc-wrapper {
inherit shell;
inherit (last) stdenv;
@ -73,8 +77,6 @@ in rec {
nativeTools = true;
nativePrefix = bootstrapTools;
nativeLibc = false;
hostPlatform = localSystem;
targetPlatform = localSystem;
libc = last.pkgs.darwin.Libsystem;
isClang = true;
cc = { name = "clang-9.9.9"; outPath = bootstrapTools; };
@ -90,9 +92,6 @@ in rec {
'';
initialPath = [ bootstrapTools ];
hostPlatform = localSystem;
targetPlatform = localSystem;
fetchurlBoot = import ../../build-support/fetchurl {
stdenv = stage0.stdenv;
curl = bootstrapTools;
@ -107,9 +106,6 @@ in rec {
};
in {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config overlays;
stdenv = thisStdenv;
};
@ -279,6 +275,10 @@ in rec {
name = "stdenv-darwin";
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
preHook = commonPreHook + ''
export PATH_LOCALE=${pkgs.darwin.locale}/share/locale
'';
@ -286,9 +286,6 @@ in rec {
stdenvSandboxProfile = binShClosure + libSystemProfile;
extraSandboxProfile = binShClosure + libSystemProfile;
hostPlatform = localSystem;
targetPlatform = localSystem;
initialPath = import ../common-path.nix { inherit pkgs; };
shell = "${pkgs.bash}/bin/bash";
@ -297,8 +294,6 @@ in rec {
inherit shell;
nativeTools = false;
nativeLibc = false;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit (pkgs) coreutils binutils gnugrep;
inherit (pkgs.darwin) dyld;
cc = pkgs.llvmPackages.clang-unwrapped;
@ -338,9 +333,6 @@ in rec {
stage3
stage4
(prevStage: {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config overlays;
stdenv = stdenvDarwin prevStage;
})

View File

@ -35,6 +35,9 @@ let inherit (localSystem) system; in
stdenv = import ../generic {
name = "stdenv-freebsd-boot-1";
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config;
initialPath = [ "/" "/usr" ];
hostPlatform = localSystem;
@ -52,6 +55,9 @@ let inherit (localSystem) system; in
stdenv = import ../generic {
name = "stdenv-freebsd-boot-0";
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config;
initialPath = [ prevStage.bootstrapTools ];
inherit (prevStage.stdenv)
@ -62,12 +68,12 @@ let inherit (localSystem) system; in
})
(prevStage: {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config overlays;
stdenv = import ../generic {
name = "stdenv-freebsd-boot-3";
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config;
inherit (prevStage.stdenv)
@ -77,8 +83,6 @@ let inherit (localSystem) system; in
nativeTools = true;
nativePrefix = "/usr";
nativeLibc = true;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit (prevStage) stdenv;
cc = {
name = "clang-9.9.9";

View File

@ -15,18 +15,32 @@ let lib = import ../../../lib; in lib.makeOverridable (
, stdenvSandboxProfile ? ""
, extraSandboxProfile ? ""
, # The platforms here do *not* correspond to the stage the stdenv is
# used in, but rather the previous one, in which it was built. We
# use the latter two platforms, like a cross compiler, because the
# stand environment is a build tool if you squint at it, and because
# neither of these are used when building stdenv so we know the
# build platform is irrelevant.
hostPlatform, targetPlatform
## Platform parameters
##
## The "build" "host" "target" terminology below comes from GNU Autotools. See
## its documentation for more information on what those words mean. Note that
## each should always be defined, even when not cross compiling.
##
## For purposes of bootstrapping, think of each stage as a "sliding window"
## over a list of platforms. Specifically, the host platform of the previous
## stage becomes the build platform of the current one, and likewise the
## target platform of the previous stage becomes the host platform of the
## current one.
##
, # The platform on which packages are built. Consists of `system`, a
# string (e.g.,`i686-linux') identifying the most import attributes of the
# build platform, and `platform` a set of other details.
buildPlatform
, # The platform on which packages run.
hostPlatform
, # The platform which build tools (especially compilers) build for in this stage,
targetPlatform
}:
let
inherit (targetPlatform) system;
defaultNativeBuildInputs = extraBuildInputs ++
[ ../../build-support/setup-hooks/move-docs.sh
../../build-support/setup-hooks/compress-man-pages.sh
@ -49,7 +63,11 @@ let
derivation (
(if isNull allowedRequisites then {} else { allowedRequisites = allowedRequisites ++ defaultNativeBuildInputs; }) //
{
inherit system name;
inherit name;
# Nix itself uses the `system` field of a derivation to decide where to
# build it. This is a bit confusing for cross compilation.
inherit (buildPlatform) system;
builder = shell;
@ -59,7 +77,7 @@ let
inherit preHook initialPath shell defaultNativeBuildInputs;
}
// lib.optionalAttrs hostPlatform.isDarwin {
// lib.optionalAttrs buildPlatform.isDarwin {
__sandboxProfile = stdenvSandboxProfile;
__impureHostDeps = __stdenvImpureHostDeps;
})
@ -71,6 +89,8 @@ let
platforms = lib.platforms.all;
};
inherit buildPlatform hostPlatform targetPlatform;
inherit extraBuildInputs __extraImpureHostDeps extraSandboxProfile;
# Utility flags to test the type of platform.
@ -85,9 +105,6 @@ let
inherit (import ./make-derivation.nix {
inherit lib config stdenv;
# TODO(@Ericson2314): Remove
inherit
hostPlatform targetPlatform;
}) mkDerivation;
# For convenience, bring in the library functions in lib/ so

View File

@ -1,8 +1,4 @@
{ lib, config, stdenv
# TODO(@Ericson2314): get off stdenv
, hostPlatform, targetPlatform
}:
{ lib, config, stdenv }:
rec {
# `mkDerivation` wraps the builtin `derivation` function to
@ -49,12 +45,12 @@ rec {
outputs' =
outputs ++
(if separateDebugInfo then assert targetPlatform.isLinux; [ "debug" ] else []);
(if separateDebugInfo then assert stdenv.hostPlatform.isLinux; [ "debug" ] else []);
dependencies' = let
justMap = map lib.chooseDevOutputs dependencies;
nativeBuildInputs = lib.elemAt justMap 0
++ lib.optional targetPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh;
++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh;
buildInputs = lib.elemAt justMap 1
# TODO(@Ericson2314): Should instead also be appended to `nativeBuildInputs`.
++ lib.optional separateDebugInfo ../../build-support/setup-hooks/separate-debug-info.sh;
@ -82,7 +78,7 @@ rec {
builder = attrs.realBuilder or stdenv.shell;
args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
inherit stdenv;
system = stdenv.system; # TODO(@Ericson2314): be correct about cross compilation
inherit (stdenv) system;
userHook = config.stdenv.userHook or null;
__ignoreNulls = true;
@ -91,7 +87,7 @@ rec {
propagatedNativeBuildInputs = lib.elemAt propagatedDependencies' 0;
propagatedBuildInputs = lib.elemAt propagatedDependencies' 1;
} // lib.optionalAttrs (hostPlatform.isDarwin) {
} // lib.optionalAttrs (stdenv.buildPlatform.isDarwin) {
# TODO: remove lib.unique once nix has a list canonicalization primitive
__sandboxProfile =
let profiles = [ stdenv.extraSandboxProfile ] ++ computedSandboxProfile ++ computedPropagatedSandboxProfile ++ [ propagatedSandboxProfile sandboxProfile ];
@ -139,7 +135,9 @@ rec {
{
inherit lib config meta derivationArg;
mkDerivationArg = attrs;
inherit (stdenv) system; # TODO: cross-compilation?
# Nix itself uses the `system` field of a derivation to decide where
# to build it. This is a bit confusing for cross compilation.
inherit (stdenv) system;
}))
( {
overrideAttrs = f: mkDerivation (attrs // (f attrs));

View File

@ -52,8 +52,11 @@ let
let
thisStdenv = import ../generic {
inherit config extraBuildInputs;
name = "stdenv-linux-boot";
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config extraBuildInputs;
preHook =
''
# Don't patch #!/interpreter because it leads to retained
@ -64,9 +67,6 @@ let
shell = "${bootstrapTools}/bin/bash";
initialPath = [bootstrapTools];
hostPlatform = localSystem;
targetPlatform = localSystem;
fetchurlBoot = import ../../build-support/fetchurl/boot.nix {
inherit system;
};
@ -76,8 +76,6 @@ let
else lib.makeOverridable (import ../../build-support/cc-wrapper) {
nativeTools = false;
nativeLibc = false;
hostPlatform = localSystem;
targetPlatform = localSystem;
cc = prevStage.gcc-unwrapped;
isGNU = true;
libc = prevStage.glibc;
@ -99,9 +97,6 @@ let
};
in {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config overlays;
stdenv = thisStdenv;
};
@ -241,8 +236,6 @@ in
nativeTools = false;
nativeLibc = false;
isGNU = true;
hostPlatform = localSystem;
targetPlatform = localSystem;
cc = prevStage.gcc-unwrapped;
libc = self.glibc;
inherit (self) stdenv binutils coreutils gnugrep;
@ -263,11 +256,11 @@ in
# dependency (`nix-store -qR') on bootstrapTools or the first
# binutils built.
(prevStage: {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config overlays;
stdenv = import ../generic rec {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config;
preHook = ''
@ -280,9 +273,6 @@ in
initialPath =
((import ../common-path.nix) {pkgs = prevStage;});
hostPlatform = localSystem;
targetPlatform = localSystem;
extraBuildInputs = [ prevStage.patchelf prevStage.paxctl ] ++
# Many tarballs come with obsolete config.sub/config.guess that don't recognize aarch64.
lib.optional (system == "aarch64-linux") prevStage.updateAutotoolsGnuConfigScriptsHook;

View File

@ -81,6 +81,7 @@ let
{ cc, fetchurl, extraPath ? [], overrides ? (self: super: { }) }:
import ../generic {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
@ -125,8 +126,6 @@ in
"i686-solaris" = "/usr/gnu";
"x86_64-solaris" = "/opt/local/gcc47";
}.${system} or "/usr";
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit stdenv;
};
@ -140,9 +139,6 @@ in
# First build a stdenv based only on tools outside the store.
(prevStage: {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config overlays;
stdenv = makeStdenv {
inherit (prevStage) cc fetchurl;
@ -152,9 +148,6 @@ in
# Using that, build a stdenv that adds the xz command (which most systems
# don't have, so we mustn't rely on the native environment providing it).
(prevStage: {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config overlays;
stdenv = makeStdenv {
inherit (prevStage.stdenv) cc fetchurl;

View File

@ -10,10 +10,13 @@ bootStages ++ [
(prevStage: let
inherit (prevStage) stdenv;
in {
inherit (prevStage) buildPlatform hostPlatform targetPlatform;
inherit config overlays;
stdenv = import ../generic rec {
buildPlatform = localSystem;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit config;
preHook = ''
@ -30,8 +33,6 @@ bootStages ++ [
nativeTools = false;
nativePrefix = stdenv.lib.optionalString hostPlatform.isSunOS "/usr";
nativeLibc = true;
hostPlatform = localSystem;
targetPlatform = localSystem;
inherit stdenv;
inherit (prevStage) binutils coreutils gnugrep;
cc = prevStage.gcc.cc;

View File

@ -18,30 +18,6 @@
, # Use to reevaluate Nixpkgs; a dirty hack that should be removed
nixpkgsFun
## Platform parameters
##
## The "build" "host" "target" terminology below comes from GNU Autotools. See
## its documentation for more information on what those words mean. Note that
## each should always be defined, even when not cross compiling.
##
## For purposes of bootstrapping, think of each stage as a "sliding window"
## over a list of platforms. Specifically, the host platform of the previous
## stage becomes the build platform of the current one, and likewise the
## target platform of the previous stage becomes the host platform of the
## current one.
##
, # The platform on which packages are built. Consists of `system`, a
# string (e.g.,`i686-linux') identifying the most import attributes of the
# build platform, and `platform` a set of other details.
buildPlatform
, # The platform on which packages run.
hostPlatform
, # The platform which build tools (especially compilers) build for in this stage,
targetPlatform
## Other parameters
##
@ -69,10 +45,10 @@
, # Non-GNU/Linux OSes are currently "impure" platforms, with their libc
# outside of the store. Thus, GCC, GFortran, & co. must always look for files
# in standard system directories (/usr/include, etc.)
noSysDirs ? buildPlatform.system != "x86_64-freebsd"
&& buildPlatform.system != "i686-freebsd"
&& buildPlatform.system != "x86_64-solaris"
&& buildPlatform.system != "x86_64-kfreebsd-gnu"
noSysDirs ? stdenv.buildPlatform.system != "x86_64-freebsd"
&& stdenv.buildPlatform.system != "i686-freebsd"
&& stdenv.buildPlatform.system != "x86_64-solaris"
&& stdenv.buildPlatform.system != "x86_64-kfreebsd-gnu"
, # The configuration attribute set
config
@ -98,19 +74,18 @@ let
// { recurseForDerivations = false; };
__targetPackages = (if __targetPackages == null then self else __targetPackages)
// { recurseForDerivations = false; };
inherit stdenv
buildPlatform hostPlatform targetPlatform;
inherit stdenv;
};
# The old identifiers for cross-compiling. These should eventually be removed,
# and the packages that rely on them refactored accordingly.
platformCompat = self: super: let
# TODO(@Ericson2314) this causes infinite recursion
#inherit (self) buildPlatform hostPlatform targetPlatform;
inherit (super.stdenv) buildPlatform hostPlatform targetPlatform;
in {
stdenv = super.stdenv // {
inherit (buildPlatform) platform;
inherit (super.stdenv.buildPlatform) platform;
};
inherit buildPlatform hostPlatform targetPlatform;
inherit (buildPlatform) system platform;
};