Skip to content

Commit

Permalink
threadsCross: factor out copy-and-pasted code
Browse files Browse the repository at this point in the history
In #236598 a chunk of code was
simply copy-pasted-tweaked.  The more often this happens, the more
unmaintainable nixpkgs becomes.  Let's use the wonderful functions
and conditionals that Nix gives us to avoid this duplication.
  • Loading branch information
Adam Joseph committed Jun 30, 2023
1 parent bec99c5 commit ffd7dbc
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15404,7 +15404,7 @@ with pkgs;
profiledCompiler = false;

libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross_pre_gcc_13 else { };
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "4.8" else { };

isl = if !stdenv.isDarwin then isl_0_14 else null;
cloog = if !stdenv.isDarwin then cloog else null;
Expand All @@ -15418,7 +15418,7 @@ with pkgs;
profiledCompiler = false;

libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross_pre_gcc_13 else { };
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "4.9" else { };

isl = if !stdenv.isDarwin then isl_0_11 else null;

Expand All @@ -15435,7 +15435,7 @@ with pkgs;
profiledCompiler = false;

libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross_pre_gcc_13 else { };
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "6" else { };

# gcc 10 is too strict to cross compile gcc <= 8
stdenv = if (stdenv.targetPlatform != stdenv.buildPlatform) && stdenv.cc.isGNU then gcc7Stdenv else stdenv;
Expand All @@ -15454,7 +15454,7 @@ with pkgs;
profiledCompiler = false;

libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross_pre_gcc_13 else { };
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "7" else { };

# gcc 10 is too strict to cross compile gcc <= 8
stdenv = if (stdenv.targetPlatform != stdenv.buildPlatform) && stdenv.cc.isGNU then gcc7Stdenv else stdenv;
Expand All @@ -15469,7 +15469,7 @@ with pkgs;
profiledCompiler = false;

libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross_pre_gcc_13 else { };
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "8" else { };

# gcc 10 is too strict to cross compile gcc <= 8
stdenv = if (stdenv.targetPlatform != stdenv.buildPlatform) && stdenv.cc.isGNU then gcc7Stdenv else stdenv;
Expand All @@ -15484,7 +15484,7 @@ with pkgs;
profiledCompiler = false;

libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross_pre_gcc_13 else { };
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "9" else { };

isl = if !stdenv.isDarwin then isl_0_20 else null;
}));
Expand All @@ -15496,7 +15496,7 @@ with pkgs;
profiledCompiler = false;

libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross_pre_gcc_13 else { };
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "10" else { };

isl = if !stdenv.isDarwin then isl_0_20 else null;
}));
Expand All @@ -15508,7 +15508,7 @@ with pkgs;
profiledCompiler = false;

libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross_pre_gcc_13 else { };
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "11" else { };

isl = if !stdenv.isDarwin then isl_0_20 else null;
}));
Expand All @@ -15520,7 +15520,7 @@ with pkgs;
profiledCompiler = false;

libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross_pre_gcc_13 else { };
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "12" else { };

isl = if !stdenv.isDarwin then isl_0_20 else null;
}));
Expand All @@ -15532,7 +15532,7 @@ with pkgs;
profiledCompiler = false;

libcCross = if stdenv.targetPlatform != stdenv.buildPlatform then libcCross else null;
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCross else { };
threadsCross = if stdenv.targetPlatform != stdenv.buildPlatform then threadsCrossFor "13" else { };

isl = if !stdenv.isDarwin then isl_0_20 else null;
}));
Expand Down Expand Up @@ -17140,10 +17140,7 @@ with pkgs;
# want the C++ library to be explicitly chosen by the caller, and null by
# default.
libcxx ? null
, extraPackages ? lib.optional (cc.isGNU or false && stdenv.targetPlatform.isMinGW)
(if lib.versionAtLeast cc.version "13"
then threadsCross.package
else threadsCross_pre_gcc_13.package)
, extraPackages ? lib.optional (cc.isGNU or false && stdenv.targetPlatform.isMinGW) ((threadsCrossFor cc.version).package)
, nixSupport ? {}
, ...
} @ extraArgs:
Expand Down Expand Up @@ -21173,20 +21170,17 @@ with pkgs;

libcCross = assert stdenv.targetPlatform != stdenv.buildPlatform; libcCrossChooser stdenv.targetPlatform.libc;

threadsCross_pre_gcc_13 = if stdenv.targetPlatform.isMinGW && !(stdenv.targetPlatform.useLLVM or false)
threadsCross = threadsCrossFor null;
threadsCrossFor = cc_version:
if stdenv.targetPlatform.isMinGW && !(stdenv.targetPlatform.useLLVM or false)
then {
# other possible values: win32 or posix
model = "mcf";
# For win32 or posix set this to null
package = targetPackages.windows.mcfgthreads_pre_gcc_13 or windows.mcfgthreads_pre_gcc_13;
} else { };

threadsCross = if stdenv.targetPlatform.isMinGW && !(stdenv.targetPlatform.useLLVM or false)
then {
# other possible values: win32 or posix
model = "mcf";
# For win32 or posix set this to null
package = targetPackages.windows.mcfgthreads or windows.mcfgthreads;
package =
if cc_version == null || lib.versionAtLeast cc_version "13"
then targetPackages.windows.mcfgthreads or windows.mcfgthreads
else targetPackages.windows.mcfgthreads_pre_gcc_13 or windows.mcfgthreads_pre_gcc_13;
} else { };

wasilibc = callPackage ../development/libraries/wasilibc {
Expand Down

0 comments on commit ffd7dbc

Please sign in to comment.