Merge pull request #304033 from sternenseemann/wrapper-cleanups

wrapCC, wrapBintools, stdenv: make Nix code a bit more consistent
This commit is contained in:
John Ericson 2024-04-18 10:57:18 -04:00 committed by GitHub
commit 0820a71359
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 26 additions and 29 deletions

View File

@ -83,8 +83,7 @@ let
replaceStrings replaceStrings
; ;
stdenv = stdenvNoCC; inherit (stdenvNoCC) hostPlatform targetPlatform;
inherit (stdenv) hostPlatform targetPlatform;
# Prefix for binaries. Customarily ends with a dash separator. # Prefix for binaries. Customarily ends with a dash separator.
# #
@ -138,7 +137,7 @@ let
in in
stdenv.mkDerivation { stdenvNoCC.mkDerivation {
pname = targetPrefix pname = targetPrefix
+ (if name != "" then name else "${bintoolsName}-wrapper"); + (if name != "" then name else "${bintoolsName}-wrapper");
version = optionalString (bintools != null) bintoolsVersion; version = optionalString (bintools != null) bintoolsVersion;
@ -346,7 +345,7 @@ stdenv.mkDerivation {
done done
'' ''
+ optionalString stdenv.targetPlatform.isDarwin '' + optionalString targetPlatform.isDarwin ''
echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/libc-ldflags echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/libc-ldflags
'' ''
@ -363,7 +362,7 @@ stdenv.mkDerivation {
### ###
### Remove certain timestamps from final binaries ### Remove certain timestamps from final binaries
### ###
+ optionalString (stdenv.targetPlatform.isDarwin && !(bintools.isGNU or false)) '' + optionalString (targetPlatform.isDarwin && !(bintools.isGNU or false)) ''
echo "export ZERO_AR_DATE=1" >> $out/nix-support/setup-hook echo "export ZERO_AR_DATE=1" >> $out/nix-support/setup-hook
'' ''
@ -380,9 +379,9 @@ stdenv.mkDerivation {
### ###
### Ensure consistent LC_VERSION_MIN_MACOSX ### Ensure consistent LC_VERSION_MIN_MACOSX
### ###
+ optionalString stdenv.targetPlatform.isDarwin ( + optionalString targetPlatform.isDarwin (
let let
inherit (stdenv.targetPlatform) inherit (targetPlatform)
darwinPlatform darwinSdkVersion darwinPlatform darwinSdkVersion
darwinMinVersion darwinMinVersionVariable; darwinMinVersion darwinMinVersionVariable;
in '' in ''

View File

@ -82,9 +82,7 @@ let
versionAtLeast versionAtLeast
; ;
inherit (stdenv) hostPlatform targetPlatform; inherit (stdenvNoCC) hostPlatform targetPlatform;
stdenv = stdenvNoCC;
includeFortifyHeaders' = if includeFortifyHeaders != null includeFortifyHeaders' = if includeFortifyHeaders != null
then includeFortifyHeaders then includeFortifyHeaders
@ -119,10 +117,10 @@ let
useGccForLibs = useCcForLibs useGccForLibs = useCcForLibs
&& libcxx == null && libcxx == null
&& !stdenv.targetPlatform.isDarwin && !targetPlatform.isDarwin
&& !(stdenv.targetPlatform.useLLVM or false) && !(targetPlatform.useLLVM or false)
&& !(stdenv.targetPlatform.useAndroidPrebuilt or false) && !(targetPlatform.useAndroidPrebuilt or false)
&& !(stdenv.targetPlatform.isiOS or false) && !(targetPlatform.isiOS or false)
&& gccForLibs != null; && gccForLibs != null;
gccForLibs_solib = getLib gccForLibs gccForLibs_solib = getLib gccForLibs
+ optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}"; + optionalString (targetPlatform != hostPlatform) "/${targetPlatform.config}";
@ -249,17 +247,17 @@ let
then cc.hardeningUnsupportedFlagsByTargetPlatform targetPlatform then cc.hardeningUnsupportedFlagsByTargetPlatform targetPlatform
else (cc.hardeningUnsupportedFlags or []); else (cc.hardeningUnsupportedFlags or []);
darwinPlatformForCC = optionalString stdenv.targetPlatform.isDarwin ( darwinPlatformForCC = optionalString targetPlatform.isDarwin (
if (targetPlatform.darwinPlatform == "macos" && isGNU) then "macosx" if (targetPlatform.darwinPlatform == "macos" && isGNU) then "macosx"
else targetPlatform.darwinPlatform else targetPlatform.darwinPlatform
); );
darwinMinVersion = optionalString stdenv.targetPlatform.isDarwin ( darwinMinVersion = optionalString targetPlatform.isDarwin (
stdenv.targetPlatform.darwinMinVersion targetPlatform.darwinMinVersion
); );
darwinMinVersionVariable = optionalString stdenv.targetPlatform.isDarwin darwinMinVersionVariable = optionalString targetPlatform.isDarwin
stdenv.targetPlatform.darwinMinVersionVariable; targetPlatform.darwinMinVersionVariable;
in in
assert includeFortifyHeaders' -> fortify-headers != null; assert includeFortifyHeaders' -> fortify-headers != null;
@ -272,7 +270,7 @@ assert nativeTools == bintools.nativeTools;
assert nativeLibc == bintools.nativeLibc; assert nativeLibc == bintools.nativeLibc;
assert nativePrefix == bintools.nativePrefix; assert nativePrefix == bintools.nativePrefix;
stdenv.mkDerivation { stdenvNoCC.mkDerivation {
pname = targetPrefix pname = targetPrefix
+ (if name != "" then name else "${ccName}-wrapper"); + (if name != "" then name else "${ccName}-wrapper");
version = optionalString (cc != null) ccVersion; version = optionalString (cc != null) ccVersion;
@ -426,7 +424,7 @@ stdenv.mkDerivation {
../setup-hooks/role.bash ../setup-hooks/role.bash
] ++ optional (cc.langC or true) ./setup-hook.sh ] ++ optional (cc.langC or true) ./setup-hook.sh
++ optional (cc.langFortran or false) ./fortran-hook.sh ++ optional (cc.langFortran or false) ./fortran-hook.sh
++ optional (targetPlatform.isWindows) (stdenv.mkDerivation { ++ optional (targetPlatform.isWindows) (stdenvNoCC.mkDerivation {
name = "win-dll-hook.sh"; name = "win-dll-hook.sh";
dontUnpack = true; dontUnpack = true;
installPhase = '' installPhase = ''
@ -479,8 +477,8 @@ stdenv.mkDerivation {
# break `useLLVM` into.) # break `useLLVM` into.)
+ optionalString (isClang + optionalString (isClang
&& targetPlatform.isLinux && targetPlatform.isLinux
&& !(stdenv.targetPlatform.useAndroidPrebuilt or false) && !(targetPlatform.useAndroidPrebuilt or false)
&& !(stdenv.targetPlatform.useLLVM or false) && !(targetPlatform.useLLVM or false)
&& gccForLibs != null) ('' && gccForLibs != null) (''
echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags echo "--gcc-toolchain=${gccForLibs}" >> $out/nix-support/cc-cflags
@ -689,7 +687,7 @@ stdenv.mkDerivation {
done done
'' ''
+ optionalString stdenv.targetPlatform.isDarwin '' + optionalString targetPlatform.isDarwin ''
echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/cc-cflags echo "-arch ${targetPlatform.darwinArch}" >> $out/nix-support/cc-cflags
'' ''

View File

@ -328,12 +328,12 @@ in
assert isBuiltByBootstrapFilesCompiler prevStage.patchelf; assert isBuiltByBootstrapFilesCompiler prevStage.patchelf;
stageFun prevStage { stageFun prevStage {
name = "bootstrap-stage-xgcc"; name = "bootstrap-stage-xgcc";
overrides = final: prev: { overrides = self: super: {
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 = prev.gmp.override { cxx = false; }; gmp = super.gmp.override { cxx = false; };
gcc-unwrapped = gcc-unwrapped =
(prev.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
# "gcc-stage1". Unfortunately "stage" is already reserved for the # "gcc-stage1". Unfortunately "stage" is already reserved for the
# layers of stdenv, so using "stage" in the name of this package # layers of stdenv, so using "stage" in the name of this package
@ -376,7 +376,7 @@ in
# #
configureFlags = (a.configureFlags or []) ++ [ configureFlags = (a.configureFlags or []) ++ [
"--with-native-system-header-dir=/include" "--with-native-system-header-dir=/include"
"--with-build-sysroot=${lib.getDev final.stdenv.cc.libc}" "--with-build-sysroot=${lib.getDev self.stdenv.cc.libc}"
]; ];
# This is a separate phase because gcc assembles its phase scripts # This is a separate phase because gcc assembles its phase scripts

View File

@ -152,7 +152,7 @@ in
inherit config overlays; inherit config overlays;
stdenv = makeStdenv { stdenv = makeStdenv {
inherit (prevStage) cc fetchurl; inherit (prevStage) cc fetchurl;
overrides = prev: final: { inherit (prevStage) fetchurl; }; overrides = self: super: { inherit (prevStage) fetchurl; };
} // { } // {
inherit (prevStage) fetchurl; inherit (prevStage) fetchurl;
}; };