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 ? ""
, lib
, 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
, sharedLibraryLoader ?
if libc == null then
@ -419,7 +420,8 @@ stdenvNoCC.mkDerivation {
env = {
# for substitution in utils.bash
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;
wrapperName = "BINTOOLS_WRAPPER";
inherit dynamicLinker targetPrefix suffixSalt coreutils_bin;

View File

@ -8,7 +8,8 @@
{ name ? ""
, lib
, stdenvNoCC
, cc ? null, libc ? null, bintools, coreutils ? null, shell ? stdenvNoCC.shell
, runtimeShell
, cc ? null, libc ? null, bintools, coreutils ? null
, zlib ? null
, nativeTools, noLibc ? false, nativeLibc, nativePrefix ? ""
, propagateDoc ? cc != null && cc ? man
@ -739,7 +740,8 @@ stdenvNoCC.mkDerivation {
# for substitution in utils.bash
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;
# 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.

View File

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

View File

@ -196,6 +196,7 @@ let
inherit (prevStage) coreutils gnugrep;
stdenvNoCC = prevStage.ccWrapperStdenv;
fortify-headers = prevStage.fortify-headers;
runtimeShell = prevStage.ccWrapperStdenv.shell;
}).overrideAttrs(a: lib.optionalAttrs (prevStage.gcc-unwrapped.passthru.isXgcc or false) {
# This affects only `xgcc` (the compiler which compiles the final compiler).
postFixup = (a.postFixup or "") + ''
@ -265,6 +266,7 @@ in
inherit lib;
inherit (self) stdenvNoCC coreutils gnugrep;
bintools = bootstrapTools;
runtimeShell = "${bootstrapTools}/bin/bash";
};
coreutils = bootstrapTools;
gnugrep = bootstrapTools;
@ -332,6 +334,14 @@ in
inherit (prevStage) ccWrapperStdenv coreutils gnugrep gettext bison texinfo zlib gnum4 perl patchelf;
${localSystem.libc} = getLibc prevStage;
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 =
(super.gcc-unwrapped.override (commonGccOverrides // {
# The most logical name for this package would be something like
@ -544,9 +554,8 @@ in
# other purposes (binutils and top-level pkgs) too.
inherit (prevStage) gettext gnum4 bison perl texinfo zlib linuxHeaders libidn2 libunistring;
${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 {
# Don't use stdenv's shell but our own
shell = self.bash + "/bin/bash";
# Build expand-response-params with last stage like below
buildPackages = {
inherit (prevStage) stdenv;
@ -568,8 +577,7 @@ in
bintools = self.binutils;
libc = getLibc self;
inherit lib;
inherit (self) stdenvNoCC coreutils gnugrep;
shell = self.bash + "/bin/bash";
inherit (self) stdenvNoCC coreutils gnugrep runtimeShell;
fortify-headers = self.fortify-headers;
};
};