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!

authored by philiptaron.tngl.sh and committed by Valentin Gagarin 64f4bdb7 8616de22

+85 -72
+85 -72
pkgs/development/compilers/gcc/default.nix
··· 1 - { lib, stdenv, targetPackages, fetchurl, fetchpatch, noSysDirs 2 , langC ? true, langCC ? true, langFortran ? false 3 , langAda ? false 4 , langObjC ? stdenv.targetPlatform.isDarwin ··· 48 }: 49 50 let 51 - versions = import ./versions.nix; 52 - version = versions.fromMajorMinor majorMinorVersion; 53 54 - majorVersion = lib.versions.major version; 55 - atLeast13 = lib.versionAtLeast version "13"; 56 - atLeast12 = lib.versionAtLeast version "12"; 57 - atLeast11 = lib.versionAtLeast version "11"; 58 - atLeast10 = lib.versionAtLeast version "10"; 59 - atLeast9 = lib.versionAtLeast version "9"; 60 - atLeast8 = lib.versionAtLeast version "8"; 61 - atLeast7 = lib.versionAtLeast version "7"; 62 - atLeast6 = lib.versionAtLeast version "6"; 63 - atLeast49 = lib.versionAtLeast version "4.9"; 64 is13 = majorVersion == "13"; 65 is12 = majorVersion == "12"; 66 is11 = majorVersion == "11"; ··· 69 is8 = majorVersion == "8"; 70 is7 = majorVersion == "7"; 71 is6 = majorVersion == "6"; 72 - is49 = majorVersion == "4" && lib.versions.minor version == "9"; 73 - is48 = majorVersion == "4" && lib.versions.minor version == "8"; 74 - in 75 - 76 - # We enable the isl cloog backend. 77 - assert !atLeast6 -> (cloog != null -> isl != null); 78 - 79 - assert langJava -> !atLeast7 && zip != null && unzip != null && zlib != null && boehmgc != null && perl != null; # for `--enable-java-home' 80 - 81 - # Make sure we get GNU sed. 82 - assert stdenv.buildPlatform.isDarwin -> gnused != null; 83 - 84 - # The go frontend is written in c++ 85 - assert langGo -> langCC; 86 - assert (atLeast6 && !is7 && !is8) -> (langAda -> gnat-bootstrap != null); 87 - 88 - # TODO: fixup D bootstapping, probably by using gdc11 (and maybe other changes). 89 - # error: GDC is required to build d 90 - assert atLeast12 -> !langD; 91 - 92 - # threadsCross is just for MinGW 93 - assert threadsCross != {} -> stdenv.targetPlatform.isWindows; 94 95 - # profiledCompiler builds inject non-determinism in one of the compilation stages. 96 - # If turned on, we can't provide reproducible builds anymore 97 - assert reproducibleBuild -> profiledCompiler == false; 98 - 99 - with lib; 100 - with builtins; 101 - 102 - let inherit version; 103 disableBootstrap = atLeast11 && !stdenv.hostPlatform.isDarwin && (atLeast12 -> !profiledCompiler); 104 105 inherit (stdenv) buildPlatform hostPlatform targetPlatform; ··· 117 libX11 libXt libSM libICE libXtst libXrender libXrandr libXi 118 xorgproto 119 ]; 120 - callFile = lib.callPackageWith ({ 121 # lets 122 inherit 123 majorVersion ··· 182 zip 183 zlib 184 ; 185 - } // lib.optionalAttrs (!atLeast7) { 186 inherit 187 boehmgc 188 flex ··· 225 226 in 227 228 # We need all these X libraries when building AWT with GTK. 229 assert !atLeast7 -> (x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []); 230 231 - lib.pipe ((callFile ./common/builder.nix {}) ({ 232 pname = "${crossNameAddon}${name}"; 233 inherit version; 234 ··· 249 then "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz" 250 else "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2"; 251 ${if is10 || is11 || is13 then "hash" else "sha256"} = 252 - versions.srcHashForVersion version; 253 }; 254 255 inherit patches; 256 257 outputs = 258 if atLeast7 259 - then [ "out" "man" "info" ] ++ lib.optional (!langJit) "lib" 260 else if atLeast49 && (langJava || langGo || (if atLeast6 then langJit else targetPlatform.isDarwin)) then ["out" "man" "info"] 261 else [ "out" "lib" "man" "info" ]; 262 ··· 265 libc_dev = stdenv.cc.libc_dev; 266 267 hardeningDisable = [ "format" "pie" ] 268 - ++ lib.optionals (is11 && langAda) [ "fortify3" ]; 269 270 - postPatch = lib.optionalString atLeast7 '' 271 configureScripts=$(find . -name configure) 272 for configureScript in $configureScripts; do 273 patchShebangs $configureScript ··· 275 '' 276 # This should kill all the stdinc frameworks that gcc and friends like to 277 # insert into default search paths. 278 - + lib.optionalString (atLeast6 && hostPlatform.isDarwin) '' 279 - substituteInPlace gcc/config/darwin-c.c${lib.optionalString atLeast12 "c"} \ 280 --replace 'if (stdinc)' 'if (0)' 281 282 substituteInPlace libgcc/config/t-slibgcc-darwin \ ··· 286 --replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname" 287 '' 288 + ( 289 - lib.optionalString (targetPlatform != hostPlatform || stdenv.cc.libc != null) 290 # On NixOS, use the right path to the dynamic linker instead of 291 # `/lib/ld*.so'. 292 (let ··· 296 '' echo "fixing the {GLIBC,UCLIBC,MUSL}_DYNAMIC_LINKER macros..." 297 for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h 298 do 299 - grep -q ${lib.optionalString (!atLeast6) "LIBC"}_DYNAMIC_LINKER "$header" || continue 300 echo " fixing $header..." 301 sed -i "$header" \ 302 -e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g' \ 303 -e 's|define[[:blank:]]*MUSL_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define MUSL_DYNAMIC_LINKER\1 "${libc.out}\2"|g' 304 done 305 - '' + lib.optionalString (atLeast6 && targetPlatform.libc == "musl") '' 306 sed -i gcc/config/linux.h -e '1i#undef LOCAL_INCLUDE_DIR' 307 '' 308 ) 309 )) 310 - + lib.optionalString (atLeast7 && targetPlatform.isAvr) ('' 311 makeFlagsArray+=( 312 '-s' # workaround for hitting hydra log limit 313 'LIMITS_H_TEST=false' ··· 319 320 inherit (callFile ./common/dependencies.nix { }) depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget; 321 322 - preConfigure = (callFile ./common/pre-configure.nix { }) + lib.optionalString atLeast10 '' 323 ln -sf ${libxcrypt}/include/crypt.h libsanitizer/sanitizer_common/crypt.h 324 ''; 325 ··· 338 assert atLeast12 -> (profiledCompiler -> !disableBootstrap); 339 if atLeast11 340 then let target = 341 - lib.optionalString (profiledCompiler) "profiled" + 342 - lib.optionalString (targetPlatform == hostPlatform && hostPlatform == buildPlatform && !disableBootstrap) "bootstrap"; 343 - in lib.optional (target != "") target 344 else 345 optional 346 (targetPlatform == hostPlatform && hostPlatform == buildPlatform) ··· 394 EXTRA_LDFLAGS_FOR_TARGET 395 ; 396 } // optionalAttrs is7 { 397 - NIX_CFLAGS_COMPILE = lib.optionalString (stdenv.cc.isClang && langFortran) "-Wno-unused-command-line-argument" 398 # Downgrade register storage class specifier errors to warnings when building a cross compiler from a clang stdenv. 399 - + lib.optionalString (stdenv.cc.isClang && targetPlatform != hostPlatform) " -Wno-register"; 400 } // optionalAttrs (!is7 && !atLeast12 && stdenv.cc.isClang && targetPlatform != hostPlatform) { 401 NIX_CFLAGS_COMPILE = "-Wno-register"; 402 } // optionalAttrs (!atLeast7) { 403 inherit langJava; 404 } // optionalAttrs atLeast6 { 405 - NIX_LDFLAGS = lib.optionalString hostPlatform.isSunOS "-lm"; 406 }); 407 408 passthru = { 409 inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD langJava version; 410 isGNU = true; 411 - hardeningUnsupportedFlags = lib.optional is48 "stackprotector" 412 - ++ lib.optional (!atLeast11) "zerocallusedregs" 413 - ++ lib.optionals (!atLeast12) [ "fortify3" "trivialautovarinit" ] 414 - ++ lib.optionals (langFortran) [ "fortify" "format" ]; 415 }; 416 417 enableParallelBuilding = true; ··· 426 platforms 427 maintainers 428 ; 429 - } // lib.optionalAttrs (!atLeast11) { 430 badPlatforms = 431 # avr-gcc8 is maintained for the `qmk` package 432 if (is8 && targetPlatform.isAvr) then [] 433 else if !(is48 || is49) then [ "aarch64-darwin" ] 434 - else lib.platforms.darwin; 435 - } // lib.optionalAttrs is11 { 436 badPlatforms = if targetPlatform != hostPlatform then [ "aarch64-darwin" ] else [ ]; 437 }; 438 - } // lib.optionalAttrs (!atLeast10 && stdenv.targetPlatform.isDarwin) { 439 # GCC <10 requires default cctools `strip` instead of `llvm-strip` used by Darwin bintools. 440 preBuild = '' 441 - makeFlagsArray+=('STRIP=${lib.getBin darwin.cctools-port}/bin/${stdenv.cc.targetPrefix}strip') 442 ''; 443 } // optionalAttrs (!atLeast8) { 444 doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv
··· 1 + { lib, stdenv, targetPackages, fetchurl, fetchpatch, fetchFromGitHub, noSysDirs 2 , langC ? true, langCC ? true, langFortran ? false 3 , langAda ? false 4 , langObjC ? stdenv.targetPlatform.isDarwin ··· 48 }: 49 50 let 51 + inherit (lib) 52 + callPackageWith 53 + filter 54 + getBin 55 + maintainers 56 + makeLibraryPath 57 + makeSearchPathOutput 58 + mapAttrs 59 + optional 60 + optionalAttrs 61 + optionals 62 + optionalString 63 + pipe 64 + platforms 65 + versionAtLeast 66 + versions 67 + ; 68 69 + gccVersions = import ./versions.nix; 70 + version = gccVersions.fromMajorMinor majorMinorVersion; 71 + 72 + majorVersion = versions.major version; 73 + atLeast13 = versionAtLeast version "13"; 74 + atLeast12 = versionAtLeast version "12"; 75 + atLeast11 = versionAtLeast version "11"; 76 + atLeast10 = versionAtLeast version "10"; 77 + atLeast9 = versionAtLeast version "9"; 78 + atLeast8 = versionAtLeast version "8"; 79 + atLeast7 = versionAtLeast version "7"; 80 + atLeast6 = versionAtLeast version "6"; 81 + atLeast49 = versionAtLeast version "4.9"; 82 is13 = majorVersion == "13"; 83 is12 = majorVersion == "12"; 84 is11 = majorVersion == "11"; ··· 87 is8 = majorVersion == "8"; 88 is7 = majorVersion == "7"; 89 is6 = majorVersion == "6"; 90 + is49 = majorVersion == "4" && versions.minor version == "9"; 91 + is48 = majorVersion == "4" && versions.minor version == "8"; 92 93 disableBootstrap = atLeast11 && !stdenv.hostPlatform.isDarwin && (atLeast12 -> !profiledCompiler); 94 95 inherit (stdenv) buildPlatform hostPlatform targetPlatform; ··· 107 libX11 libXt libSM libICE libXtst libXrender libXrandr libXi 108 xorgproto 109 ]; 110 + callFile = callPackageWith ({ 111 # lets 112 inherit 113 majorVersion ··· 172 zip 173 zlib 174 ; 175 + } // optionalAttrs (!atLeast7) { 176 inherit 177 boehmgc 178 flex ··· 215 216 in 217 218 + # We enable the isl cloog backend. 219 + assert !atLeast6 -> (cloog != null -> isl != null); 220 + 221 + assert langJava -> !atLeast7 && zip != null && unzip != null && zlib != null && boehmgc != null && perl != null; # for `--enable-java-home' 222 + 223 + # Make sure we get GNU sed. 224 + assert stdenv.buildPlatform.isDarwin -> gnused != null; 225 + 226 + # The go frontend is written in c++ 227 + assert langGo -> langCC; 228 + assert (atLeast6 && !is7 && !is8) -> (langAda -> gnat-bootstrap != null); 229 + 230 + # TODO: fixup D bootstapping, probably by using gdc11 (and maybe other changes). 231 + # error: GDC is required to build d 232 + assert atLeast12 -> !langD; 233 + 234 + # threadsCross is just for MinGW 235 + assert threadsCross != {} -> stdenv.targetPlatform.isWindows; 236 + 237 + # profiledCompiler builds inject non-determinism in one of the compilation stages. 238 + # If turned on, we can't provide reproducible builds anymore 239 + assert reproducibleBuild -> profiledCompiler == false; 240 + 241 # We need all these X libraries when building AWT with GTK. 242 assert !atLeast7 -> (x11Support -> (filter (x: x == null) ([ gtk2 libart_lgpl ] ++ xlibs)) == []); 243 244 + pipe ((callFile ./common/builder.nix {}) ({ 245 pname = "${crossNameAddon}${name}"; 246 inherit version; 247 ··· 262 then "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.xz" 263 else "mirror://gnu/gcc/gcc-${version}/gcc-${version}.tar.bz2"; 264 ${if is10 || is11 || is13 then "hash" else "sha256"} = 265 + gccVersions.srcHashForVersion version; 266 }; 267 268 inherit patches; 269 270 outputs = 271 if atLeast7 272 + then [ "out" "man" "info" ] ++ optional (!langJit) "lib" 273 else if atLeast49 && (langJava || langGo || (if atLeast6 then langJit else targetPlatform.isDarwin)) then ["out" "man" "info"] 274 else [ "out" "lib" "man" "info" ]; 275 ··· 278 libc_dev = stdenv.cc.libc_dev; 279 280 hardeningDisable = [ "format" "pie" ] 281 + ++ optionals (is11 && langAda) [ "fortify3" ]; 282 283 + postPatch = optionalString atLeast7 '' 284 configureScripts=$(find . -name configure) 285 for configureScript in $configureScripts; do 286 patchShebangs $configureScript ··· 288 '' 289 # This should kill all the stdinc frameworks that gcc and friends like to 290 # insert into default search paths. 291 + + optionalString (atLeast6 && hostPlatform.isDarwin) '' 292 + substituteInPlace gcc/config/darwin-c.c${optionalString atLeast12 "c"} \ 293 --replace 'if (stdinc)' 'if (0)' 294 295 substituteInPlace libgcc/config/t-slibgcc-darwin \ ··· 299 --replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname" 300 '' 301 + ( 302 + optionalString (targetPlatform != hostPlatform || stdenv.cc.libc != null) 303 # On NixOS, use the right path to the dynamic linker instead of 304 # `/lib/ld*.so'. 305 (let ··· 309 '' echo "fixing the {GLIBC,UCLIBC,MUSL}_DYNAMIC_LINKER macros..." 310 for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h 311 do 312 + grep -q ${optionalString (!atLeast6) "LIBC"}_DYNAMIC_LINKER "$header" || continue 313 echo " fixing $header..." 314 sed -i "$header" \ 315 -e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g' \ 316 -e 's|define[[:blank:]]*MUSL_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define MUSL_DYNAMIC_LINKER\1 "${libc.out}\2"|g' 317 done 318 + '' + optionalString (atLeast6 && targetPlatform.libc == "musl") '' 319 sed -i gcc/config/linux.h -e '1i#undef LOCAL_INCLUDE_DIR' 320 '' 321 ) 322 )) 323 + + optionalString (atLeast7 && targetPlatform.isAvr) ('' 324 makeFlagsArray+=( 325 '-s' # workaround for hitting hydra log limit 326 'LIMITS_H_TEST=false' ··· 332 333 inherit (callFile ./common/dependencies.nix { }) depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget; 334 335 + preConfigure = (callFile ./common/pre-configure.nix { }) + optionalString atLeast10 '' 336 ln -sf ${libxcrypt}/include/crypt.h libsanitizer/sanitizer_common/crypt.h 337 ''; 338 ··· 351 assert atLeast12 -> (profiledCompiler -> !disableBootstrap); 352 if atLeast11 353 then let target = 354 + optionalString (profiledCompiler) "profiled" + 355 + optionalString (targetPlatform == hostPlatform && hostPlatform == buildPlatform && !disableBootstrap) "bootstrap"; 356 + in optional (target != "") target 357 else 358 optional 359 (targetPlatform == hostPlatform && hostPlatform == buildPlatform) ··· 407 EXTRA_LDFLAGS_FOR_TARGET 408 ; 409 } // optionalAttrs is7 { 410 + NIX_CFLAGS_COMPILE = optionalString (stdenv.cc.isClang && langFortran) "-Wno-unused-command-line-argument" 411 # Downgrade register storage class specifier errors to warnings when building a cross compiler from a clang stdenv. 412 + + optionalString (stdenv.cc.isClang && targetPlatform != hostPlatform) " -Wno-register"; 413 } // optionalAttrs (!is7 && !atLeast12 && stdenv.cc.isClang && targetPlatform != hostPlatform) { 414 NIX_CFLAGS_COMPILE = "-Wno-register"; 415 } // optionalAttrs (!atLeast7) { 416 inherit langJava; 417 } // optionalAttrs atLeast6 { 418 + NIX_LDFLAGS = optionalString hostPlatform.isSunOS "-lm"; 419 }); 420 421 passthru = { 422 inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD langJava version; 423 isGNU = true; 424 + hardeningUnsupportedFlags = optional is48 "stackprotector" 425 + ++ optional (!atLeast11) "zerocallusedregs" 426 + ++ optionals (!atLeast12) [ "fortify3" "trivialautovarinit" ] 427 + ++ optionals (langFortran) [ "fortify" "format" ]; 428 }; 429 430 enableParallelBuilding = true; ··· 439 platforms 440 maintainers 441 ; 442 + } // optionalAttrs (!atLeast11) { 443 badPlatforms = 444 # avr-gcc8 is maintained for the `qmk` package 445 if (is8 && targetPlatform.isAvr) then [] 446 else if !(is48 || is49) then [ "aarch64-darwin" ] 447 + else platforms.darwin; 448 + } // optionalAttrs is11 { 449 badPlatforms = if targetPlatform != hostPlatform then [ "aarch64-darwin" ] else [ ]; 450 }; 451 + } // optionalAttrs (!atLeast10 && stdenv.targetPlatform.isDarwin) { 452 # GCC <10 requires default cctools `strip` instead of `llvm-strip` used by Darwin bintools. 453 preBuild = '' 454 + makeFlagsArray+=('STRIP=${getBin darwin.cctools-port}/bin/${stdenv.cc.targetPrefix}strip') 455 ''; 456 } // optionalAttrs (!atLeast8) { 457 doCheck = false; # requires a lot of tools, causes a dependency cycle for stdenv