Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: add depsBuildHost depsHostTarget #227502

Draft
wants to merge 3 commits into
base: staging
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pkgs/stdenv/adapters.nix
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ rec {
# Used to override packages in stdenv like Make. Should not be used
# for other dependencies.
overrideInStdenv = stdenv: pkgs:
stdenv.override (prev: { allowedRequisites = null; extraBuildInputs = (prev.extraBuildInputs or []) ++ pkgs; });
stdenv.override (prev: { allowedRequisites = null; extraDepsHostTarget = (prev.extraDepsHostTarget or []) ++ pkgs; });


# Override the setup script of stdenv. Useful for testing new
Expand Down Expand Up @@ -68,7 +68,7 @@ rec {
];
}));
} // lib.optionalAttrs (stdenv0.hostPlatform.libc == "libc") {
extraBuildInputs = (old.extraBuildInputs or []) ++ [
extraDepsHostTarget = (old.extraDepsHostTarget or []) ++ [
pkgs.glibc.static
];
});
Expand All @@ -93,8 +93,8 @@ rec {
# Best effort static binaries. Will still be linked to libSystem,
# but more portable than Nix store binaries.
makeStaticDarwin = stdenv: stdenv.override (old: {
# extraBuildInputs are dropped in cross.nix, but darwin still needs them
extraBuildInputs = [ pkgs.buildPackages.darwin.CF ];
# extraDepsHostTarget are dropped in cross.nix, but darwin still needs them
extraDepsHostTarget = [ pkgs.buildPackages.darwin.CF ];
mkDerivationFromStdenv = extendMkDerivationArgs old (args: {
NIX_CFLAGS_LINK = toString (args.NIX_CFLAGS_LINK or "")
+ lib.optionalString (stdenv.cc.isGNU or false) " -static-libgcc";
Expand Down
5 changes: 3 additions & 2 deletions pkgs/stdenv/cross/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ in lib.init bootStages ++ [
# Prior overrides are surely not valid as packages built with this run on
# a different platform, and so are disabled.
overrides = _: _: {};
extraBuildInputs = [ ] # Old ones run on wrong platform
extraBuildInputs = [ ]; # Old ones run on wrong platform
extraDepsHostTarget = [ ] # Old ones run on wrong platform
++ lib.optionals hostPlatform.isDarwin [ buildPackages.targetPackages.darwin.apple_sdk.frameworks.CoreFoundation ]
;
allowedRequisites = null;
Expand All @@ -75,7 +76,7 @@ in lib.init bootStages ++ [
then buildPackages.llvmPackages.clangUseLLVM
else buildPackages.gcc;

extraNativeBuildInputs = old.extraNativeBuildInputs
extraDepsBuildHost = old.extraDepsBuildHost
++ lib.optionals
(hostPlatform.isLinux && !buildPlatform.isLinux)
[ buildPackages.patchelf ]
Expand Down
32 changes: 16 additions & 16 deletions pkgs/stdenv/darwin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ rec {
stageFun = step: last: { shell ? "${bootstrapTools}/bin/bash"
, overrides ? (self: super: { })
, extraPreHook ? ""
, extraNativeBuildInputs
, extraBuildInputs
, extraDepsBuildHost
, extraDepsHostTarget
, libcxx
, allowedRequisites ? null
}:
Expand Down Expand Up @@ -148,9 +148,9 @@ rec {
thisStdenv = import ../generic {
name = "${name}-stdenv-darwin";

inherit config shell extraBuildInputs;
inherit config shell extraDepsHostTarget;

extraNativeBuildInputs = extraNativeBuildInputs ++ lib.optionals doUpdateAutoTools [
extraDepsBuildHost = extraDepsBuildHost ++ lib.optionals doUpdateAutoTools [
last.pkgs.updateAutotoolsGnuConfigScriptsHook
last.pkgs.gnu-config
];
Expand Down Expand Up @@ -364,8 +364,8 @@ rec {
};
};

extraNativeBuildInputs = [ ];
extraBuildInputs = [ ];
extraDepsBuildHost = [ ];
extraDepsHostTarget = [ ];
libcxx = null;
};

Expand Down Expand Up @@ -411,8 +411,8 @@ rec {
in
with prevStage; stageFun 1 prevStage {
extraPreHook = "export NIX_CFLAGS_COMPILE+=\" -F${bootstrapTools}/Library/Frameworks\"";
extraNativeBuildInputs = [ ];
extraBuildInputs = [ pkgs.darwin.CF ];
extraDepsBuildHost = [ ];
extraDepsHostTarget = [ pkgs.darwin.CF ];
libcxx = pkgs."${finalLlvmPackages}".libcxx;

allowedRequisites =
Expand Down Expand Up @@ -469,8 +469,8 @@ rec {
export PATH_LOCALE=${pkgs.darwin.locale}/share/locale
'';

extraNativeBuildInputs = [ pkgs.xz ];
extraBuildInputs = [ pkgs.darwin.CF ];
extraDepsBuildHost = [ pkgs.xz ];
extraDepsHostTarget = [ pkgs.darwin.CF ];
libcxx = pkgs."${finalLlvmPackages}".libcxx;

allowedRequisites =
Expand Down Expand Up @@ -539,8 +539,8 @@ rec {
# enables patchShebangs above. Unfortunately, patchShebangs ignores our $SHELL setting
# and instead goes by $PATH, which happens to contain bootstrapTools. So it goes and
# patches our shebangs back to point at bootstrapTools. This makes sure bash comes first.
extraNativeBuildInputs = with pkgs; [ xz ];
extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ];
extraDepsBuildHost = with pkgs; [ xz ];
extraDepsHostTarget = [ pkgs.darwin.CF pkgs.bash ];
libcxx = pkgs."${finalLlvmPackages}".libcxx;

extraPreHook = ''
Expand Down Expand Up @@ -625,8 +625,8 @@ rec {
in
with prevStage; stageFun 4 prevStage {
shell = "${pkgs.bash}/bin/bash";
extraNativeBuildInputs = with pkgs; [ xz ];
extraBuildInputs = [ pkgs.darwin.CF pkgs.bash ];
extraDepsBuildHost = with pkgs; [ xz ];
extraDepsHostTarget = [ pkgs.darwin.CF pkgs.bash ];
libcxx = pkgs."${finalLlvmPackages}".libcxx;

extraPreHook = ''
Expand Down Expand Up @@ -692,11 +692,11 @@ rec {

cc = pkgs."${finalLlvmPackages}".libcxxClang;

extraNativeBuildInputs = lib.optionals localSystem.isAarch64 [
extraDepsBuildHost = lib.optionals localSystem.isAarch64 [
pkgs.updateAutotoolsGnuConfigScriptsHook
];

extraBuildInputs = [ pkgs.darwin.CF ];
extraDepsHostTarget = [ pkgs.darwin.CF ];

extraAttrs = {
libc = pkgs.darwin.Libsystem;
Expand Down
4 changes: 2 additions & 2 deletions pkgs/stdenv/generic/builder.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ mkdir $out
{
echo "export SHELL=$shell"
echo "initialPath=\"$initialPath\""
echo "defaultNativeBuildInputs=\"$defaultNativeBuildInputs\""
echo "defaultBuildInputs=\"$defaultBuildInputs\""
echo "defaultDepsBuildHost=\"$defaultDepsBuildHost\""
echo "defaultDepsHostTarget=\"$defaultDepsHostTarget\""
echo "$preHook"
cat "$setup"
} > "$out/setup"
Expand Down
13 changes: 8 additions & 5 deletions pkgs/stdenv/generic/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ argsStdenv@{ name ? "stdenv", preHook ? "", initialPath

, extraNativeBuildInputs ? []
, extraBuildInputs ? []
, extraDepsBuildHost ? []
, extraDepsHostTarget ? []
, __stdenvImpureHostDeps ? []
, __extraImpureHostDeps ? []
, stdenvSandboxProfile ? ""
Expand Down Expand Up @@ -56,7 +58,7 @@ argsStdenv@{ name ? "stdenv", preHook ? "", initialPath
}:

let
defaultNativeBuildInputs = extraNativeBuildInputs ++
defaultDepsBuildHost = extraDepsBuildHost ++ extraNativeBuildInputs ++
[
../../build-support/setup-hooks/audit-tmpdir.sh
../../build-support/setup-hooks/compress-man-pages.sh
Expand All @@ -73,7 +75,7 @@ let
../../build-support/setup-hooks/strip.sh
] ++ lib.optionals hasCC [ cc ];

defaultBuildInputs = extraBuildInputs;
defaultDepsHostTarget = extraDepsHostTarget ++ extraBuildInputs;

stdenv = (stdenv-overridable argsStdenv);

Expand All @@ -82,7 +84,7 @@ let
derivation (
lib.optionalAttrs (allowedRequisites != null) {
allowedRequisites = allowedRequisites
++ defaultNativeBuildInputs ++ defaultBuildInputs;
++ defaultDepsBuildHost ++ defaultDepsHostTarget;
}
// lib.optionalAttrs config.contentAddressedByDefault {
__contentAddressed = true;
Expand Down Expand Up @@ -124,7 +126,7 @@ let
;

inherit initialPath shell
defaultNativeBuildInputs defaultBuildInputs;
defaultDepsBuildHost defaultDepsHostTarget;
}
// lib.optionalAttrs buildPlatform.isDarwin {
__sandboxProfile = stdenvSandboxProfile;
Expand All @@ -140,7 +142,8 @@ let

inherit buildPlatform hostPlatform targetPlatform;

inherit extraNativeBuildInputs extraBuildInputs
inherit extraDepsBuildHost extraDepsHostTarget
extraNativeBuildInputs extraBuildInputs
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
extraNativeBuildInputs extraBuildInputs

__extraImpureHostDeps extraSandboxProfile;

# Utility flags to test the type of platform.
Expand Down
33 changes: 21 additions & 12 deletions pkgs/stdenv/generic/make-derivation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,17 @@ let
, depsBuildBuildPropagated ? [] # -1 -> -1
, nativeBuildInputs ? [] # -1 -> 0 N.B. Legacy name
, propagatedNativeBuildInputs ? [] # -1 -> 0 N.B. Legacy name
, depsBuildHost ? [] # -1 -> 0
, depsBuildHostPropagated ? [] # -1 -> 0
, depsBuildTarget ? [] # -1 -> 1
, depsBuildTargetPropagated ? [] # -1 -> 1

, depsHostHost ? [] # 0 -> 0
, depsHostHostPropagated ? [] # 0 -> 0
, buildInputs ? [] # 0 -> 1 N.B. Legacy name
, propagatedBuildInputs ? [] # 0 -> 1 N.B. Legacy name
, depsHostTarget ? [] # 0 -> 1 N.B.
, depsHostTargetPropagated ? [] # 0 -> 1 N.B.

, depsTargetTarget ? [] # 1 -> 1
, depsTargetTargetPropagated ? [] # 1 -> 1
Expand Down Expand Up @@ -184,6 +188,7 @@ let
noNonNativeDeps = builtins.length (depsBuildTarget ++ depsBuildTargetPropagated
++ depsHostHost ++ depsHostHostPropagated
++ buildInputs ++ propagatedBuildInputs
++ depsBuildTarget ++ depsBuildTargetPropagated
++ depsTargetTarget ++ depsTargetTargetPropagated) == 0;
dontAddHostSuffix = attrs ? outputHash && !noNonNativeDeps || !stdenv.hasCC;

Expand Down Expand Up @@ -224,29 +229,29 @@ then abort ("mkDerivation was called with unsupported hardening flags: " + lib.g
else let
doCheck = doCheck';
doInstallCheck = doInstallCheck';
buildInputs' = buildInputs
depsHostTarget' = depsHostTarget ++ buildInputs
++ lib.optionals doCheck checkInputs
++ lib.optionals doInstallCheck installCheckInputs;
nativeBuildInputs' = nativeBuildInputs
depsBuildHost' = depsBuildHost ++ nativeBuildInputs
++ lib.optional separateDebugInfo' ../../build-support/setup-hooks/separate-debug-info.sh
++ lib.optional stdenv.hostPlatform.isWindows ../../build-support/setup-hooks/win-dll-link.sh
++ lib.optionals doCheck nativeCheckInputs
++ lib.optionals doInstallCheck nativeInstallCheckInputs;

outputs = outputs';

references = nativeBuildInputs ++ buildInputs
++ propagatedNativeBuildInputs ++ propagatedBuildInputs;
references = depsBuildHost ++ nativeBuildInputs ++ depsHostTarget ++ buildInputs
++ depsBuildHostPropagated ++ propagatedNativeBuildInputs ++ depsHostTargetPropagated ++ propagatedBuildInputs;

dependencies = map (map lib.chooseDevOutputs) [
[
(map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuild" depsBuildBuild))
(map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "nativeBuildInputs" nativeBuildInputs'))
(map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "depsBuildHost/nativeBuildInputs" depsBuildHost'))
(map (drv: drv.__spliced.buildTarget or drv) (checkDependencyList "depsBuildTarget" depsBuildTarget))
]
[
(map (drv: drv.__spliced.hostHost or drv) (checkDependencyList "depsHostHost" depsHostHost))
(map (drv: drv.__spliced.hostTarget or drv) (checkDependencyList "buildInputs" buildInputs'))
(map (drv: drv.__spliced.hostTarget or drv) (checkDependencyList "depsHostTarget/buildInputs" depsHostTarget'))
]
[
(map (drv: drv.__spliced.targetTarget or drv) (checkDependencyList "depsTargetTarget" depsTargetTarget))
Expand All @@ -255,12 +260,12 @@ else let
propagatedDependencies = map (map lib.chooseDevOutputs) [
[
(map (drv: drv.__spliced.buildBuild or drv) (checkDependencyList "depsBuildBuildPropagated" depsBuildBuildPropagated))
(map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "propagatedNativeBuildInputs" propagatedNativeBuildInputs))
(map (drv: drv.__spliced.buildHost or drv) (checkDependencyList "depsBuildHostPropagated/propagatedNativeBuildInputs" (depsBuildHostPropagated ++ propagatedNativeBuildInputs)))
(map (drv: drv.__spliced.buildTarget or drv) (checkDependencyList "depsBuildTargetPropagated" depsBuildTargetPropagated))
]
[
(map (drv: drv.__spliced.hostHost or drv) (checkDependencyList "depsHostHostPropagated" depsHostHostPropagated))
(map (drv: drv.__spliced.hostTarget or drv) (checkDependencyList "propagatedBuildInputs" propagatedBuildInputs))
(map (drv: drv.__spliced.hostTarget or drv) (checkDependencyList "depsHostTargetPropagated/propagatedBuildInputs" (depsHostTargetPropagated ++ propagatedBuildInputs)))
]
[
(map (drv: drv.__spliced.targetTarget or drv) (checkDependencyList "depsTargetTargetPropagated" depsTargetTargetPropagated))
Expand All @@ -269,8 +274,8 @@ else let

computedSandboxProfile =
lib.concatMap (input: input.__propagatedSandboxProfile or [])
(stdenv.extraNativeBuildInputs
++ stdenv.extraBuildInputs
(stdenv.extraDepsBuildHost
++ stdenv.extraDepsHostTarget
++ lib.concatLists dependencies);

computedPropagatedSandboxProfile =
Expand All @@ -279,8 +284,8 @@ else let

computedImpureHostDeps =
lib.unique (lib.concatMap (input: input.__propagatedImpureHostDeps or [])
(stdenv.extraNativeBuildInputs
++ stdenv.extraBuildInputs
(stdenv.extraDepsBuildHost
++ stdenv.extraDepsHostTarget
++ lib.concatLists dependencies));

computedPropagatedImpureHostDeps =
Expand Down Expand Up @@ -344,16 +349,20 @@ else let

depsBuildBuild = lib.elemAt (lib.elemAt dependencies 0) 0;
nativeBuildInputs = lib.elemAt (lib.elemAt dependencies 0) 1;
depsBuildHost = lib.elemAt (lib.elemAt dependencies 0) 1;
depsBuildTarget = lib.elemAt (lib.elemAt dependencies 0) 2;
depsHostHost = lib.elemAt (lib.elemAt dependencies 1) 0;
buildInputs = lib.elemAt (lib.elemAt dependencies 1) 1;
depsHostTarget = lib.elemAt (lib.elemAt dependencies 1) 1;
depsTargetTarget = lib.elemAt (lib.elemAt dependencies 2) 0;

depsBuildBuildPropagated = lib.elemAt (lib.elemAt propagatedDependencies 0) 0;
propagatedNativeBuildInputs = lib.elemAt (lib.elemAt propagatedDependencies 0) 1;
depsBuildHostPropagated = lib.elemAt (lib.elemAt propagatedDependencies 0) 1;
depsBuildTargetPropagated = lib.elemAt (lib.elemAt propagatedDependencies 0) 2;
depsHostHostPropagated = lib.elemAt (lib.elemAt propagatedDependencies 1) 0;
propagatedBuildInputs = lib.elemAt (lib.elemAt propagatedDependencies 1) 1;
depsHostTargetPropagated = lib.elemAt (lib.elemAt propagatedDependencies 1) 1;
depsTargetTargetPropagated = lib.elemAt (lib.elemAt propagatedDependencies 2) 0;

# This parameter is sometimes a string, sometimes null, and sometimes a list, yuck
Expand Down
16 changes: 12 additions & 4 deletions pkgs/stdenv/generic/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -611,10 +611,12 @@ findInputs() {

# Make sure all are at least defined as empty
: "${depsBuildBuild=}" "${depsBuildBuildPropagated=}"
: "${nativeBuildInputs=}" "${propagatedNativeBuildInputs=}" "${defaultNativeBuildInputs=}"
: "${nativeBuildInputs=}" "${propagatedNativeBuildInputs=}"
: "${depsBuildHost=}" "${depsBuildHostPropagated=}" "${defaultDepsBuildHost=}"
: "${depsBuildTarget=}" "${depsBuildTargetPropagated=}"
: "${depsHostHost=}" "${depsHostHostPropagated=}"
: "${buildInputs=}" "${propagatedBuildInputs=}" "${defaultBuildInputs=}"
: "${buildInputs=}" "${propagatedBuildInputs=}"
: "${depsHostTargetPropagated=}" "${depsHostTarget=}" "${defaultDepsHostTarget=}"
: "${depsTargetTarget=}" "${depsTargetTargetPropagated=}"

for pkg in ${depsBuildBuild[@]} ${depsBuildBuildPropagated[@]}; do
Expand All @@ -623,6 +625,9 @@ done
for pkg in ${nativeBuildInputs[@]} ${propagatedNativeBuildInputs[@]}; do
findInputs "$pkg" -1 0
done
for pkg in ${depsBuildHost[@]} ${depsBuildHostPropagated[@]}; do
findInputs "$pkg" -1 0
done
for pkg in ${depsBuildTarget[@]} ${depsBuildTargetPropagated[@]}; do
findInputs "$pkg" -1 1
done
Expand All @@ -632,14 +637,17 @@ done
for pkg in ${buildInputs[@]} ${propagatedBuildInputs[@]} ; do
findInputs "$pkg" 0 1
done
for pkg in ${depsHostTarget[@]} ${depsHostTargetPropagated[@]} ; do
findInputs "$pkg" 0 1
done
for pkg in ${depsTargetTarget[@]} ${depsTargetTargetPropagated[@]}; do
findInputs "$pkg" 1 1
done
# Default inputs must be processed last
for pkg in ${defaultNativeBuildInputs[@]}; do
for pkg in ${defaultDepsBuildHost[@]}; do
findInputs "$pkg" -1 0
done
for pkg in ${defaultBuildInputs[@]}; do
for pkg in ${defaultDepsHostTarget[@]}; do
findInputs "$pkg" 0 1
done

Expand Down
Loading