nixpkgs mirror (for testing) github.com/NixOS/nixpkgs
nix
at python-updates 687 lines 28 kB view raw
1{ 2 version, 3 sha256, 4 url ? "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz", 5}: 6 7{ 8 lib, 9 stdenv, 10 pkgsBuildTarget, 11 pkgsHostTarget, 12 buildPackages, 13 targetPackages, 14 15 # build-tools 16 bootPkgs, 17 autoreconfHook, 18 coreutils, 19 fetchpatch, 20 fetchurl, 21 perl, 22 python3, 23 sphinx, 24 xattr, 25 autoSignDarwinBinariesHook, 26 bash, 27 28 libiconv ? null, 29 ncurses, 30 31 # GHC can be built with system libffi or a bundled one. 32 libffi ? null, 33 34 useLLVM ? !(import ./common-have-ncg.nix { inherit lib stdenv version; }), 35 36 # LLVM is conceptually a run-time-only dependency, but for 37 # non-x86, we need LLVM to bootstrap later stages, so it becomes a 38 # build-time dependency too. 39 buildTargetLlvmPackages, 40 llvmPackages, 41 42 # If enabled, GHC will be built with the GPL-free but slightly slower native 43 # bignum backend instead of the faster but GPLed gmp backend. 44 enableNativeBignum ? 45 !(lib.meta.availableOn stdenv.hostPlatform gmp && lib.meta.availableOn stdenv.targetPlatform gmp), 46 gmp, 47 48 # If enabled, use -fPIC when compiling static libs. 49 enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform, 50 51 # Exceeds Hydra output limit (at the time of writing ~3GB) when cross compiled to riscv64. 52 # A riscv64 cross-compiler fits into the limit comfortably. 53 enableProfiledLibs ? !stdenv.hostPlatform.isRiscV64, 54 55 # Whether to build dynamic libs for the standard library (on the target 56 # platform). Static libs are always built. 57 enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic, 58 59 # Whether to build terminfo. 60 enableTerminfo ? 61 !( 62 stdenv.targetPlatform.isWindows 63 # terminfo can't be built for cross 64 || (stdenv.buildPlatform != stdenv.hostPlatform) 65 || (stdenv.hostPlatform != stdenv.targetPlatform) 66 ), 67 68 # Enable NUMA support in RTS 69 enableNuma ? lib.meta.availableOn stdenv.targetPlatform numactl, 70 numactl, 71 72 # What flavour to build. An empty string indicates no 73 # specific flavour and falls back to ghc default values. 74 ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) ( 75 if useLLVM then "perf-cross" else "perf-cross-ncg" 76 ), 77 78 # Whether to build sphinx documentation. 79 enableDocs ? ( 80 # Docs disabled if we are building on musl because it's a large task to keep 81 # all `sphinx` dependencies building in this environment. 82 !stdenv.buildPlatform.isMusl 83 ), 84 85 enableHaddockProgram ? 86 # Disabled for cross; see note [HADDOCK_DOCS]. 87 (stdenv.buildPlatform == stdenv.hostPlatform && stdenv.targetPlatform == stdenv.hostPlatform), 88 89 # Whether to disable the large address space allocator 90 # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 91 disableLargeAddressSpace ? stdenv.targetPlatform.isiOS, 92 93 # Whether to build an unregisterised version of GHC. 94 # GHC will normally auto-detect whether it can do a registered build, but this 95 # option will force it to do an unregistered build when set to true. 96 # See https://gitlab.haskell.org/ghc/ghc/-/wikis/building/unregisterised 97 # Registerised RV64 compiler produces programs that segfault 98 # See https://gitlab.haskell.org/ghc/ghc/-/issues/23957 99 enableUnregisterised ? stdenv.hostPlatform.isRiscV64 || stdenv.targetPlatform.isRiscV64, 100}: 101 102assert !enableNativeBignum -> gmp != null; 103 104# Cross cannot currently build the `haddock` program for silly reasons, 105# see note [HADDOCK_DOCS]. 106assert 107 (stdenv.buildPlatform != stdenv.hostPlatform || stdenv.targetPlatform != stdenv.hostPlatform) 108 -> !enableHaddockProgram; 109 110# GHC does not support building when all 3 platforms are different. 111assert stdenv.buildPlatform == stdenv.hostPlatform || stdenv.hostPlatform == stdenv.targetPlatform; 112 113let 114 inherit (stdenv) buildPlatform hostPlatform targetPlatform; 115 116 # TODO(@Ericson2314) Make unconditional 117 targetPrefix = lib.optionalString (targetPlatform != hostPlatform) "${targetPlatform.config}-"; 118 119 buildMK = '' 120 BuildFlavour = ${ghcFlavour} 121 ifneq \"\$(BuildFlavour)\" \"\" 122 include mk/flavours/\$(BuildFlavour).mk 123 endif 124 BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} 125 BUILD_SPHINX_PDF = NO 126 127 WITH_TERMINFO = ${if enableTerminfo then "YES" else "NO"} 128 '' 129 + 130 # Note [HADDOCK_DOCS]: 131 # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` 132 # program is built (which we generally always want to have a complete GHC install) 133 # and whether it is run on the GHC sources to generate hyperlinked source code 134 # (which is impossible for cross-compilation); see: 135 # https://gitlab.haskell.org/ghc/ghc/-/issues/20077 krank:ignore-line 136 # This implies that currently a cross-compiled GHC will never have a `haddock` 137 # program, so it can never generate haddocks for any packages. 138 # If this is solved in the future, we'd like to unconditionally 139 # build the haddock program (removing the `enableHaddockProgram` option). 140 '' 141 HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"} 142 # Build haddocks for boot packages with hyperlinking 143 EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump 144 145 DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} 146 BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"} 147 '' 148 + lib.optionalString (targetPlatform != hostPlatform) '' 149 Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"} 150 CrossCompilePrefix = ${targetPrefix} 151 '' 152 + lib.optionalString (!enableProfiledLibs) '' 153 BUILD_PROF_LIBS = NO 154 '' 155 + 156 # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) 157 # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. 158 # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell 159 lib.optionalString enableRelocatedStaticLibs '' 160 GhcLibHcOpts += -fPIC -fexternal-dynamic-refs 161 GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs 162 '' 163 + lib.optionalString targetPlatform.useAndroidPrebuilt '' 164 EXTRA_CC_OPTS += -std=gnu99 165 ''; 166 167 # Splicer will pull out correct variations 168 libDeps = 169 platform: 170 lib.optional enableTerminfo ncurses 171 ++ [ libffi ] 172 ++ lib.optional (!enableNativeBignum) gmp 173 ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; 174 175 # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 176 # GHC doesn't seem to have {LLC,OPT}_HOST 177 toolsForTarget = [ 178 pkgsBuildTarget.targetPackages.stdenv.cc 179 ] 180 ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 181 182 buildCC = buildPackages.stdenv.cc; 183 targetCC = builtins.head toolsForTarget; 184 installCC = pkgsHostTarget.targetPackages.stdenv.cc; 185 186 # toolPath calculates the absolute path to the name tool associated with a 187 # given `stdenv.cc` derivation, i.e. it picks the correct derivation to take 188 # the tool from (cc, cc.bintools, cc.bintools.bintools) and adds the correct 189 # subpath of the tool. 190 toolPath = 191 name: cc: 192 let 193 tools = 194 { 195 "cc" = cc; 196 "c++" = cc; 197 as = cc.bintools; 198 199 ar = cc.bintools; 200 ranlib = cc.bintools; 201 nm = cc.bintools; 202 readelf = cc.bintools; 203 objdump = cc.bintools; 204 205 ld = cc.bintools; 206 "ld.gold" = cc.bintools; 207 208 otool = cc.bintools.bintools; 209 210 # GHC needs install_name_tool on all darwin platforms. The same one can 211 # be used on both platforms. It is safe to use with linker-generated 212 # signatures because it will update the signatures automatically after 213 # modifying the target binary. 214 install_name_tool = cc.bintools.bintools; 215 216 # strip on darwin is wrapped to enable deterministic mode. 217 strip = 218 # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 219 if stdenv.targetPlatform.isDarwin then cc.bintools else cc.bintools.bintools; 220 221 # clang is used as an assembler on darwin with the LLVM backend 222 clang = cc; 223 } 224 .${name}; 225 in 226 getToolExe tools name; 227 228 # targetPrefix aware lib.getExe' 229 getToolExe = drv: name: lib.getExe' drv "${drv.targetPrefix or ""}${name}"; 230 231 # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 232 # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 233 # see #84670 and #49071 for more background. 234 useLdGold = 235 targetPlatform.linker == "gold" 236 || ( 237 targetPlatform.linker == "bfd" 238 && (targetCC.bintools.bintools.hasGold or false) 239 && !targetPlatform.isMusl 240 ); 241 242 # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 243 variantSuffix = lib.concatStrings [ 244 (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 245 (lib.optionalString enableNativeBignum "-native-bignum") 246 ]; 247 248 # These libraries are library dependencies of the standard libraries bundled 249 # by GHC (core libs) users will link their compiled artifacts again. Thus, 250 # they should be taken from targetPackages. 251 # 252 # We need to use pkgsHostTarget if we are cross compiling a native GHC compiler, 253 # though (when native compiling GHC, pkgsHostTarget == targetPackages): 254 # 255 # 1. targetPackages would be empty(-ish) in this situation since we can't 256 # execute cross compiled compilers in order to obtain the libraries 257 # that would be in targetPackages. 258 # 2. pkgsHostTarget is fine to use since hostPlatform == targetPlatform in this 259 # situation. 260 # 3. The core libs used by the final GHC (stage 2) for user artifacts are also 261 # used to build stage 2 GHC itself, i.e. the core libs are both host and 262 # target. 263 targetLibs = { 264 inherit (if hostPlatform != targetPlatform then targetPackages else pkgsHostTarget) 265 gmp 266 libffi 267 ncurses 268 numactl 269 ; 270 }; 271 272in 273 274stdenv.mkDerivation ( 275 rec { 276 pname = "${targetPrefix}ghc${variantSuffix}"; 277 inherit version; 278 279 src = fetchurl { 280 inherit url sha256; 281 }; 282 283 enableParallelBuilding = true; 284 285 outputs = [ 286 "out" 287 "doc" 288 ]; 289 290 patches = [ 291 # Determine size of time related types using hsc2hs instead of assuming CLong. 292 # Prevents failures when e.g. stat(2)ing on 32bit systems with 64bit time_t etc. 293 # https://github.com/haskell/ghcup-hs/issues/1107 krank:ignore-line 294 # https://gitlab.haskell.org/ghc/ghc/-/issues/25095 krank:ignore-line 295 # Note that in normal situations this shouldn't be the case since nixpkgs 296 # doesn't set -D_FILE_OFFSET_BITS=64 and friends (yet). 297 (fetchpatch { 298 name = "unix-fix-ctimeval-size-32-bit.patch"; 299 url = "https://github.com/haskell/unix/commit/8183e05b97ce870dd6582a3677cc82459ae566ec.patch"; 300 sha256 = "17q5yyigqr5kxlwwzb95sx567ysfxlw6bp3j4ji20lz0947aw6gv"; 301 stripLen = 1; 302 extraPrefix = "libraries/unix/"; 303 }) 304 305 # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 krank:ignore-line 306 ./docs-sphinx-7.patch 307 308 # Fix docs build with Sphinx >= 9 https://gitlab.haskell.org/ghc/ghc/-/issues/26810 309 ./ghc-9.4-docs-sphinx-9.patch 310 311 # Correctly record libnuma's library and include directories in the 312 # package db. This fixes linking whenever stdenv and propagation won't 313 # quite pass the correct -L flags to the linker, e.g. when using GHC 314 # outside of stdenv/nixpkgs or build->build compilation in pkgsStatic. 315 ./ghc-9.4-rts-package-db-libnuma-dirs.patch 316 ] 317 318 # Before GHC 9.6, GHC, when used to compile C sources (i.e. to drive the CC), would first 319 # invoke the C compiler to generate assembly and later call the assembler on the result of 320 # that operation. Unfortunately, that is brittle in a lot of cases, e.g. when using mismatched 321 # CC / assembler (https://gitlab.haskell.org/ghc/ghc/-/merge_requests/12005). This issue 322 # does not affect us. However, LLVM 18 introduced a check in clang that makes sure no 323 # non private labels occur between .cfi_startproc and .cfi_endproc which causes the 324 # assembly that the same version (!) of clang generates from rts/StgCRun.c to be rejected. 325 # This causes GHC to fail compilation on mach-o platforms ever since we upgraded to 326 # LLVM 19. 327 # 328 # clang compiles the same file without issues whithout the roundtrip via assembly. Thus, 329 # the solution is to backport those changes from GHC 9.6 that skip the intermediate 330 # assembly step. 331 # 332 # https://gitlab.haskell.org/ghc/ghc/-/issues/25608#note_622589 krank:ignore-line 333 # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6877 334 ++ [ 335 # Need to use this patch so the next one applies, passes file location info to the cc phase 336 (fetchpatch { 337 name = "ghc-add-location-to-cc-phase.patch"; 338 url = "https://gitlab.haskell.org/ghc/ghc/-/commit/4a7256a75af2fc0318bef771a06949ffb3939d5a.patch"; 339 hash = "sha256-DnTI+i1zMebeWvw75D59vMaEEBb2Nr9HusxTyhmdy2M="; 340 }) 341 # Makes Cc phase directly generate object files instead of assembly 342 (fetchpatch { 343 name = "ghc-cc-directly-emit-object.patch"; 344 url = "https://gitlab.haskell.org/ghc/ghc/-/commit/96811ba491495b601ec7d6a32bef8563b0292109.patch"; 345 hash = "sha256-G8u7/MK/tGOEN8Wxccxj/YIOP7mL2G9Co1WKdHXOo6I="; 346 }) 347 ] 348 349 # Fix build with gcc15 350 # https://gitlab.haskell.org/ghc/ghc/-/issues/25662 351 # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13863 352 ++ lib.optionals (lib.versions.majorMinor version == "9.4") [ 353 (fetchpatch { 354 name = "ghc-hp2ps-c-gnu17.patch"; 355 url = "https://src.fedoraproject.org/rpms/ghc/raw/9c26d7c3c3de73509a25806e5663b37bcf2e0b4e/f/hp2ps-C-gnu17.patch"; 356 hash = "sha256-Vr5wkiSE1S5e+cJ8pWUvG9KFpxtmvQ8wAy08ElGNp5E="; 357 }) 358 ] 359 360 ++ [ 361 # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs 362 # Can be removed if the Cabal library included with ghc backports the linked fix 363 (fetchpatch { 364 url = "https://github.com/haskell/cabal/commit/6c796218c92f93c95e94d5ec2d077f6956f68e98.patch"; 365 stripLen = 1; 366 extraPrefix = "libraries/Cabal/"; 367 sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY="; 368 }) 369 ] 370 371 # Fixes stack overrun in rts which crashes an process whenever 372 # freeHaskellFunPtr is called with nixpkgs' hardening flags. 373 # https://gitlab.haskell.org/ghc/ghc/-/issues/25485 krank:ignore-line 374 # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/13599 375 # TODO: patch doesn't apply for < 9.4, but may still be necessary? 376 ++ [ 377 (fetchpatch { 378 name = "ghc-rts-adjustor-fix-i386-stack-overrun.patch"; 379 url = "https://gitlab.haskell.org/ghc/ghc/-/commit/39bb6e583d64738db51441a556d499aa93a4fc4a.patch"; 380 sha256 = "0w5fx413z924bi2irsy1l4xapxxhrq158b5gn6jzrbsmhvmpirs0"; 381 }) 382 ] 383 384 ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 385 # Prevent the paths module from emitting symbols that we don't use 386 # when building with separate outputs. 387 # 388 # These cause problems as they're not eliminated by GHC's dead code 389 # elimination on aarch64-darwin. (see 390 # https://github.com/NixOS/nixpkgs/issues/140774 for details). krank:ignore-line 391 ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch 392 ] 393 394 ++ (import ./common-llvm-patches.nix { inherit lib version fetchpatch; }); 395 396 postPatch = "patchShebangs ."; 397 398 # GHC is a bit confused on its cross terminology. 399 # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 400 preConfigure = '' 401 for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 402 export "''${env#TARGET_}=''${!env}" 403 done 404 # Stage0 (build->build) which builds stage 1 405 export GHC="${bootPkgs.ghc}/bin/ghc" 406 # GHC is a bit confused on its cross terminology, as these would normally be 407 # the *host* tools. 408 export CC="${toolPath "cc" targetCC}" 409 export CXX="${toolPath "c++" targetCC}" 410 # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 411 export LD="${toolPath "ld${lib.optionalString useLdGold ".gold"}" targetCC}" 412 export AS="${toolPath "as" targetCC}" 413 export AR="${toolPath "ar" targetCC}" 414 export NM="${toolPath "nm" targetCC}" 415 export RANLIB="${toolPath "ranlib" targetCC}" 416 export READELF="${toolPath "readelf" targetCC}" 417 export STRIP="${toolPath "strip" targetCC}" 418 export OBJDUMP="${toolPath "objdump" targetCC}" 419 '' 420 + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 421 export OTOOL="${toolPath "otool" targetCC}" 422 export INSTALL_NAME_TOOL="${toolPath "install_name_tool" targetCC}" 423 '' 424 + lib.optionalString useLLVM '' 425 export LLC="${getToolExe buildTargetLlvmPackages.llvm "llc"}" 426 export OPT="${getToolExe buildTargetLlvmPackages.llvm "opt"}" 427 '' 428 + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 429 # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 430 # The executable we specify via $CLANG is used as an assembler (exclusively, it seems, but this isn't 431 # clarified in any user facing documentation). As such, it'll be called on assembly produced by $CC 432 # which usually comes from the darwin stdenv. To prevent a situation where $CLANG doesn't understand 433 # the assembly it is given, we need to make sure that it matches the LLVM version of $CC if possible. 434 # It is unclear (at the time of writing 2024-09-01) whether $CC should match the LLVM version we use 435 # for llc and opt which would require using a custom darwin stdenv for targetCC. 436 export CLANG="${ 437 if targetCC.isClang then 438 toolPath "clang" targetCC 439 else 440 getToolExe buildTargetLlvmPackages.clang "clang" 441 }" 442 '' 443 + '' 444 # No need for absolute paths since these tools only need to work during the build 445 export CC_STAGE0="$CC_FOR_BUILD" 446 export LD_STAGE0="$LD_FOR_BUILD" 447 export AR_STAGE0="$AR_FOR_BUILD" 448 449 echo -n "${buildMK}" > mk/build.mk 450 '' 451 # Haddock and sphinx need a working locale 452 + lib.optionalString (enableDocs || enableHaddockProgram) ( 453 '' 454 export LANG="en_US.UTF-8" 455 '' 456 + lib.optionalString (stdenv.buildPlatform.libc == "glibc") '' 457 export LOCALE_ARCHIVE="${buildPackages.glibcLocales}/lib/locale/locale-archive" 458 '' 459 ) 460 + lib.optionalString (!stdenv.hostPlatform.isDarwin) '' 461 export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 462 '' 463 + lib.optionalString stdenv.hostPlatform.isDarwin '' 464 export NIX_LDFLAGS+=" -no_dtrace_dof" 465 '' 466 + lib.optionalString (stdenv.hostPlatform.isDarwin) '' 467 468 # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 469 export XATTR=${lib.getBin xattr}/bin/xattr 470 '' 471 + lib.optionalString targetPlatform.useAndroidPrebuilt '' 472 sed -i -e '5i ,("armv7a-unknown-linux-androideabi", ("e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", "cortex-a8", ""))' llvm-targets 473 '' 474 + lib.optionalString targetPlatform.isMusl '' 475 echo "patching llvm-targets for musl targets..." 476 echo "Cloning these existing '*-linux-gnu*' targets:" 477 grep linux-gnu llvm-targets | sed 's/^/ /' 478 echo "(go go gadget sed)" 479 sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 480 echo "llvm-targets now contains these '*-linux-musl*' targets:" 481 grep linux-musl llvm-targets | sed 's/^/ /' 482 483 echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 484 for x in aclocal.m4; do 485 substituteInPlace $x \ 486 --replace '*-android*|*-gnueabi*)' \ 487 '*-android*|*-gnueabi*|*-musleabi*)' 488 done 489 ''; 490 491 # Although it is usually correct to pass --host, we don't do that here because 492 # GHC's usage of build, host, and target is non-standard. 493 # See https://gitlab.haskell.org/ghc/ghc/-/wikis/building/cross-compiling 494 # TODO(@Ericson2314): Always pass "--target" and always prefix. 495 configurePlatforms = [ 496 "build" 497 ] 498 ++ lib.optional (buildPlatform != hostPlatform || targetPlatform != hostPlatform) "target"; 499 500 # `--with` flags for libraries needed for RTS linker 501 configureFlags = [ 502 "--datadir=$doc/share/doc/ghc" 503 ] 504 ++ lib.optionals enableTerminfo [ 505 "--with-curses-includes=${lib.getDev targetLibs.ncurses}/include" 506 "--with-curses-libraries=${lib.getLib targetLibs.ncurses}/lib" 507 ] 508 ++ lib.optionals (libffi != null) [ 509 "--with-system-libffi" 510 "--with-ffi-includes=${targetLibs.libffi.dev}/include" 511 "--with-ffi-libraries=${targetLibs.libffi.out}/lib" 512 ] 513 ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 514 "--with-gmp-includes=${targetLibs.gmp.dev}/include" 515 "--with-gmp-libraries=${targetLibs.gmp.out}/lib" 516 ] 517 ++ 518 lib.optionals 519 (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) 520 [ 521 "--with-iconv-includes=${libiconv}/include" 522 "--with-iconv-libraries=${libiconv}/lib" 523 ] 524 ++ lib.optionals (targetPlatform != hostPlatform) [ 525 "--enable-bootstrap-with-devel-snapshot" 526 ] 527 ++ lib.optionals useLdGold [ 528 "CFLAGS=-fuse-ld=gold" 529 "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 530 "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 531 ] 532 ++ lib.optionals disableLargeAddressSpace [ 533 "--disable-large-address-space" 534 ] 535 ++ lib.optionals enableNuma [ 536 "--enable-numa" 537 "--with-libnuma-includes=${lib.getDev targetLibs.numactl}/include" 538 "--with-libnuma-libraries=${lib.getLib targetLibs.numactl}/lib" 539 ] 540 ++ lib.optionals enableUnregisterised [ 541 "--enable-unregisterised" 542 ]; 543 544 # Make sure we never relax`$PATH` and hooks support for compatibility. 545 strictDeps = true; 546 547 # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 548 dontAddExtraLibs = true; 549 550 nativeBuildInputs = [ 551 autoreconfHook 552 perl 553 python3 554 bootPkgs.alex 555 bootPkgs.happy 556 bootPkgs.hscolour 557 bootPkgs.ghc-settings-edit 558 ] 559 ++ lib.optionals (stdenv.hostPlatform.isDarwin && stdenv.hostPlatform.isAarch64) [ 560 autoSignDarwinBinariesHook 561 ] 562 ++ lib.optionals enableDocs [ 563 sphinx 564 ]; 565 566 # Everything the stage0 compiler needs to build stage1: CC, bintools, extra libs. 567 # See also GHC, {CC,LD,AR}_STAGE0 in preConfigure. 568 depsBuildBuild = [ 569 # N.B. We do not declare bootPkgs.ghc in any of the stdenv.mkDerivation 570 # dependency lists to prevent the bintools setup hook from adding ghc's 571 # lib directory to the linker flags. Instead we tell configure about it 572 # via the GHC environment variable. 573 buildCC 574 # stage0 builds terminfo unconditionally, so we always need ncurses 575 ncurses 576 ]; 577 # For building runtime libs 578 depsBuildTarget = toolsForTarget; 579 580 # Prevent stage0 ghc from leaking into the final result. This was an issue 581 # with GHC 9.6. 582 disallowedReferences = [ 583 bootPkgs.ghc 584 ]; 585 586 buildInputs = [ bash ] ++ (libDeps hostPlatform); 587 588 # stage1 GHC doesn't need to link against libnuma, so it's target specific 589 depsTargetTarget = map lib.getDev ( 590 libDeps targetPlatform ++ lib.optionals enableNuma [ targetLibs.numactl ] 591 ); 592 depsTargetTargetPropagated = map (lib.getOutput "out") ( 593 libDeps targetPlatform ++ lib.optionals enableNuma [ targetLibs.numactl ] 594 ); 595 596 # required, because otherwise all symbols from HSffi.o are stripped, and 597 # that in turn causes GHCi to abort 598 stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 599 600 checkTarget = "test"; 601 602 hardeningDisable = [ 603 "format" 604 ]; 605 606 # big-parallel allows us to build with more than 2 cores on 607 # Hydra which already warrants a significant speedup 608 requiredSystemFeatures = [ "big-parallel" ]; 609 610 # Install occasionally fails due to a race condition in minimal builds. 611 # > /nix/store/wyzpysxwgs3qpvmylm9krmfzh2plicix-coreutils-9.7/bin/install -c -m 755 -d "/nix/store/xzb3390rhvhg2a0cvzmrvjspw1d8nf8h-ghc-riscv64-unknown-linux-gnu-9.4.8/bin" 612 # > install: cannot create regular file '/nix/store/xzb3390rhvhg2a0cvzmrvjspw1d8nf8h-ghc-riscv64-unknown-linux-gnu-9.4.8/lib/ghc-9.4.8': No such file or directory 613 preInstall = '' 614 mkdir -p "$out/lib/${passthru.haskellCompilerName}" 615 ''; 616 617 postInstall = '' 618 settingsFile="$out/lib/${targetPrefix}${passthru.haskellCompilerName}/settings" 619 620 # Make the installed GHC use the host->target tools. 621 ghc-settings-edit "$settingsFile" \ 622 "C compiler command" "${toolPath "cc" installCC}" \ 623 "Haskell CPP command" "${toolPath "cc" installCC}" \ 624 "C++ compiler command" "${toolPath "c++" installCC}" \ 625 "ld command" "${toolPath "ld${lib.optionalString useLdGold ".gold"}" installCC}" \ 626 "Merge objects command" "${toolPath "ld${lib.optionalString useLdGold ".gold"}" installCC}" \ 627 "ar command" "${toolPath "ar" installCC}" \ 628 "ranlib command" "${toolPath "ranlib" installCC}" 629 '' 630 + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 631 ghc-settings-edit "$settingsFile" \ 632 "otool command" "${toolPath "otool" installCC}" \ 633 "install_name_tool command" "${toolPath "install_name_tool" installCC}" 634 '' 635 + lib.optionalString useLLVM '' 636 ghc-settings-edit "$settingsFile" \ 637 "LLVM llc command" "${getToolExe llvmPackages.llvm "llc"}" \ 638 "LLVM opt command" "${getToolExe llvmPackages.llvm "opt"}" 639 '' 640 + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 641 ghc-settings-edit "$settingsFile" \ 642 "LLVM clang command" "${ 643 # See comment for CLANG in preConfigure 644 if installCC.isClang then toolPath "clang" installCC else getToolExe llvmPackages.clang "clang" 645 }" 646 '' 647 + '' 648 649 # Install the bash completion file. 650 install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 651 ''; 652 653 passthru = { 654 inherit bootPkgs targetPrefix; 655 656 inherit llvmPackages; 657 inherit enableShared; 658 659 # This is used by the haskell builder to query 660 # the presence of the haddock program. 661 hasHaddock = enableHaddockProgram; 662 663 # Our Cabal compiler name 664 haskellCompilerName = "ghc-${version}"; 665 666 bootstrapAvailable = lib.meta.availableOn stdenv.buildPlatform bootPkgs.ghc; 667 }; 668 669 meta = { 670 homepage = "http://haskell.org/ghc"; 671 description = "Glasgow Haskell Compiler"; 672 maintainers = with lib.maintainers; [ 673 guibou 674 ]; 675 teams = [ lib.teams.haskell ]; 676 timeout = 24 * 3600; 677 platforms = lib.platforms.all; 678 inherit (bootPkgs.ghc.meta) license; 679 }; 680 681 } 682 // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { 683 dontStrip = true; 684 dontPatchELF = true; 685 noAuditTmpdir = true; 686 } 687)