From c2d1d8b7519b540d3f592b2ea40dd867ceb35d4b Mon Sep 17 00:00:00 2001 From: Adam Joseph Date: Sat, 1 Jul 2023 15:19:59 -0700 Subject: [PATCH] gcc: deduplicate top-level expressions This commit deduplicates the copy-pasted gcc mess in pkgs/top-level/all-packages.txt, replacing it with a single expression that branches based on the chosen version. This refactoring has exposed several bizzare behaviors in our historical gcc expressions. These are almost certainly a result of people reaching back and making a change only to the version they care about, and neglecting adjacent versions. These oddities went un-noticed because in copy-paste-duplicated form it is nearly impossible to notice what has happened. When refactored into branch-on-version form, the irregularities jump out at you: 1. The ISL version we are using jumps *backward* from 0.14 on gcc48 to 0.11 on gcc49, then forward again at gcc6. If gcc49 cannot use isl 0.14 why is gcc48 able to? I doubt this is right, but if it is there should be an explanatory comment, and I found none. 2. gcc6 bumps to isl 0.17 only if compiling for RedoxOS. This probably means that gcc6 is able to use isl 0.17 everywhere. If not, there should have been a comment explaining why RedoxOS is special here. 3. gcc49 on Darwin uses gccStdenv because "build fails on Darwin with clang"; surely if that is the case then that is true for gcc48 as well, no? 4. gcc49 overrides cloog to v0.18.0, but gcc48 doesn't. Again, very weird, probably somebody meant to override gcc 4.9 *and all older versions*, not just that one particular version. 5. when cross-compiling, gcc6,7,8 override stdenv to gcc7Stdenv because "gcc 10 is too strict to cross compile gcc <= 8" yet this override was not applied to any other versions of gcc which are "<= 8". It's also odd that gcc7Stdenv is used rather than gcc8Stdenv. The best part about switch-on-version form is that oversights like the above *make the code more verbose* so they stand out. Fixing these likely-bugs will make the code simpler and shorter. In copy-paste-duplicated style the opposite is true: you get shorter code by *forgetting* to apply changes to all the versions that need the change! That's a very perverse incentive. This PR does not attempt to change or fix any of these behaviors. I have confirmed that it does not affect eval (same drv-hash) for all gcc versions on both x86_64-linux and x86_64-darwin. --- pkgs/top-level/all-packages.nix | 174 +++++++------------------------- 1 file changed, 35 insertions(+), 139 deletions(-) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f7f0aea87660bf7..6c64b02126b0c30 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -15583,145 +15583,41 @@ with pkgs; extraPackages = []; }; - gcc48 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/4.8 { - inherit noSysDirs; - - reproducibleBuild = true; - profiledCompiler = false; - - libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; - threadsCross = lib.optionalAttrs (stdenv.targetPlatform != stdenv.buildPlatform) (threadsCrossFor "4.8"); - - isl = if !stdenv.isDarwin then isl_0_14 else null; - cloog = if !stdenv.isDarwin then cloog else null; - texinfo = texinfo5; # doesn't validate since 6.1 -> 6.3 bump - })); - - gcc49 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/4.9 { - inherit noSysDirs; - - reproducibleBuild = true; - profiledCompiler = false; - - libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; - threadsCross = lib.optionalAttrs (stdenv.targetPlatform != stdenv.buildPlatform) (threadsCrossFor "4.9"); - - isl = if !stdenv.isDarwin then isl_0_11 else null; - - cloog = if !stdenv.isDarwin then cloog_0_18_0 else null; - - # Build fails on Darwin with clang - stdenv = if stdenv.isDarwin then gccStdenv else stdenv; - })); - - gcc6 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/6 { - inherit noSysDirs; - - reproducibleBuild = true; - profiledCompiler = false; - - libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; - threadsCross = lib.optionalAttrs (stdenv.targetPlatform != stdenv.buildPlatform) (threadsCrossFor "6"); - - # gcc 10 is too strict to cross compile gcc <= 8 - stdenv = if (stdenv.targetPlatform != stdenv.buildPlatform) && stdenv.cc.isGNU then gcc7Stdenv else stdenv; - - isl = if stdenv.isDarwin - then null - else if stdenv.targetPlatform.isRedox - then isl_0_17 - else isl_0_14; - })); - - gcc7 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/7 { - inherit noSysDirs; - - reproducibleBuild = true; - profiledCompiler = false; - - libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; - threadsCross = lib.optionalAttrs (stdenv.targetPlatform != stdenv.buildPlatform) (threadsCrossFor "7"); - - # gcc 10 is too strict to cross compile gcc <= 8 - stdenv = if (stdenv.targetPlatform != stdenv.buildPlatform) && stdenv.cc.isGNU then gcc7Stdenv else stdenv; - - isl = if !stdenv.isDarwin then isl_0_17 else null; - })); - - gcc8 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/8 { - inherit noSysDirs; - - reproducibleBuild = true; - profiledCompiler = false; - - libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; - threadsCross = lib.optionalAttrs (stdenv.targetPlatform != stdenv.buildPlatform) (threadsCrossFor "8"); - - # gcc 10 is too strict to cross compile gcc <= 8 - stdenv = if (stdenv.targetPlatform != stdenv.buildPlatform) && stdenv.cc.isGNU then gcc7Stdenv else stdenv; - - isl = if !stdenv.isDarwin then isl_0_17 else null; - })); - - gcc9 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/9 { - inherit noSysDirs; - - reproducibleBuild = true; - profiledCompiler = false; - - libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; - threadsCross = lib.optionalAttrs (stdenv.targetPlatform != stdenv.buildPlatform) (threadsCrossFor "9"); - - isl = if !stdenv.isDarwin then isl_0_20 else null; - })); - - gcc10 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/10 { - inherit noSysDirs; - - reproducibleBuild = true; - profiledCompiler = false; - - libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; - threadsCross = lib.optionalAttrs (stdenv.targetPlatform != stdenv.buildPlatform) (threadsCrossFor "10"); - - isl = if !stdenv.isDarwin then isl_0_20 else null; - })); - - gcc11 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/11 { - inherit noSysDirs; - - reproducibleBuild = true; - profiledCompiler = false; - - libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; - threadsCross = lib.optionalAttrs (stdenv.targetPlatform != stdenv.buildPlatform) (threadsCrossFor "11"); - - isl = if !stdenv.isDarwin then isl_0_20 else null; - })); - - gcc12 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/12 { - inherit noSysDirs; - - reproducibleBuild = true; - profiledCompiler = false; - - libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; - threadsCross = lib.optionalAttrs (stdenv.targetPlatform != stdenv.buildPlatform) (threadsCrossFor "12"); - - isl = if !stdenv.isDarwin then isl_0_20 else null; - })); - - gcc13 = lowPrio (wrapCC (callPackage ../development/compilers/gcc/13 { - inherit noSysDirs; - - reproducibleBuild = true; - profiledCompiler = false; - - libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; - threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "13" else { }; - - isl = if !stdenv.isDarwin then isl_0_20 else null; - })); + # This expression will be pushed into pkgs/development/compilers/gcc/common + # once the top-level gcc/${version}/default.nix files are deduplicated. + inherit + (lib.listToAttrs (map (version: + let atLeast = lib.versionAtLeast version; + attrName = "gcc${lib.replaceStrings ["."] [""] version}"; + pkg = lowPrio (wrapCC (callPackage (../development/compilers/gcc + "/${version}") ({ + inherit noSysDirs; + reproducibleBuild = true; + profiledCompiler = false; + libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null; + threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor version else { }; + isl = if stdenv.isDarwin then null + else if atLeast "9" then isl_0_20 + else if atLeast "7" then isl_0_17 + else if atLeast "6" then (if stdenv.targetPlatform.isRedox then isl_0_17 else isl_0_14) + else if atLeast "4.9" then isl_0_11 + else /* "4.8" */ isl_0_14; + } // lib.optionalAttrs (version == "4.8") { + texinfo = texinfo5; # doesn't validate since 6.1 -> 6.3 bump + } // lib.optionalAttrs (version == "4.9") { + # Build fails on Darwin with clang + stdenv = if stdenv.isDarwin then gccStdenv else stdenv; + } // lib.optionalAttrs (!(atLeast "6")) { + cloog = if stdenv.isDarwin + then null + else if atLeast "4.9" then cloog_0_18_0 + else /* 4.8 */ cloog; + } // lib.optionalAttrs (atLeast "6" && !(atLeast "9")) { + # gcc 10 is too strict to cross compile gcc <= 8 + stdenv = if (stdenv.targetPlatform != stdenv.buildPlatform) && stdenv.cc.isGNU then gcc7Stdenv else stdenv; + }))); + in lib.nameValuePair attrName pkg + ) [ "4.8" "4.9" "6" "7" "8" "9" "10" "11" "12" "13" ])) + gcc48 gcc49 gcc6 gcc7 gcc8 gcc9 gcc10 gcc11 gcc12 gcc13; gcc_latest = gcc13;