From a302d7360f201cc4fcfb4a43a432b31536795507 Mon Sep 17 00:00:00 2001 From: John Ericson Date: Wed, 5 Jul 2017 21:47:48 -0400 Subject: top-level: {build,host,target}Platform are defined in the stdenv instead See #27069 for a discussion of this --- pkgs/stdenv/generic/default.nix | 45 +++++++++++++++++++++++---------- pkgs/stdenv/generic/make-derivation.nix | 18 ++++++------- 2 files changed, 39 insertions(+), 24 deletions(-) (limited to 'pkgs/stdenv/generic') diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix index d7b736a12e56..a5d3c5a8ff5c 100644 --- a/pkgs/stdenv/generic/default.nix +++ b/pkgs/stdenv/generic/default.nix @@ -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 diff --git a/pkgs/stdenv/generic/make-derivation.nix b/pkgs/stdenv/generic/make-derivation.nix index ec48e5374139..31b0428eeb2b 100644 --- a/pkgs/stdenv/generic/make-derivation.nix +++ b/pkgs/stdenv/generic/make-derivation.nix @@ -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)); -- cgit 1.4.1