wrapCC, wrapBintools: use runtimeShell instead of stdenv shell

We don't need to artificially make sure that we can execute the wrapper
scripts on the build platform by using stdenv's shell (which comes from
buildPackages) since our cross infrastructure will get us the wrapper
from buildPackages. The upside of this change is that cross-compiled
wrappers (e.g. pkgsCross.aarch64-multiplatform.gcc) will actually work
when executed!

For bootstrapping this is also not a problem, since we have a long
build->build platform chain so runtimeShell is just as good as
stdenvNoCC.shell. We do fall back to old ways, though, by explicitly
using the bootstrap-tools shell in stage2, so the adjacent bash is only
used from stage4 onwards. This is unnecessary in principle (I'll try
removing this hack in the future), but ensures this change causes zero
rebuilds.
This commit is contained in:
sternenseemann 2024-04-12 00:14:16 +02:00
parent 1486e76262
commit b2a568906a
4 changed files with 25 additions and 13 deletions

View File

@ -8,7 +8,8 @@
{ name ? "" { name ? ""
, lib , lib
, stdenvNoCC , stdenvNoCC
, bintools ? null, libc ? null, coreutils ? null, shell ? stdenvNoCC.shell, gnugrep ? null , runtimeShell
, bintools ? null, libc ? null, coreutils ? null, gnugrep ? null
, netbsd ? null, netbsdCross ? null , netbsd ? null, netbsdCross ? null
, sharedLibraryLoader ? , sharedLibraryLoader ?
if libc == null then if libc == null then
@ -419,7 +420,8 @@ stdenvNoCC.mkDerivation {
env = { env = {
# for substitution in utils.bash # for substitution in utils.bash
expandResponseParams = "${expand-response-params}/bin/expand-response-params"; expandResponseParams = "${expand-response-params}/bin/expand-response-params";
shell = getBin shell + shell.shellPath or ""; # TODO(@sternenseemann): rename env var via stdenv rebuild
shell = (getBin runtimeShell + runtimeShell.shellPath or "");
gnugrep_bin = optionalString (!nativeTools) gnugrep; gnugrep_bin = optionalString (!nativeTools) gnugrep;
wrapperName = "BINTOOLS_WRAPPER"; wrapperName = "BINTOOLS_WRAPPER";
inherit dynamicLinker targetPrefix suffixSalt coreutils_bin; inherit dynamicLinker targetPrefix suffixSalt coreutils_bin;

View File

@ -8,7 +8,8 @@
{ name ? "" { name ? ""
, lib , lib
, stdenvNoCC , stdenvNoCC
, cc ? null, libc ? null, bintools, coreutils ? null, shell ? stdenvNoCC.shell , runtimeShell
, cc ? null, libc ? null, bintools, coreutils ? null
, zlib ? null , zlib ? null
, nativeTools, noLibc ? false, nativeLibc, nativePrefix ? "" , nativeTools, noLibc ? false, nativeLibc, nativePrefix ? ""
, propagateDoc ? cc != null && cc ? man , propagateDoc ? cc != null && cc ? man
@ -739,7 +740,8 @@ stdenvNoCC.mkDerivation {
# for substitution in utils.bash # for substitution in utils.bash
expandResponseParams = "${expand-response-params}/bin/expand-response-params"; expandResponseParams = "${expand-response-params}/bin/expand-response-params";
shell = getBin shell + shell.shellPath or ""; # TODO(@sternenseemann): rename env var via stdenv rebuild
shell = getBin runtimeShell + runtimeShell.shellPath or "";
gnugrep_bin = optionalString (!nativeTools) gnugrep; gnugrep_bin = optionalString (!nativeTools) gnugrep;
# stdenv.cc.cc should not be null and we have nothing better for now. # stdenv.cc.cc should not be null and we have nothing better for now.
# if the native impure bootstrap is gotten rid of this can become `inherit cc;` again. # if the native impure bootstrap is gotten rid of this can become `inherit cc;` again.

View File

@ -117,6 +117,7 @@ let
inherit (prevStage) coreutils gnugrep; inherit (prevStage) coreutils gnugrep;
stdenvNoCC = prevStage.ccWrapperStdenv; stdenvNoCC = prevStage.ccWrapperStdenv;
runtimeShell = prevStage.ccWrapperStdenv.shell;
}; };
bash = prevStage.bash or bootstrapTools; bash = prevStage.bash or bootstrapTools;
@ -258,6 +259,7 @@ in
inherit lib; inherit lib;
inherit (self) stdenvNoCC coreutils gnugrep; inherit (self) stdenvNoCC coreutils gnugrep;
runtimeShell = self.stdenvNoCC.shell;
bintools = selfDarwin.binutils-unwrapped; bintools = selfDarwin.binutils-unwrapped;
@ -457,6 +459,8 @@ in
bintools = selfDarwin.binutils-unwrapped; bintools = selfDarwin.binutils-unwrapped;
libc = selfDarwin.Libsystem; libc = selfDarwin.Libsystem;
# TODO(@sternenseemann): can this be removed?
runtimeShell = "${bootstrapTools}/bin/bash";
}; };
binutils-unwrapped = superDarwin.binutils-unwrapped.override { binutils-unwrapped = superDarwin.binutils-unwrapped.override {
@ -1044,8 +1048,6 @@ in
}; };
binutils = superDarwin.binutils.override { binutils = superDarwin.binutils.override {
shell = self.bash + "/bin/bash";
buildPackages = { buildPackages = {
inherit (prevStage) stdenv; inherit (prevStage) stdenv;
}; };
@ -1124,9 +1126,7 @@ in
inherit (self.llvmPackages) libcxx; inherit (self.llvmPackages) libcxx;
inherit lib; inherit lib;
inherit (self) stdenvNoCC coreutils gnugrep; inherit (self) stdenvNoCC coreutils gnugrep runtimeShell;
shell = self.bash + "/bin/bash";
}; };
}); });
libraries = super.llvmPackages.libraries.extend (_: _:{ libraries = super.llvmPackages.libraries.extend (_: _:{

View File

@ -196,6 +196,7 @@ let
inherit (prevStage) coreutils gnugrep; inherit (prevStage) coreutils gnugrep;
stdenvNoCC = prevStage.ccWrapperStdenv; stdenvNoCC = prevStage.ccWrapperStdenv;
fortify-headers = prevStage.fortify-headers; fortify-headers = prevStage.fortify-headers;
runtimeShell = prevStage.ccWrapperStdenv.shell;
}).overrideAttrs(a: lib.optionalAttrs (prevStage.gcc-unwrapped.passthru.isXgcc or false) { }).overrideAttrs(a: lib.optionalAttrs (prevStage.gcc-unwrapped.passthru.isXgcc or false) {
# This affects only `xgcc` (the compiler which compiles the final compiler). # This affects only `xgcc` (the compiler which compiles the final compiler).
postFixup = (a.postFixup or "") + '' postFixup = (a.postFixup or "") + ''
@ -265,6 +266,7 @@ in
inherit lib; inherit lib;
inherit (self) stdenvNoCC coreutils gnugrep; inherit (self) stdenvNoCC coreutils gnugrep;
bintools = bootstrapTools; bintools = bootstrapTools;
runtimeShell = "${bootstrapTools}/bin/bash";
}; };
coreutils = bootstrapTools; coreutils = bootstrapTools;
gnugrep = bootstrapTools; gnugrep = bootstrapTools;
@ -332,6 +334,14 @@ in
inherit (prevStage) ccWrapperStdenv coreutils gnugrep gettext bison texinfo zlib gnum4 perl patchelf; inherit (prevStage) ccWrapperStdenv coreutils gnugrep gettext bison texinfo zlib gnum4 perl patchelf;
${localSystem.libc} = getLibc prevStage; ${localSystem.libc} = getLibc prevStage;
gmp = super.gmp.override { cxx = false; }; gmp = super.gmp.override { cxx = false; };
# This stage also rebuilds binutils which will of course be used only in the next stage.
# We inherit this until stage3, in stage4 it will be rebuilt using the adjacent bash/runtimeShell pkg.
# TODO(@sternenseemann): Can we already build the wrapper with the actual runtimeShell here?
# Historically, the wrapper didn't use runtimeShell, so the used shell had to be changed explicitly
# (or stdenvNoCC.shell would be used) which happened in stage4.
binutils = super.binutils.override {
runtimeShell = "${bootstrapTools}/bin/bash";
};
gcc-unwrapped = gcc-unwrapped =
(super.gcc-unwrapped.override (commonGccOverrides // { (super.gcc-unwrapped.override (commonGccOverrides // {
# The most logical name for this package would be something like # The most logical name for this package would be something like
@ -544,9 +554,8 @@ in
# other purposes (binutils and top-level pkgs) too. # other purposes (binutils and top-level pkgs) too.
inherit (prevStage) gettext gnum4 bison perl texinfo zlib linuxHeaders libidn2 libunistring; inherit (prevStage) gettext gnum4 bison perl texinfo zlib linuxHeaders libidn2 libunistring;
${localSystem.libc} = getLibc prevStage; ${localSystem.libc} = getLibc prevStage;
# Since this is the first fresh build of binutils since stage2, our own runtimeShell will be used.
binutils = super.binutils.override { binutils = super.binutils.override {
# Don't use stdenv's shell but our own
shell = self.bash + "/bin/bash";
# Build expand-response-params with last stage like below # Build expand-response-params with last stage like below
buildPackages = { buildPackages = {
inherit (prevStage) stdenv; inherit (prevStage) stdenv;
@ -568,8 +577,7 @@ in
bintools = self.binutils; bintools = self.binutils;
libc = getLibc self; libc = getLibc self;
inherit lib; inherit lib;
inherit (self) stdenvNoCC coreutils gnugrep; inherit (self) stdenvNoCC coreutils gnugrep runtimeShell;
shell = self.bash + "/bin/bash";
fortify-headers = self.fortify-headers; fortify-headers = self.fortify-headers;
}; };
}; };