1{
2 lib,
3 stdenv,
4 pkgs,
5 targetPackages,
6 callPackage,
7 isl_0_20,
8 noSysDirs,
9 lowPrio,
10 wrapCC,
11}@args:
12
13let
14 versions = import ./versions.nix;
15 gccForMajorMinorVersion =
16 majorMinorVersion:
17 let
18 majorVersion = lib.versions.major majorMinorVersion;
19 atLeast = lib.versionAtLeast majorMinorVersion;
20 attrName = "gcc${lib.replaceStrings [ "." ] [ "" ] majorMinorVersion}";
21 pkg = lowPrio (
22 wrapCC (
23 callPackage ./default.nix {
24 inherit noSysDirs;
25 inherit majorMinorVersion;
26 reproducibleBuild = true;
27 profiledCompiler = false;
28 libcCross =
29 if !lib.systems.equals stdenv.targetPlatform stdenv.buildPlatform then
30 targetPackages.libc or pkgs.libc
31 else
32 null;
33 threadsCross =
34 if !lib.systems.equals stdenv.targetPlatform stdenv.buildPlatform then
35 targetPackages.threads or pkgs.threads
36 else
37 { };
38 isl = if stdenv.hostPlatform.isDarwin then null else isl_0_20;
39 # do not allow version skew when cross-building gcc
40 #
41 # When `gcc` is cross-built (`build` != `target` && `host` == `target`)
42 # `gcc` assumes that it has a compatible cross-compiler in the environment
43 # that can build target libraries. Version of a cross-compiler has to
44 # match the compiler being cross-built as libraries frequently use fresh
45 # compiler features, like `-std=c++26` or target-specific types like
46 # `_Bfloat16`.
47 # Version mismatch causes build failures like:
48 # https://github.com/NixOS/nixpkgs/issues/351905
49 #
50 # Similar problems (but on a smaller scale) happen when a `gcc`
51 # cross-compiler is built (`build` == `host` && `host` != `target`) built
52 # by a mismatching version of a native compiler (`build` == `host` &&
53 # `host` == `target`).
54 #
55 # Let's fix both problems by requiring the same compiler version for
56 # cross-case.
57 stdenv =
58 if
59 (
60 (!lib.systems.equals stdenv.targetPlatform stdenv.buildPlatform)
61 || (!lib.systems.equals stdenv.hostPlatform stdenv.targetPlatform)
62 )
63 && stdenv.cc.isGNU
64 then
65 pkgs."gcc${majorVersion}Stdenv"
66 else
67 stdenv;
68 }
69 )
70 );
71 in
72 lib.nameValuePair attrName pkg;
73in
74lib.listToAttrs (map gccForMajorMinorVersion versions.allMajorVersions)