Avoid top-level with ...;
in pkgs/development/compilers/gcc/default.nix
I didn't fix the whitespace and indenting, but I really wanted to. The global `with` was masking that `fetchFromGitHub` wasn't injected!
This commit is contained in:
parent
8616de2279
commit
64f4bdb7e1
|
@ -1,4 +1,4 @@
|
||||||
{ lib, stdenv, targetPackages, fetchurl, fetchpatch, noSysDirs
|
{ lib, stdenv, targetPackages, fetchurl, fetchpatch, fetchFromGitHub, noSysDirs
|
||||||
, langC ? true, langCC ? true, langFortran ? false
|
, langC ? true, langCC ? true, langFortran ? false
|
||||||
, langAda ? false
|
, langAda ? false
|
||||||
, langObjC ? stdenv.targetPlatform.isDarwin
|
, langObjC ? stdenv.targetPlatform.isDarwin
|
||||||
|
@ -48,19 +48,37 @@
|
||||||
}:
|
}:
|
||||||
|
|
||||||
let
|
let
|
||||||
versions = import ./versions.nix;
|
inherit (lib)
|
||||||
version = versions.fromMajorMinor majorMinorVersion;
|
callPackageWith
|
||||||
|
filter
|
||||||
|
getBin
|
||||||
|
maintainers
|
||||||
|
makeLibraryPath
|
||||||
|
makeSearchPathOutput
|
||||||
|
mapAttrs
|
||||||
|
optional
|
||||||
|
optionalAttrs
|
||||||
|
optionals
|
||||||
|
optionalString
|
||||||
|
pipe
|
||||||
|
platforms
|
||||||
|
versionAtLeast
|
||||||
|
versions
|
||||||
|
;
|
||||||
|
|
||||||
majorVersion = lib.versions.major version;
|
gccVersions = import ./versions.nix;
|
||||||
atLeast13 = lib.versionAtLeast version "13";
|
version = gccVersions.fromMajorMinor majorMinorVersion;
|
||||||
atLeast12 = lib.versionAtLeast version "12";
|
|
||||||
atLeast11 = lib.versionAtLeast version "11";
|
majorVersion = versions.major version;
|
||||||
atLeast10 = lib.versionAtLeast version "10";
|
atLeast13 = versionAtLeast version "13";
|
||||||
atLeast9 = lib.versionAtLeast version "9";
|
atLeast12 = versionAtLeast version "12";
|
||||||
atLeast8 = lib.versionAtLeast version "8";
|
atLeast11 = versionAtLeast version "11";
|
||||||
atLeast7 = lib.versionAtLeast version "7";
|
atLeast10 = versionAtLeast version "10";
|
||||||
atLeast6 = lib.versionAtLeast version "6";
|
atLeast9 = versionAtLeast version "9";
|
||||||
atLeast49 = lib.versionAtLeast version "4.9";
|
atLeast8 = versionAtLeast version "8";
|
||||||
|
atLeast7 = versionAtLeast version "7";
|
||||||
|
atLeast6 = versionAtLeast version "6";
|
||||||
|
atLeast49 = versionAtLeast version "4.9";
|
||||||
is13 = majorVersion == "13";
|
is13 = majorVersion == "13";
|
||||||
is12 = majorVersion == "12";
|
is12 = majorVersion == "12";
|
||||||
is11 = majorVersion == "11";
|
is11 = majorVersion == "11";
|
||||||
|
@ -69,37 +87,9 @@ let
|
||||||
is8 = majorVersion == "8";
|
is8 = majorVersion == "8";
|
||||||
is7 = majorVersion == "7";
|
is7 = majorVersion == "7";
|
||||||
is6 = majorVersion == "6";
|
is6 = majorVersion == "6";
|
||||||
is49 = majorVersion == "4" && lib.versions.minor version == "9";
|
is49 = majorVersion == "4" && versions.minor version == "9";
|
||||||
is48 = majorVersion == "4" && lib.versions.minor version == "8";
|
is48 = majorVersion == "4" && versions.minor version == "8";
|
||||||
in
|
|
||||||
|
|
||||||
# We enable the isl cloog backend.
|
|
||||||
assert !atLeast6 -> (cloog != null -> isl != null);
|
|
||||||
|
|
||||||
assert langJava -> !atLeast7 && zip != null && unzip != null && zlib != null && boehmgc != null && perl != null; # for `--enable-java-home'
|
|
||||||
|
|
||||||
# Make sure we get GNU sed.
|
|
||||||
assert stdenv.buildPlatform.isDarwin -> gnused != null;
|
|
||||||
|
|
||||||
# The go frontend is written in c++
|
|
||||||
assert langGo -> langCC;
|
|
||||||
assert (atLeast6 && !is7 && !is8) -> (langAda -> gnat-bootstrap != null);
|
|
||||||
|
|
||||||
# TODO: fixup D bootstapping, probably by using gdc11 (and maybe other changes).
|
|
||||||
# error: GDC is required to build d
|
|
||||||
assert atLeast12 -> !langD;
|
|
||||||
|
|
||||||
# threadsCross is just for MinGW
|
|
||||||
assert threadsCross != {} -> stdenv.targetPlatform.isWindows;
|
|
||||||
|
|
||||||
# profiledCompiler builds inject non-determinism in one of the compilation stages.
|
|
||||||
# If turned on, we can't provide reproducible builds anymore
|
|
||||||
assert reproducibleBuild -> profiledCompiler == false;
|
|
||||||
|
|
||||||
with lib;
|
|
||||||
with builtins;
|
|
||||||
|
|
||||||
let inherit version;
|
|
||||||
disableBootstrap = atLeast11 && !stdenv.hostPlatform.isDarwin && (atLeast12 -> !profiledCompiler);
|
disableBootstrap = atLeast11 && !stdenv.hostPlatform.isDarwin && (atLeast12 -> !profiledCompiler);
|
||||||
|
|
||||||
inherit (stdenv) buildPlatform hostPlatform targetPlatform;
|
inherit (stdenv) buildPlatform hostPlatform targetPlatform;
|
||||||
|
@ -117,7 +107,7 @@ let inherit version;
|
||||||
libX11 libXt libSM libICE libXtst libXrender libXrandr libXi
|
libX11 libXt libSM libICE libXtst libXrender libXrandr libXi
|
||||||
xorgproto
|
xorgproto
|
||||||
];
|
];
|
||||||
callFile = lib.callPackageWith ({
|
callFile = callPackageWith ({
|
||||||
# lets
|
# lets
|
||||||
inherit
|
inherit
|
||||||
majorVersion
|
majorVersion
|
||||||
|
@ -182,7 +172,7 @@ let inherit version;
|
||||||
zip
|
zip
|
||||||
zlib
|
zlib
|
||||||
;
|
;
|
||||||
} // lib.optionalAttrs (!atLeast7) {
|
} // optionalAttrs (!atLeast7) {
|
||||||
inherit
|
inherit
|
||||||
boehmgc
|
boehmgc
|
||||||
flex
|
flex
|
||||||
|
@ -225,10 +215,33 @@ let inherit version;
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
|
# We enable the isl cloog backend.
|
||||||
|
assert !atLeast6 -> (cloog != null -> isl != null);
|
||||||
|
|
||||||
|
assert langJava -> !atLeast7 && zip != null && unzip != null && zlib != null && boehmgc != null && perl != null; # for `--enable-java-home'
|
||||||
|
|
||||||
|
# Make sure we get GNU sed.
|
||||||
|
assert stdenv.buildPlatform.isDarwin -> gnused != null;
|
||||||
|
|
||||||
|
# The go frontend is written in c++
|
||||||
|
assert langGo -> langCC;
|
||||||
|
assert (atLeast6 && !is7 && !is8) -> (langAda -> gnat-bootstrap != null);
|
||||||
|
|
||||||
|
# TODO: fixup D bootstapping, probably by using gdc11 (and maybe other changes).
|
||||||
|
# error: GDC is required to build d
|
||||||
|
assert atLeast12 -> !langD;
|
||||||
|
|
||||||
|
# threadsCross is just for MinGW
|
||||||
|
assert threadsCross != {} -> stdenv.targetPlatform.isWindows;
|
||||||
|
|
||||||
|
# profiledCompiler builds inject non-determinism in one of the compilation stages.
|
||||||
|
# If turned on, we can't provide reproducible builds anymore
|
||||||
|
assert reproducibleBuild -> profiledCompiler == false;
|
||||||
|
|
||||||
# We need all these X libraries when building AWT with GTK.
|
# We need all these X libraries when building AWT with GTK.
|
||||||
assert !atLeast7 -> (x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []);
|
assert !atLeast7 -> (x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []);
|
||||||
|
|
||||||
lib.pipe ((callFile ./common/builder.nix {}) ({
|
pipe ((callFile ./common/builder.nix {}) ({
|
||||||
pname = "${crossNameAddon}${name}";
|
pname = "${crossNameAddon}${name}";
|
||||||
inherit version;
|
inherit version;
|
||||||
|
|
||||||
|
@ -249,14 +262,14 @@ lib.pipe ((callFile ./common/builder.nix {}) ({
|
||||||
then "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz"
|
then "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz"
|
||||||
else "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2";
|
else "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2";
|
||||||
${if is10 || is11 || is13 then "hash" else "sha256"} =
|
${if is10 || is11 || is13 then "hash" else "sha256"} =
|
||||||
versions.srcHashForVersion version;
|
gccVersions.srcHashForVersion version;
|
||||||
};
|
};
|
||||||
|
|
||||||
inherit patches;
|
inherit patches;
|
||||||
|
|
||||||
outputs =
|
outputs =
|
||||||
if atLeast7
|
if atLeast7
|
||||||
then [ "out" "man" "info" ] ++ lib.optional (!langJit) "lib"
|
then [ "out" "man" "info" ] ++ optional (!langJit) "lib"
|
||||||
else if atLeast49 && (langJava || langGo || (if atLeast6 then langJit else targetPlatform.isDarwin)) then ["out" "man" "info"]
|
else if atLeast49 && (langJava || langGo || (if atLeast6 then langJit else targetPlatform.isDarwin)) then ["out" "man" "info"]
|
||||||
else [ "out" "lib" "man" "info" ];
|
else [ "out" "lib" "man" "info" ];
|
||||||
|
|
||||||
|
@ -265,9 +278,9 @@ lib.pipe ((callFile ./common/builder.nix {}) ({
|
||||||
libc_dev = stdenv.cc.libc_dev;
|
libc_dev = stdenv.cc.libc_dev;
|
||||||
|
|
||||||
hardeningDisable = [ "format" "pie" ]
|
hardeningDisable = [ "format" "pie" ]
|
||||||
++ lib.optionals (is11 && langAda) [ "fortify3" ];
|
++ optionals (is11 && langAda) [ "fortify3" ];
|
||||||
|
|
||||||
postPatch = lib.optionalString atLeast7 ''
|
postPatch = optionalString atLeast7 ''
|
||||||
configureScripts=$(find . -name configure)
|
configureScripts=$(find . -name configure)
|
||||||
for configureScript in $configureScripts; do
|
for configureScript in $configureScripts; do
|
||||||
patchShebangs $configureScript
|
patchShebangs $configureScript
|
||||||
|
@ -275,8 +288,8 @@ lib.pipe ((callFile ./common/builder.nix {}) ({
|
||||||
''
|
''
|
||||||
# This should kill all the stdinc frameworks that gcc and friends like to
|
# This should kill all the stdinc frameworks that gcc and friends like to
|
||||||
# insert into default search paths.
|
# insert into default search paths.
|
||||||
+ lib.optionalString (atLeast6 && hostPlatform.isDarwin) ''
|
+ optionalString (atLeast6 && hostPlatform.isDarwin) ''
|
||||||
substituteInPlace gcc/config/darwin-c.c${lib.optionalString atLeast12 "c"} \
|
substituteInPlace gcc/config/darwin-c.c${optionalString atLeast12 "c"} \
|
||||||
--replace 'if (stdinc)' 'if (0)'
|
--replace 'if (stdinc)' 'if (0)'
|
||||||
|
|
||||||
substituteInPlace libgcc/config/t-slibgcc-darwin \
|
substituteInPlace libgcc/config/t-slibgcc-darwin \
|
||||||
|
@ -286,7 +299,7 @@ lib.pipe ((callFile ./common/builder.nix {}) ({
|
||||||
--replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname"
|
--replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname"
|
||||||
''
|
''
|
||||||
+ (
|
+ (
|
||||||
lib.optionalString (targetPlatform != hostPlatform || stdenv.cc.libc != null)
|
optionalString (targetPlatform != hostPlatform || stdenv.cc.libc != null)
|
||||||
# On NixOS, use the right path to the dynamic linker instead of
|
# On NixOS, use the right path to the dynamic linker instead of
|
||||||
# `/lib/ld*.so'.
|
# `/lib/ld*.so'.
|
||||||
(let
|
(let
|
||||||
|
@ -296,18 +309,18 @@ lib.pipe ((callFile ./common/builder.nix {}) ({
|
||||||
'' echo "fixing the {GLIBC,UCLIBC,MUSL}_DYNAMIC_LINKER macros..."
|
'' echo "fixing the {GLIBC,UCLIBC,MUSL}_DYNAMIC_LINKER macros..."
|
||||||
for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h
|
for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h
|
||||||
do
|
do
|
||||||
grep -q ${lib.optionalString (!atLeast6) "LIBC"}_DYNAMIC_LINKER "$header" || continue
|
grep -q ${optionalString (!atLeast6) "LIBC"}_DYNAMIC_LINKER "$header" || continue
|
||||||
echo " fixing $header..."
|
echo " fixing $header..."
|
||||||
sed -i "$header" \
|
sed -i "$header" \
|
||||||
-e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g' \
|
-e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g' \
|
||||||
-e 's|define[[:blank:]]*MUSL_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define MUSL_DYNAMIC_LINKER\1 "${libc.out}\2"|g'
|
-e 's|define[[:blank:]]*MUSL_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define MUSL_DYNAMIC_LINKER\1 "${libc.out}\2"|g'
|
||||||
done
|
done
|
||||||
'' + lib.optionalString (atLeast6 && targetPlatform.libc == "musl") ''
|
'' + optionalString (atLeast6 && targetPlatform.libc == "musl") ''
|
||||||
sed -i gcc/config/linux.h -e '1i#undef LOCAL_INCLUDE_DIR'
|
sed -i gcc/config/linux.h -e '1i#undef LOCAL_INCLUDE_DIR'
|
||||||
''
|
''
|
||||||
)
|
)
|
||||||
))
|
))
|
||||||
+ lib.optionalString (atLeast7 && targetPlatform.isAvr) (''
|
+ optionalString (atLeast7 && targetPlatform.isAvr) (''
|
||||||
makeFlagsArray+=(
|
makeFlagsArray+=(
|
||||||
'-s' # workaround for hitting hydra log limit
|
'-s' # workaround for hitting hydra log limit
|
||||||
'LIMITS_H_TEST=false'
|
'LIMITS_H_TEST=false'
|
||||||
|
@ -319,7 +332,7 @@ lib.pipe ((callFile ./common/builder.nix {}) ({
|
||||||
|
|
||||||
inherit (callFile ./common/dependencies.nix { }) depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget;
|
inherit (callFile ./common/dependencies.nix { }) depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget;
|
||||||
|
|
||||||
preConfigure = (callFile ./common/pre-configure.nix { }) + lib.optionalString atLeast10 ''
|
preConfigure = (callFile ./common/pre-configure.nix { }) + optionalString atLeast10 ''
|
||||||
ln -sf ${libxcrypt}/include/crypt.h libsanitizer/sanitizer_common/crypt.h
|
ln -sf ${libxcrypt}/include/crypt.h libsanitizer/sanitizer_common/crypt.h
|
||||||
'';
|
'';
|
||||||
|
|
||||||
|
@ -338,9 +351,9 @@ lib.pipe ((callFile ./common/builder.nix {}) ({
|
||||||
assert atLeast12 -> (profiledCompiler -> !disableBootstrap);
|
assert atLeast12 -> (profiledCompiler -> !disableBootstrap);
|
||||||
if atLeast11
|
if atLeast11
|
||||||
then let target =
|
then let target =
|
||||||
lib.optionalString (profiledCompiler) "profiled" +
|
optionalString (profiledCompiler) "profiled" +
|
||||||
lib.optionalString (targetPlatform == hostPlatform && hostPlatform == buildPlatform && !disableBootstrap) "bootstrap";
|
optionalString (targetPlatform == hostPlatform && hostPlatform == buildPlatform && !disableBootstrap) "bootstrap";
|
||||||
in lib.optional (target != "") target
|
in optional (target != "") target
|
||||||
else
|
else
|
||||||
optional
|
optional
|
||||||
(targetPlatform == hostPlatform && hostPlatform == buildPlatform)
|
(targetPlatform == hostPlatform && hostPlatform == buildPlatform)
|
||||||
|
@ -394,24 +407,24 @@ lib.pipe ((callFile ./common/builder.nix {}) ({
|
||||||
EXTRA_LDFLAGS_FOR_TARGET
|
EXTRA_LDFLAGS_FOR_TARGET
|
||||||
;
|
;
|
||||||
} // optionalAttrs is7 {
|
} // optionalAttrs is7 {
|
||||||
NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.cc.isClang && langFortran) "-Wno-unused-command-line-argument"
|
NIX_CFLAGS_COMPILE = optionalString (stdenv.cc.isClang && langFortran) "-Wno-unused-command-line-argument"
|
||||||
# Downgrade register storage class specifier errors to warnings when building a cross compiler from a clang stdenv.
|
# Downgrade register storage class specifier errors to warnings when building a cross compiler from a clang stdenv.
|
||||||
+ lib.optionalString (stdenv.cc.isClang && targetPlatform != hostPlatform) " -Wno-register";
|
+ optionalString (stdenv.cc.isClang && targetPlatform != hostPlatform) " -Wno-register";
|
||||||
} // optionalAttrs (!is7 && !atLeast12 && stdenv.cc.isClang && targetPlatform != hostPlatform) {
|
} // optionalAttrs (!is7 && !atLeast12 && stdenv.cc.isClang && targetPlatform != hostPlatform) {
|
||||||
NIX_CFLAGS_COMPILE = "-Wno-register";
|
NIX_CFLAGS_COMPILE = "-Wno-register";
|
||||||
} // optionalAttrs (!atLeast7) {
|
} // optionalAttrs (!atLeast7) {
|
||||||
inherit langJava;
|
inherit langJava;
|
||||||
} // optionalAttrs atLeast6 {
|
} // optionalAttrs atLeast6 {
|
||||||
NIX_LDFLAGS = lib.optionalString hostPlatform.isSunOS "-lm";
|
NIX_LDFLAGS = optionalString hostPlatform.isSunOS "-lm";
|
||||||
});
|
});
|
||||||
|
|
||||||
passthru = {
|
passthru = {
|
||||||
inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD langJava version;
|
inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD langJava version;
|
||||||
isGNU = true;
|
isGNU = true;
|
||||||
hardeningUnsupportedFlags = lib.optional is48 "stackprotector"
|
hardeningUnsupportedFlags = optional is48 "stackprotector"
|
||||||
++ lib.optional (!atLeast11) "zerocallusedregs"
|
++ optional (!atLeast11) "zerocallusedregs"
|
||||||
++ lib.optionals (!atLeast12) [ "fortify3" "trivialautovarinit" ]
|
++ optionals (!atLeast12) [ "fortify3" "trivialautovarinit" ]
|
||||||
++ lib.optionals (langFortran) [ "fortify" "format" ];
|
++ optionals (langFortran) [ "fortify" "format" ];
|
||||||
};
|
};
|
||||||
|
|
||||||
enableParallelBuilding = true;
|
enableParallelBuilding = true;
|
||||||
|
@ -426,19 +439,19 @@ lib.pipe ((callFile ./common/builder.nix {}) ({
|
||||||
platforms
|
platforms
|
||||||
maintainers
|
maintainers
|
||||||
;
|
;
|
||||||
} // lib.optionalAttrs (!atLeast11) {
|
} // optionalAttrs (!atLeast11) {
|
||||||
badPlatforms =
|
badPlatforms =
|
||||||
# avr-gcc8 is maintained for the `qmk` package
|
# avr-gcc8 is maintained for the `qmk` package
|
||||||
if (is8 && targetPlatform.isAvr) then []
|
if (is8 && targetPlatform.isAvr) then []
|
||||||
else if !(is48 || is49) then [ "aarch64-darwin" ]
|
else if !(is48 || is49) then [ "aarch64-darwin" ]
|
||||||
else lib.platforms.darwin;
|
else platforms.darwin;
|
||||||
} // lib.optionalAttrs is11 {
|
} // optionalAttrs is11 {
|
||||||
badPlatforms = if targetPlatform != hostPlatform then [ "aarch64-darwin" ] else [ ];
|
badPlatforms = if targetPlatform != hostPlatform then [ "aarch64-darwin" ] else [ ];
|
||||||
};
|
};
|
||||||
} // lib.optionalAttrs (!atLeast10 && stdenv.targetPlatform.isDarwin) {
|
} // optionalAttrs (!atLeast10 && stdenv.targetPlatform.isDarwin) {
|
||||||
# GCC <10 requires default cctools `strip` instead of `llvm-strip` used by Darwin bintools.
|
# GCC <10 requires default cctools `strip` instead of `llvm-strip` used by Darwin bintools.
|
||||||
preBuild = ''
|
preBuild = ''
|
||||||
makeFlagsArray+=('STRIP=${lib.getBin darwin.cctools-port}/bin/${stdenv.cc.targetPrefix}strip')
|
makeFlagsArray+=('STRIP=${getBin darwin.cctools-port}/bin/${stdenv.cc.targetPrefix}strip')
|
||||||
'';
|
'';
|
||||||
} // optionalAttrs (!atLeast8) {
|
} // optionalAttrs (!atLeast8) {
|
||||||
doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv
|
doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv
|
||||||
|
|
Loading…
Reference in New Issue
Block a user