stdenv: Move some logic from cross adapter to stdenv proper

Eventually the adapter will be removed.  Moved is

 - Name suffix from hostPlatform

 - configurePlatforms

   To not cause more breakage, the default is currently [], but
   eventually it will be [ "build" "host" ], as the cross adapter makes
   it today.
This commit is contained in:
John Ericson 2017-07-12 19:00:19 -04:00
parent 30a1420414
commit e826a6a247
2 changed files with 23 additions and 19 deletions

View File

@ -73,15 +73,8 @@ rec {
}; };
in stdenv // { in stdenv // {
mkDerivation = mkDerivation =
{ name ? "", buildInputs ? [], nativeBuildInputs ? [] { buildInputs ? [], nativeBuildInputs ? []
, propagatedBuildInputs ? [], propagatedNativeBuildInputs ? [] , propagatedBuildInputs ? [], propagatedNativeBuildInputs ? []
, # Disabling the tests by default when cross compiling, as usually the
# tests rely on being able to run produced binaries.
doCheck ? 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 , selfNativeBuildInput ? args.crossAttrs.selfNativeBuildInput or false
, ... , ...
} @ args: } @ args:
@ -106,7 +99,6 @@ rec {
nativeInputsFromBuildInputs = stdenv.lib.filter hostAsNativeDrv buildInputsNotNull; nativeInputsFromBuildInputs = stdenv.lib.filter hostAsNativeDrv buildInputsNotNull;
in in
stdenv.mkDerivation (args // { stdenv.mkDerivation (args // {
name = name + "-" + hostPlatform.config;
nativeBuildInputs = nativeBuildInputs nativeBuildInputs = nativeBuildInputs
++ nativeInputsFromBuildInputs ++ nativeInputsFromBuildInputs
++ stdenv.lib.optional selfNativeBuildInput nativeDrv ++ stdenv.lib.optional selfNativeBuildInput nativeDrv
@ -116,15 +108,6 @@ rec {
++ stdenv.lib.optional (hostPlatform.config == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook ++ stdenv.lib.optional (hostPlatform.config == "aarch64-linux-gnu") pkgs.updateAutotoolsGnuConfigScriptsHook
; ;
inherit doCheck;
# 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

View File

@ -12,12 +12,22 @@ rec {
# * https://nixos.org/nix/manual/#ssec-derivation # * https://nixos.org/nix/manual/#ssec-derivation
# Explanation about derivations in general # Explanation about derivations in general
mkDerivation = mkDerivation =
{ nativeBuildInputs ? [] { name ? ""
, nativeBuildInputs ? []
, buildInputs ? [] , buildInputs ? []
, propagatedNativeBuildInputs ? [] , propagatedNativeBuildInputs ? []
, propagatedBuildInputs ? [] , propagatedBuildInputs ? []
, configureFlags ? []
, # Target is not included by default because most programs don't care.
# Including it then would cause needless mass rebuilds.
#
# TODO(@Ericson2314): Make [ "build" "host" ] always the default.
configurePlatforms ? lib.optionals
(stdenv.hostPlatform != stdenv.buildPlatform)
[ "build" "host" ]
, crossConfig ? null , crossConfig ? null
, meta ? {} , meta ? {}
, passthru ? {} , passthru ? {}
@ -72,6 +82,9 @@ rec {
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (lib.concatLists propagatedDependencies')); lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or []) (lib.concatLists propagatedDependencies'));
in in
{ {
name = name + lib.optionalString
(stdenv.hostPlatform != stdenv.buildPlatform)
stdenv.hostPlatform.config;
builder = attrs.realBuilder or stdenv.shell; builder = attrs.realBuilder or stdenv.shell;
args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)]; args = attrs.args or ["-e" (attrs.builder or ./default-builder.sh)];
inherit stdenv; inherit stdenv;
@ -84,6 +97,14 @@ rec {
propagatedNativeBuildInputs = lib.elemAt propagatedDependencies' 0; propagatedNativeBuildInputs = lib.elemAt propagatedDependencies' 0;
propagatedBuildInputs = lib.elemAt propagatedDependencies' 1; propagatedBuildInputs = lib.elemAt propagatedDependencies' 1;
# This parameter is sometimes a string and sometimes a list, yuck
configureFlags = let inherit (lib) optional elem; in
(if lib.isString configureFlags then [configureFlags] else configureFlags)
++ optional (elem "build" configurePlatforms) "--build=${stdenv.buildPlatform.config}"
++ optional (elem "host" configurePlatforms) "--host=${stdenv.hostPlatform.config}"
++ optional (elem "target" configurePlatforms) "--target=${stdenv.targetPlatform.config}";
} // lib.optionalAttrs (stdenv.buildPlatform.isDarwin) { } // lib.optionalAttrs (stdenv.buildPlatform.isDarwin) {
# TODO: remove lib.unique once nix has a list canonicalization primitive # TODO: remove lib.unique once nix has a list canonicalization primitive
__sandboxProfile = __sandboxProfile =