nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 254 lines 10 kB view raw
1{ 2 lib, 3 stdenv, 4 langC, 5 langAda, 6 langObjC, 7 langObjCpp, 8 langFortran, 9 langGo, 10 reproducibleBuild, 11 profiledCompiler, 12 langJit, 13 staticCompiler, 14 enableShared, 15 enableLTO, 16 version, 17 fetchpatch, 18 majorVersion, 19 targetPlatform, 20 hostPlatform, 21 noSysDirs, 22 buildPlatform, 23 fetchurl, 24 withoutTargetLibc, 25 threadsCross, 26}: 27 28let 29 atLeast15 = lib.versionAtLeast version "15"; 30 atLeast14 = lib.versionAtLeast version "14"; 31 is15 = majorVersion == "15"; 32 is14 = majorVersion == "14"; 33 is13 = majorVersion == "13"; 34 35 # We only apply these patches when building a native toolchain for 36 # aarch64-darwin, as it breaks building a foreign one: 37 # https://github.com/iains/gcc-12-branch/issues/18 38 canApplyIainsDarwinPatches = 39 stdenv.hostPlatform.isDarwin 40 && stdenv.hostPlatform.isAarch64 41 && (lib.systems.equals buildPlatform hostPlatform) 42 && (lib.systems.equals hostPlatform targetPlatform); 43 44 inherit (lib) optionals optional; 45in 46 47# 48# Patches below are organized into two general categories: 49# 1. Patches relevant on every platform 50# 2. Patches relevant on specific platforms 51# 52 53## 1. Patches relevant on every platform #################################### 54 55optionals noSysDirs ( 56 [ 57 # Do not try looking for binaries and libraries in /lib and /usr/lib 58 ./gcc-12-no-sys-dirs.patch 59 ] 60 ++ ( 61 { 62 "15" = [ 63 # Do not try looking for binaries and libraries in /lib and /usr/lib 64 ./13/no-sys-dirs-riscv.patch 65 # Mangle the nix store hash in __FILE__ to prevent unneeded runtime references 66 # 67 # TODO: Remove these and the `useMacroPrefixMap` conditional 68 # in `cc-wrapper` once <https://gcc.gnu.org/PR111527> 69 # is fixed. 70 ./13/mangle-NIX_STORE-in-__FILE__.patch 71 ]; 72 "14" = [ 73 ./13/no-sys-dirs-riscv.patch 74 ./13/mangle-NIX_STORE-in-__FILE__.patch 75 ./13/libsanitizer-fix-with-glibc-2.42.patch 76 ]; 77 "13" = [ 78 ./13/no-sys-dirs-riscv.patch 79 ./13/mangle-NIX_STORE-in-__FILE__.patch 80 ./13/libsanitizer-fix-with-glibc-2.42.patch 81 ]; 82 } 83 ."${majorVersion}" or [ ] 84 ) 85) 86# Pass CFLAGS on to gnat 87++ optional langAda ./gnat-cflags-11.patch 88++ 89 optional langFortran 90 # Fix interaction of gfortran and libtool 91 # Fixes the output of -v 92 # See also https://github.com/nixOS/nixpkgs/commit/cc6f814a8f0e9b70ede5b24192558664fa1f98a2 93 ./gcc-12-gfortran-driving.patch 94# Do not pass a default include dir on PowerPC+Musl 95# See https://github.com/NixOS/nixpkgs/pull/45340/commits/d6bb7d45162ac93e017cc9b665ae4836f6410710 96++ [ ./ppc-musl.patch ] 97# Moves the .cfi_starproc instruction to after the function label 98# Needed to build llvm-18 and later 99# See https://github.com/NixOS/nixpkgs/pull/354107/commits/2de1b4b14e17f42ba8b4bf43a29347c91511e008 100++ optional (!atLeast14) ./cfi_startproc-reorder-label-09-1.diff 101++ optional (atLeast14 && !canApplyIainsDarwinPatches) ./cfi_startproc-reorder-label-14-1.diff 102# c++tools: Don't check --enable-default-pie. 103# --enable-default-pie breaks bootstrap gcc otherwise, because libiberty.a is not found 104++ optional (is14 || is15) ./c++tools-dont-check-enable-default-pie.patch 105# http://gcc.gnu.org/PR120718 backport (will be inclkuded in 15.3.0) to 106# fix `highway-1.3.0` ICE on aarch64-linux. 107++ optional is15 ./15/aarch64-sve-rtx.patch 108 109## 2. Patches relevant on specific platforms #################################### 110 111### Musl+Go+gcc12 112 113# backport fixes to build gccgo with musl libc 114++ optionals (stdenv.hostPlatform.isMusl && langGo) [ 115 # libgo: handle stat st_atim32 field and SYS_SECCOMP 116 # syscall: gofmt 117 # Add blank lines after //sys comments where needed, and then run gofmt 118 # on the syscall package with the new formatter. 119 # See https://go-review.googlesource.com/c/gofrontend/+/412074 120 (fetchpatch { 121 excludes = [ "gcc/go/gofrontend/MERGE" ]; 122 url = "https://github.com/gcc-mirror/gcc/commit/cf79b1117bd177d3d4c6ed24b6fa243c3628ac2d.diff"; 123 hash = "sha256-mS5ZiYi5D8CpGXrWg3tXlbhp4o86ew1imCTwaHLfl+I="; 124 }) 125 # libgo: permit loff_t and off_t to be macros 126 # See https://go-review.googlesource.com/c/gofrontend/+/412075 127 (fetchpatch { 128 excludes = [ "gcc/go/gofrontend/MERGE" ]; 129 url = "https://github.com/gcc-mirror/gcc/commit/7f195a2270910a6ed08bd76e3a16b0a6503f9faf.diff"; 130 hash = "sha256-Ze/cFM0dQofKH00PWPDoklXUlwWhwA1nyTuiDAZ6FKo="; 131 }) 132 # libgo: handle stat st_atim32 field and SYS_SECCOMP 133 # See https://go-review.googlesource.com/c/gofrontend/+/415294 134 (fetchpatch { 135 excludes = [ "gcc/go/gofrontend/MERGE" ]; 136 url = "https://github.com/gcc-mirror/gcc/commit/762fd5e5547e464e25b4bee435db6df4eda0de90.diff"; 137 hash = "sha256-o28upwTcHAnHG2Iq0OewzwSBEhHs+XpBGdIfZdT81pk="; 138 }) 139 # runtime: portable access to sigev_notify_thread_id 140 # See https://sourceware.org/bugzilla/show_bug.cgi?id=27417 141 # See https://go-review.googlesource.com/c/gofrontend/+/434755 142 (fetchpatch { 143 excludes = [ "gcc/go/gofrontend/MERGE" ]; 144 url = "https://github.com/gcc-mirror/gcc/commit/e73d9fcafbd07bc3714fbaf8a82db71d50015c92.diff"; 145 hash = "sha256-1SjYCVHLEUihdON2TOC3Z2ufM+jf2vH0LvYtZL+c1Fo="; 146 }) 147 # syscall, runtime: always call XSI strerror_r 148 # See https://go-review.googlesource.com/c/gofrontend/+/454176 149 (fetchpatch { 150 excludes = [ "gcc/go/gofrontend/MERGE" ]; 151 url = "https://github.com/gcc-mirror/gcc/commit/b6c6a3d64f2e4e9347733290aca3c75898c44b2e.diff"; 152 hash = "sha256-RycJ3YCHd3MXtYFjxP0zY2Wuw7/C4bWoBAQtTKJZPOQ="; 153 }) 154 # libgo: check for makecontext in -lucontext 155 # See https://go-review.googlesource.com/c/gofrontend/+/458396 156 (fetchpatch { 157 excludes = [ "gcc/go/gofrontend/MERGE" ]; 158 url = "https://github.com/gcc-mirror/gcc/commit/2b1a604a9b28fbf4f382060bebd04adb83acc2f9.diff"; 159 hash = "sha256-WiBQG0Xbk75rHk+AMDvsbrm+dc7lDH0EONJXSdEeMGE="; 160 }) 161 # x86: Fix -fsplit-stack feature detection via TARGET_CAN_SPLIT_STACK 162 # Fixes compiling for non-glibc target 163 (fetchpatch { 164 url = "https://github.com/gcc-mirror/gcc/commit/c86b726c048eddc1be320c0bf64a897658bee13d.diff"; 165 hash = "sha256-QSIlqDB6JRQhbj/c3ejlmbfWz9l9FurdSWxpwDebnlI="; 166 }) 167] 168 169## Darwin 170 171# Fixes detection of Darwin on x86_64-darwin and aarch64-darwin. Otherwise, GCC uses a deployment target of 10.5, which crashes ld64. 172++ optional ( 173 # this one would conflict with gcc-14-darwin-aarch64-support.patch 174 is14 && stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isx86_64 175) ../patches/14/libgcc-darwin-detection.patch 176++ optional (atLeast15 && stdenv.hostPlatform.isDarwin) ../patches/15/libgcc-darwin-detection.patch 177 178# Fix libgcc_s.1.dylib build on Darwin 11+ by not reexporting unwind symbols that don't exist 179++ optional ( 180 atLeast15 && stdenv.hostPlatform.isDarwin 181) ../patches/15/libgcc-darwin-fix-reexport.patch 182 183# Fix detection of bootstrap compiler Ada support (cctools as) on Nix Darwin 184++ optional (stdenv.hostPlatform.isDarwin && langAda) ./ada-cctools-as-detection-configure.patch 185 186# Remove CoreServices on Darwin, as it is only needed for macOS SDK 14+ 187++ optional ( 188 atLeast14 && stdenv.hostPlatform.isDarwin && langAda 189) ../patches/14/gcc-darwin-remove-coreservices.patch 190 191# Use absolute path in GNAT dylib install names on Darwin 192++ optionals (stdenv.hostPlatform.isDarwin && langAda) ( 193 { 194 "15" = [ ../patches/14/gnat-darwin-dylib-install-name-14.patch ]; 195 "14" = [ ../patches/14/gnat-darwin-dylib-install-name-14.patch ]; 196 "13" = [ ./gnat-darwin-dylib-install-name-13.patch ]; 197 } 198 .${majorVersion} or [ ] 199) 200 201# Here we apply patches by Iains (https://github.com/iains) 202# GitHub's "compare" API produces unstable diffs, so we resort to reusing 203# diffs from the Homebrew repo. 204++ optionals canApplyIainsDarwinPatches ( 205 { 206 "15" = [ 207 # Patches from https://github.com/iains/gcc-15-branch/compare/releases/gcc-15..gcc-15.1-darwin-rc1 208 (fetchpatch { 209 name = "gcc-15-darwin-aarch64-support.patch"; 210 url = "https://raw.githubusercontent.com/Homebrew/formula-patches/a25079204c1cb3d78ba9dd7dd22b8aecce7ce264/gcc/gcc-15.1.0.diff"; 211 sha256 = "sha256-MJxSGv6LEP1sIM8cDqbmfUV7byV0bYgADeIBY/Teyu8="; 212 }) 213 ]; 214 "14" = [ 215 # Patches from https://github.com/iains/gcc-14-branch/compare/04696df09633baf97cdbbdd6e9929b9d472161d3..gcc-14.2-darwin-r2 216 (fetchpatch { 217 # There are no upstream release tags nor a static branch for 14.3.0 in https://github.com/iains/gcc-14-branch. 218 # aa4cd614456de65ee3417acb83c6cff0640144e9 is the merge base of https://github.com/iains/gcc-14-branch/tree/gcc-14-3-darwin-pre-0 and https://github.com/gcc-mirror/gcc/releases/tag/releases%2Fgcc-14.3.0 219 # 3e1d48d240f4aa5223c701b5c231c66f66ab1126 is the newest commit of https://github.com/iains/gcc-14-branch/tree/gcc-14-3-darwin-pre-0 220 name = "gcc-14-darwin-aarch64-support.patch"; 221 url = "https://github.com/iains/gcc-14-branch/compare/aa4cd614456de65ee3417acb83c6cff0640144e9..3e1d48d240f4aa5223c701b5c231c66f66ab1126.diff"; 222 hash = "sha256-BSTSYnkBJBEm++mGerVVyaCUC4dUyXq0N1tqbk25bO4="; 223 }) 224 ]; 225 # Patches from https://github.com/iains/gcc-13-branch/compare/b71f1de6e9cf7181a288c0f39f9b1ef6580cf5c8..gcc-13-3-darwin 226 "13" = [ 227 (fetchpatch { 228 name = "gcc-13-darwin-aarch64-support.patch"; 229 url = "https://raw.githubusercontent.com/Homebrew/formula-patches/698885df7f624d0ce15bceb79a4d9760a473b502/gcc/gcc-13.4.0.diff"; 230 hash = "sha256-xqkBDFYZ6fdowtqR3kV7bR8a4Cu11RDokSzGn1k3a1w="; 231 }) 232 ]; 233 } 234 .${majorVersion} or [ ] 235) 236 237++ optional (targetPlatform.isWindows || targetPlatform.isCygwin) (fetchpatch { 238 name = "libstdc-fix-compilation-in-freestanding-win32.patch"; 239 url = "https://inbox.sourceware.org/gcc-patches/20250922182808.2599390-2-corngood@gmail.com/raw"; 240 hash = "sha256-+EYW9lG8CviVX7RyNHp+iX+8BRHUjt5b07k940khbbY="; 241}) 242 243++ optionals targetPlatform.isCygwin [ 244 (fetchpatch { 245 name = "cygwin-fix-compilation-with-inhibit_libc.patch"; 246 url = "https://inbox.sourceware.org/gcc-patches/20250926170154.2222977-1-corngood@gmail.com/raw"; 247 hash = "sha256-mgzMRvgPdhj+Q2VRsFhpE2WQzg0CvWsc5/FRAsSU1Es="; 248 }) 249 (fetchpatch { 250 name = "cygwin-use-builtin_define_std-for-unix.patch"; 251 url = "https://inbox.sourceware.org/gcc-patches/20250922182808.2599390-3-corngood@gmail.com/raw"; 252 hash = "sha256-8I2G4430gkYoWgUued4unqhk8ZCajHf1dcivAeuLZ0E="; 253 }) 254]