···
1
-
{ lib, stdenv, targetPackages, fetchurl, fetchpatch, noSysDirs
2
-
, langC ? true, langCC ? true, langFortran ? false
4
-
, langObjC ? stdenv.targetPlatform.isDarwin
5
-
, langObjCpp ? stdenv.targetPlatform.isDarwin
8
-
, reproducibleBuild ? true
9
-
, profiledCompiler ? false
11
-
, staticCompiler ? false
12
-
, enableShared ? stdenv.targetPlatform.hasSharedLibraries
13
-
, enableLTO ? stdenv.hostPlatform.hasSharedLibraries
15
-
, perl ? null # optional, for texi2pod (then pod2man)
16
-
, gmp, mpfr, libmpc, gettext, which, patchelf, binutils
17
-
, isl ? null # optional, for the Graphite optimization framework.
19
-
, libucontext ? null
20
-
, gnat-bootstrap ? null
21
-
, enableMultilib ? false
22
-
, enablePlugin ? stdenv.hostPlatform == stdenv.buildPlatform # Whether to support user-supplied plug-ins
25
-
, threadsCross ? null # for MinGW
26
-
, withoutTargetLibc ? false
28
-
, cloog # unused; just for compat with gcc4, as we override the parameter on some places
31
-
, disableGdbPlugin ? !enablePlugin
36
-
# Make sure we get GNU sed.
37
-
assert stdenv.buildPlatform.isDarwin -> gnused != null;
39
-
# The go frontend is written in c++
40
-
assert langGo -> langCC;
41
-
assert langAda -> gnat-bootstrap != null;
43
-
# TODO: fixup D bootstapping, probably by using gdc11 (and maybe other changes).
44
-
# error: GDC is required to build d
47
-
# threadsCross is just for MinGW
48
-
assert threadsCross != {} -> stdenv.targetPlatform.isWindows;
50
-
# profiledCompiler builds inject non-determinism in one of the compilation stages.
51
-
# If turned on, we can't provide reproducible builds anymore
52
-
assert reproducibleBuild -> profiledCompiler == false;
57
-
let majorVersion = "13";
58
-
version = "${majorVersion}.2.0";
59
-
disableBootstrap = !stdenv.hostPlatform.isDarwin && !profiledCompiler;
61
-
inherit (stdenv) buildPlatform hostPlatform targetPlatform;
64
-
optional (targetPlatform != hostPlatform) ../libstdc++-target.patch
65
-
++ optional noSysDirs ../gcc-12-no-sys-dirs.patch
66
-
++ optional noSysDirs ./no-sys-dirs-riscv.patch
68
-
../gnat-cflags-11.patch
69
-
../gcc-12-gfortran-driving.patch
72
-
# We only apply this patch when building a native toolchain for aarch64-darwin, as it breaks building
73
-
# a foreign one: https://github.com/iains/gcc-12-branch/issues/18
74
-
++ optional (stdenv.isDarwin && stdenv.isAarch64 && buildPlatform == hostPlatform && hostPlatform == targetPlatform) (fetchpatch {
75
-
name = "gcc-13-darwin-aarch64-support.patch";
76
-
url = "https://raw.githubusercontent.com/Homebrew/formula-patches/3c5cbc8e9cf444a1967786af48e430588e1eb481/gcc/gcc-13.2.0.diff";
77
-
sha256 = "sha256-Y5r3U3dwAFG6+b0TNCFd18PNxYu2+W/5zDbZ5cHvv+U=";
79
-
++ optional langD ../libphobos.patch
81
-
# backport fixes to build gccgo with musl libc
82
-
++ optionals (langGo && stdenv.hostPlatform.isMusl) [
84
-
excludes = [ "gcc/go/gofrontend/MERGE" ];
85
-
url = "https://github.com/gcc-mirror/gcc/commit/cf79b1117bd177d3d4c6ed24b6fa243c3628ac2d.diff";
86
-
hash = "sha256-mS5ZiYi5D8CpGXrWg3tXlbhp4o86ew1imCTwaHLfl+I=";
89
-
excludes = [ "gcc/go/gofrontend/MERGE" ];
90
-
url = "https://github.com/gcc-mirror/gcc/commit/7f195a2270910a6ed08bd76e3a16b0a6503f9faf.diff";
91
-
hash = "sha256-Ze/cFM0dQofKH00PWPDoklXUlwWhwA1nyTuiDAZ6FKo=";
94
-
excludes = [ "gcc/go/gofrontend/MERGE" ];
95
-
url = "https://github.com/gcc-mirror/gcc/commit/762fd5e5547e464e25b4bee435db6df4eda0de90.diff";
96
-
hash = "sha256-o28upwTcHAnHG2Iq0OewzwSBEhHs+XpBGdIfZdT81pk=";
99
-
excludes = [ "gcc/go/gofrontend/MERGE" ];
100
-
url = "https://github.com/gcc-mirror/gcc/commit/e73d9fcafbd07bc3714fbaf8a82db71d50015c92.diff";
101
-
hash = "sha256-1SjYCVHLEUihdON2TOC3Z2ufM+jf2vH0LvYtZL+c1Fo=";
104
-
excludes = [ "gcc/go/gofrontend/MERGE" ];
105
-
url = "https://github.com/gcc-mirror/gcc/commit/b6c6a3d64f2e4e9347733290aca3c75898c44b2e.diff";
106
-
hash = "sha256-RycJ3YCHd3MXtYFjxP0zY2Wuw7/C4bWoBAQtTKJZPOQ=";
109
-
excludes = [ "gcc/go/gofrontend/MERGE" ];
110
-
url = "https://github.com/gcc-mirror/gcc/commit/2b1a604a9b28fbf4f382060bebd04adb83acc2f9.diff";
111
-
hash = "sha256-WiBQG0Xbk75rHk+AMDvsbrm+dc7lDH0EONJXSdEeMGE=";
114
-
url = "https://github.com/gcc-mirror/gcc/commit/c86b726c048eddc1be320c0bf64a897658bee13d.diff";
115
-
hash = "sha256-QSIlqDB6JRQhbj/c3ejlmbfWz9l9FurdSWxpwDebnlI=";
119
-
# Fix detection of bootstrap compiler Ada support (cctools as) on Nix Darwin
120
-
++ optional (stdenv.isDarwin && langAda) ../ada-cctools-as-detection-configure.patch
122
-
# Use absolute path in GNAT dylib install names on Darwin
123
-
++ optional (stdenv.isDarwin && langAda) ../gnat-darwin-dylib-install-name.patch
126
-
/* Cross-gcc settings (build == host != target) */
127
-
crossMingw = targetPlatform != hostPlatform && targetPlatform.libc == "msvcrt";
128
-
stageNameAddon = if withoutTargetLibc then "stage-static" else "stage-final";
129
-
crossNameAddon = optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-${stageNameAddon}-";
131
-
callFile = lib.callPackageWith {
144
-
# inherit generated with 'nix eval --json --impure --expr "with import ./. {}; lib.attrNames (lib.functionArgs gcc13.cc.override)" | jq '.[]' --raw-output'
198
-
lib.pipe ((callFile ../common/builder.nix {}) ({
199
-
pname = "${crossNameAddon}${name}";
203
-
url = "mirror://gcc/releases/gcc-${version}/gcc-${version}.tar.xz";
204
-
hash = "sha256-4nXnZEKmBnNBon8Exca4PYYTFEAEwEE1KIY9xrXHQ9o=";
209
-
outputs = [ "out" "man" "info" ] ++ lib.optional (!langJit) "lib";
210
-
setOutputFlags = false;
211
-
NIX_NO_SELF_RPATH = true;
213
-
libc_dev = stdenv.cc.libc_dev;
215
-
hardeningDisable = [ "format" "pie" ];
218
-
configureScripts=$(find . -name configure)
219
-
for configureScript in $configureScripts; do
220
-
patchShebangs $configureScript
223
-
# This should kill all the stdinc frameworks that gcc and friends like to
224
-
# insert into default search paths.
225
-
+ lib.optionalString hostPlatform.isDarwin ''
226
-
substituteInPlace gcc/config/darwin-c.cc \
227
-
--replace 'if (stdinc)' 'if (0)'
229
-
substituteInPlace libgcc/config/t-slibgcc-darwin \
230
-
--replace "-install_name @shlib_slibdir@/\$(SHLIB_INSTALL_NAME)" "-install_name ''${!outputLib}/lib/\$(SHLIB_INSTALL_NAME)"
232
-
substituteInPlace libgfortran/configure \
233
-
--replace "-install_name \\\$rpath/\\\$soname" "-install_name ''${!outputLib}/lib/\\\$soname"
236
-
lib.optionalString (targetPlatform != hostPlatform || stdenv.cc.libc != null)
237
-
# On NixOS, use the right path to the dynamic linker instead of
240
-
libc = if libcCross != null then libcCross else stdenv.cc.libc;
243
-
'' echo "fixing the \`GLIBC_DYNAMIC_LINKER', \`UCLIBC_DYNAMIC_LINKER', and \`MUSL_DYNAMIC_LINKER' macros..."
244
-
for header in "gcc/config/"*-gnu.h "gcc/config/"*"/"*.h
246
-
grep -q _DYNAMIC_LINKER "$header" || continue
247
-
echo " fixing \`$header'..."
249
-
-e 's|define[[:blank:]]*\([UCG]\+\)LIBC_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define \1LIBC_DYNAMIC_LINKER\2 "${libc.out}\3"|g' \
250
-
-e 's|define[[:blank:]]*MUSL_DYNAMIC_LINKER\([0-9]*\)[[:blank:]]"\([^\"]\+\)"$|define MUSL_DYNAMIC_LINKER\1 "${libc.out}\2"|g'
253
-
+ lib.optionalString (targetPlatform.libc == "musl")
255
-
sed -i gcc/config/linux.h -e '1i#undef LOCAL_INCLUDE_DIR'
259
-
+ lib.optionalString targetPlatform.isAvr ''
261
-
'-s' # workaround for hitting hydra log limit
262
-
'LIMITS_H_TEST=false'
266
-
inherit noSysDirs staticCompiler withoutTargetLibc
267
-
libcCross crossMingw;
269
-
inherit (callFile ../common/dependencies.nix { }) depsBuildBuild nativeBuildInputs depsBuildTarget buildInputs depsTargetTarget;
271
-
NIX_LDFLAGS = lib.optionalString hostPlatform.isSunOS "-lm";
274
-
preConfigure = (callFile ../common/pre-configure.nix { }) + ''
275
-
ln -sf ${libxcrypt}/include/crypt.h libsanitizer/sanitizer_common/crypt.h
278
-
dontDisableStatic = true;
280
-
configurePlatforms = [ "build" "host" "target" ];
282
-
configureFlags = callFile ../common/configure-flags.nix { };
284
-
targetConfig = if targetPlatform != hostPlatform then targetPlatform.config else null;
287
-
# we do not yet have Nix-driven profiling
288
-
assert profiledCompiler -> !disableBootstrap;
290
-
lib.optionalString (profiledCompiler) "profiled" +
291
-
lib.optionalString (targetPlatform == hostPlatform && hostPlatform == buildPlatform && !disableBootstrap) "bootstrap";
292
-
in lib.optional (target != "") target;
294
-
inherit (callFile ../common/strip-attributes.nix { })
296
-
stripDebugListTarget
299
-
# https://gcc.gnu.org/PR109898
300
-
enableParallelInstalling = false;
302
-
# https://gcc.gnu.org/install/specific.html#x86-64-x-solaris210
303
-
${if hostPlatform.system == "x86_64-solaris" then "CC" else null} = "gcc -m64";
305
-
# Setting $CPATH and $LIBRARY_PATH to make sure both `gcc' and `xgcc' find the
306
-
# library headers and binaries, regarless of the language being compiled.
308
-
# Likewise, the LTO code doesn't find zlib.
310
-
# Cross-compiling, we need gcc not to read ./specs in order to build the g++
311
-
# compiler (after the specs for the cross-gcc are created). Having
312
-
# LIBRARY_PATH= makes gcc read the specs from ., and the build breaks.
314
-
CPATH = optionals (targetPlatform == hostPlatform) (makeSearchPathOutput "dev" "include" ([]
315
-
++ optional (zlib != null) zlib
318
-
LIBRARY_PATH = optionals (targetPlatform == hostPlatform) (makeLibraryPath (optional (zlib != null) zlib));
320
-
inherit (callFile ../common/extra-target-flags.nix { })
321
-
EXTRA_FLAGS_FOR_TARGET
322
-
EXTRA_LDFLAGS_FOR_TARGET
326
-
inherit langC langCC langObjC langObjCpp langAda langFortran langGo langD version;
330
-
enableParallelBuilding = true;
331
-
inherit enableShared enableMultilib;
334
-
inherit (callFile ../common/meta.nix { })
345
-
// optionalAttrs (enableMultilib) { dontMoveLib64 = true; }
348
-
(callPackage ../common/libgcc.nix { inherit version langC langCC langJit targetPlatform hostPlatform withoutTargetLibc enableShared; })
349
-
(callPackage ../common/checksum.nix { inherit langC langCC; })