haskell.compiler.ghcHEAD: 9.3.20220406 -> 9.5.20220921

Initial port of our GHC Nix expressions to the new hadrian build system,
as it has become required after 9.4. Unfortunately there are some
regressions affecting us, namely the inability to install a GHC
cross-compiler at the moment (see issue linked in relevant error
message). This means that a lot of specific configuration snippets for
cross-platforms and static compilation have been ported from make
speculatively, as we are unable to test them for the moment.

+545 -382
+2 -3
pkgs/development/compilers/ghc/9.4.2.nix
··· 1 - # Preliminary GHC 9.4.2 expression using the make build system. 2 - # TODO(@sternenseemann): port to hadrian, so we are prepared for 9.6 3 - # where make support will be dropped. 1 + # DO NOT port this expression to hadrian. It is not possible to build a GHC 2 + # cross compiler with 9.4.* and hadrian. 4 3 { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 5 4 6 5 # build-tools
+491
pkgs/development/compilers/ghc/common-hadrian.nix
··· 1 + { version 2 + , rev ? null 3 + , sha256 4 + , url ? 5 + if rev != null 6 + then "https://gitlab.haskell.org/ghc/ghc.git" 7 + else "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz" 8 + 9 + }: 10 + 11 + { lib 12 + , stdenv 13 + , pkgsBuildTarget 14 + , pkgsHostTarget 15 + , targetPackages 16 + 17 + # build-tools 18 + , bootPkgs 19 + , autoconf 20 + , automake 21 + , coreutils 22 + , fetchpatch 23 + , fetchurl 24 + , fetchgit 25 + , perl 26 + , python3 27 + , m4 28 + , sphinx 29 + , xattr 30 + , autoSignDarwinBinariesHook 31 + , bash 32 + 33 + , libiconv ? null, ncurses 34 + , glibcLocales ? null 35 + 36 + , # GHC can be built with system libffi or a bundled one. 37 + libffi ? null 38 + 39 + , useLLVM ? !(stdenv.targetPlatform.isx86 40 + || stdenv.targetPlatform.isPower 41 + || stdenv.targetPlatform.isSparc 42 + || (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin)) 43 + , # LLVM is conceptually a run-time-only depedendency, but for 44 + # non-x86, we need LLVM to bootstrap later stages, so it becomes a 45 + # build-time dependency too. 46 + buildTargetLlvmPackages 47 + , llvmPackages 48 + 49 + , # If enabled, GHC will be built with the GPL-free but slightly slower native 50 + # bignum backend instead of the faster but GPLed gmp backend. 51 + enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp) 52 + , gmp 53 + 54 + , # If enabled, use -fPIC when compiling static libs. 55 + enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform 56 + 57 + # aarch64 outputs otherwise exceed 2GB limit 58 + , enableProfiledLibs ? !stdenv.targetPlatform.isAarch64 59 + 60 + , # Whether to build dynamic libs for the standard library (on the target 61 + # platform). Static libs are always built. 62 + enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic 63 + 64 + , # Whether to build terminfo. 65 + enableTerminfo ? !stdenv.targetPlatform.isWindows 66 + 67 + , # Libdw.c only supports x86_64, i686 and s390x as of 2022-08-04 68 + enableDwarf ? (stdenv.targetPlatform.isx86 || 69 + (stdenv.targetPlatform.isS390 && stdenv.targetPlatform.is64bit)) && 70 + lib.meta.availableOn stdenv.hostPlatform elfutils && 71 + lib.meta.availableOn stdenv.targetPlatform elfutils && 72 + # HACK: elfutils is marked as broken on static platforms 73 + # which availableOn can't tell. 74 + !stdenv.targetPlatform.isStatic && 75 + !stdenv.hostPlatform.isStatic 76 + , elfutils 77 + 78 + , # What flavour to build. Flavour string may contain a flavour and flavour 79 + # transformers as accepted by hadrian. 80 + ghcFlavour ? 81 + let 82 + # TODO(@sternenseemann): does using the static flavour make sense? 83 + baseFlavour = "release"; 84 + # Note: in case hadrian's flavour transformers cease being expressive 85 + # enough for us, we'll need to resort to defining a "nixpkgs" flavour 86 + # in hadrianUserSettings and using that instead. 87 + transformers = 88 + lib.optionals useLLVM [ "llvm" ] 89 + ++ lib.optionals (!enableShared) [ 90 + "fully_static" 91 + "no_dynamic_ghc" 92 + ] 93 + ++ lib.optionals (!enableProfiledLibs) [ "no_profiled_libs" ] 94 + # While split sections are now enabled by default in ghc 8.8 for windows, 95 + # they seem to lead to `too many sections` errors when building base for 96 + # profiling. 97 + ++ lib.optionals (!stdenv.targetPlatform.isWindows) [ "split_sections" ] 98 + ; 99 + in 100 + baseFlavour + lib.concatMapStrings (t: "+${t}") transformers 101 + 102 + , # Contents of the UserSettings.hs file to use when compiling hadrian. 103 + hadrianUserSettings ? '' 104 + module UserSettings ( 105 + userFlavours, userPackages, userDefaultFlavour, 106 + verboseCommand, buildProgressColour, successColour, finalStage 107 + ) where 108 + 109 + import Flavour.Type 110 + import Expression 111 + import {-# SOURCE #-} Settings.Default 112 + 113 + -- no way to set this via the command line 114 + finalStage :: Stage 115 + finalStage = ${ 116 + if stdenv.hostPlatform == stdenv.targetPlatform 117 + then "Stage2" # native compiler 118 + else "Stage1" # cross compiler 119 + } 120 + 121 + userDefaultFlavour :: String 122 + userDefaultFlavour = "release" 123 + 124 + userFlavours :: [Flavour] 125 + userFlavours = [] 126 + 127 + -- Disable Colours 128 + buildProgressColour :: BuildProgressColour 129 + buildProgressColour = mkBuildProgressColour (Dull Reset) 130 + successColour :: SuccessColour 131 + successColour = mkSuccessColour (Dull Reset) 132 + 133 + -- taken from src/UserSettings.hs unchanged, need to be there 134 + userPackages :: [Package] 135 + userPackages = [] 136 + verboseCommand :: Predicate 137 + verboseCommand = do 138 + verbosity <- expr getVerbosity 139 + return $ verbosity >= Verbose 140 + '' 141 + 142 + , # Whether to build sphinx documentation. 143 + enableDocs ? ( 144 + # Docs disabled for musl and cross because it's a large task to keep 145 + # all `sphinx` dependencies building in those environments. 146 + # `sphinx` pulls in among others: 147 + # Ruby, Python, Perl, Rust, OpenGL, Xorg, gtk, LLVM. 148 + (stdenv.targetPlatform == stdenv.hostPlatform) 149 + && !stdenv.hostPlatform.isMusl 150 + ) 151 + 152 + , # Whether to disable the large address space allocator 153 + # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 154 + disableLargeAddressSpace ? stdenv.targetPlatform.isiOS 155 + }: 156 + 157 + assert !enableNativeBignum -> gmp != null; 158 + 159 + assert stdenv.hostPlatform == stdenv.targetPlatform || throw '' 160 + hadrian doesn't support building an installable GHC cross-compiler at the moment. 161 + Consider using GHC 9.4.2 or lower which support this via the make build system. 162 + See also: https://gitlab.haskell.org/ghc/ghc/-/issues/22090 163 + ''; 164 + 165 + let 166 + src = (if rev != null then fetchgit else fetchurl) ({ 167 + inherit url sha256; 168 + } // lib.optionalAttrs (rev != null) { 169 + inherit rev; 170 + }); 171 + 172 + inherit (stdenv) buildPlatform hostPlatform targetPlatform; 173 + 174 + inherit (bootPkgs) ghc; 175 + 176 + # TODO(@Ericson2314) Make unconditional 177 + targetPrefix = lib.optionalString 178 + (targetPlatform != hostPlatform) 179 + "${targetPlatform.config}-"; 180 + 181 + hadrianSettings = 182 + # -fexternal-dynamic-refs apparently (because it's not clear from the 183 + # documentation) makes the GHC RTS able to load static libraries, which may 184 + # be needed for TemplateHaskell. This solution was described in 185 + # https://www.tweag.io/blog/2020-09-30-bazel-static-haskell 186 + lib.optionals enableRelocatedStaticLibs [ 187 + "*.*.rts.*.opts += -fPIC -fexternal-dynamic-refs" 188 + "*.*.ghc.*.opts += -fPIC -fexternal-dynamic-refs" 189 + ] 190 + ++ lib.optionals targetPlatform.useAndroidPrebuilt [ 191 + "*.*.ghc.c.opts += -optc-std=gnu99" 192 + ]; 193 + 194 + # GHC's build system hadrian built from the GHC-to-build's source tree 195 + # using our bootstrap GHC. 196 + hadrian = bootPkgs.callPackage ../../tools/haskell/hadrian { 197 + ghcSrc = src; 198 + ghcVersion = version; 199 + userSettings = hadrianUserSettings; 200 + }; 201 + 202 + # Splicer will pull out correct variations 203 + libDeps = platform: lib.optional enableTerminfo ncurses 204 + ++ [libffi] 205 + # Bindist configure script fails w/o elfutils in linker search path 206 + # https://gitlab.haskell.org/ghc/ghc/-/issues/22081 207 + ++ lib.optional enableDwarf elfutils 208 + ++ lib.optional (!enableNativeBignum) gmp 209 + ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; 210 + 211 + # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 212 + # GHC doesn't seem to have {LLC,OPT}_HOST 213 + toolsForTarget = [ 214 + pkgsBuildTarget.targetPackages.stdenv.cc 215 + ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 216 + 217 + targetCC = builtins.head toolsForTarget; 218 + 219 + # Sometimes we have to dispatch between the bintools wrapper and the unwrapped 220 + # derivation for certain tools depending on the platform. 221 + bintoolsFor = { 222 + # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is 223 + # part of the bintools wrapper (due to codesigning requirements), but not on 224 + # x86_64-darwin. 225 + install_name_tool = 226 + if stdenv.targetPlatform.isAarch64 227 + then targetCC.bintools 228 + else targetCC.bintools.bintools; 229 + # Same goes for strip. 230 + strip = 231 + # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 232 + if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin 233 + then targetCC.bintools 234 + else targetCC.bintools.bintools; 235 + }; 236 + 237 + # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 238 + # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 239 + # see #84670 and #49071 for more background. 240 + useLdGold = targetPlatform.linker == "gold" || 241 + (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); 242 + 243 + # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 244 + variantSuffix = lib.concatStrings [ 245 + (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 246 + (lib.optionalString enableNativeBignum "-native-bignum") 247 + ]; 248 + 249 + in 250 + 251 + # C compiler, bintools and LLVM are used at build time, but will also leak into 252 + # the resulting GHC's settings file and used at runtime. This means that we are 253 + # currently only able to build GHC if hostPlatform == buildPlatform. 254 + assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; 255 + assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; 256 + assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 257 + 258 + stdenv.mkDerivation ({ 259 + pname = "${targetPrefix}ghc${variantSuffix}"; 260 + inherit version; 261 + 262 + inherit src; 263 + 264 + enableParallelBuilding = true; 265 + 266 + postPatch = '' 267 + patchShebangs --build . 268 + ''; 269 + 270 + # GHC needs the locale configured during the Haddock phase. 271 + LANG = "en_US.UTF-8"; 272 + 273 + # GHC is a bit confused on its cross terminology. 274 + # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 275 + preConfigure = '' 276 + for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 277 + export "''${env#TARGET_}=''${!env}" 278 + done 279 + # GHC is a bit confused on its cross terminology, as these would normally be 280 + # the *host* tools. 281 + export CC="${targetCC}/bin/${targetCC.targetPrefix}cc" 282 + export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++" 283 + # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 284 + export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}" 285 + export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as" 286 + export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar" 287 + export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" 288 + export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" 289 + export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" 290 + export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" 291 + '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 292 + export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" 293 + export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" 294 + '' + lib.optionalString useLLVM '' 295 + export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" 296 + export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" 297 + '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 298 + # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 299 + export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 300 + '' + 301 + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' 302 + export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" 303 + '' + lib.optionalString (!stdenv.isDarwin) '' 304 + export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 305 + '' + lib.optionalString stdenv.isDarwin '' 306 + export NIX_LDFLAGS+=" -no_dtrace_dof" 307 + 308 + # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 309 + export XATTR=${lib.getBin xattr}/bin/xattr 310 + '' 311 + # If we are not using release tarballs, some files need to be generated using 312 + # the boot script. 313 + + lib.optionalString (rev != null) '' 314 + echo ${version} > VERSION 315 + echo ${rev} > GIT_COMMIT_ID 316 + ./boot 317 + '' 318 + + lib.optionalString targetPlatform.useAndroidPrebuilt '' 319 + 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 320 + '' + lib.optionalString targetPlatform.isMusl '' 321 + echo "patching llvm-targets for musl targets..." 322 + echo "Cloning these existing '*-linux-gnu*' targets:" 323 + grep linux-gnu llvm-targets | sed 's/^/ /' 324 + echo "(go go gadget sed)" 325 + sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 326 + echo "llvm-targets now contains these '*-linux-musl*' targets:" 327 + grep linux-musl llvm-targets | sed 's/^/ /' 328 + 329 + echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 330 + # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen) 331 + for x in configure aclocal.m4; do 332 + substituteInPlace $x \ 333 + --replace '*-android*|*-gnueabi*)' \ 334 + '*-android*|*-gnueabi*|*-musleabi*)' 335 + done 336 + '' 337 + # Create bash array hadrianFlagsArray for use in buildPhase. Do it in 338 + # preConfigure, so overrideAttrs can be used to modify it effectively. 339 + # hadrianSettings are passed via the command line so they are more visible 340 + # in the build log. 341 + + '' 342 + hadrianFlagsArray=( 343 + "-j$NIX_BUILD_CORES" 344 + ${lib.escapeShellArgs hadrianSettings} 345 + ) 346 + ''; 347 + 348 + # TODO(@Ericson2314): Always pass "--target" and always prefix. 349 + configurePlatforms = [ "build" "host" ] 350 + ++ lib.optional (targetPlatform != hostPlatform) "target"; 351 + 352 + # `--with` flags for libraries needed for RTS linker 353 + configureFlags = [ 354 + "--datadir=$doc/share/doc/ghc" 355 + "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" 356 + ] ++ lib.optionals (libffi != null) [ 357 + "--with-system-libffi" 358 + "--with-ffi-includes=${targetPackages.libffi.dev}/include" 359 + "--with-ffi-libraries=${targetPackages.libffi.out}/lib" 360 + ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 361 + "--with-gmp-includes=${targetPackages.gmp.dev}/include" 362 + "--with-gmp-libraries=${targetPackages.gmp.out}/lib" 363 + ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ 364 + "--with-iconv-includes=${libiconv}/include" 365 + "--with-iconv-libraries=${libiconv}/lib" 366 + ] ++ lib.optionals (targetPlatform != hostPlatform) [ 367 + "--enable-bootstrap-with-devel-snapshot" 368 + ] ++ lib.optionals useLdGold [ 369 + "CFLAGS=-fuse-ld=gold" 370 + "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 371 + "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 372 + ] ++ lib.optionals (disableLargeAddressSpace) [ 373 + "--disable-large-address-space" 374 + ] ++ lib.optionals enableDwarf [ 375 + "--enable-dwarf-unwind" 376 + "--with-libdw-includes=${lib.getDev elfutils}/include" 377 + "--with-libdw-libraries=${lib.getLib elfutils}/lib" 378 + ]; 379 + 380 + # Make sure we never relax`$PATH` and hooks support for compatibility. 381 + strictDeps = true; 382 + 383 + # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 384 + dontAddExtraLibs = true; 385 + 386 + nativeBuildInputs = [ 387 + perl ghc hadrian bootPkgs.alex bootPkgs.happy bootPkgs.hscolour 388 + ] ++ lib.optionals (rev != null) [ 389 + # We need to execute the boot script 390 + autoconf automake m4 python3 391 + ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 392 + autoSignDarwinBinariesHook 393 + ] ++ lib.optionals enableDocs [ 394 + sphinx 395 + ]; 396 + 397 + # For building runtime libs 398 + depsBuildTarget = toolsForTarget; 399 + 400 + buildInputs = [ perl bash ] ++ (libDeps hostPlatform); 401 + 402 + depsTargetTarget = map lib.getDev (libDeps targetPlatform); 403 + depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); 404 + 405 + hadrianFlags = [ 406 + "--flavour=${ghcFlavour}" 407 + "--bignum=${if enableNativeBignum then "native" else "gmp"}" 408 + "--docs=${if enableDocs then "no-sphinx-pdfs" else "no-sphinx"}" 409 + ]; 410 + 411 + buildPhase = '' 412 + runHook preBuild 413 + 414 + # hadrianFlagsArray is created in preConfigure 415 + echo "hadrianFlags: $hadrianFlags ''${hadrianFlagsArray}" 416 + 417 + # We need to go via the bindist for installing 418 + hadrian $hadrianFlags "''${hadrianFlagsArray}" binary-dist-dir 419 + 420 + runHook postBuild 421 + ''; 422 + 423 + # required, because otherwise all symbols from HSffi.o are stripped, and 424 + # that in turn causes GHCi to abort 425 + stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 426 + 427 + checkTarget = "test"; 428 + 429 + hardeningDisable = 430 + [ "format" ] 431 + # In nixpkgs, musl based builds currently enable `pie` hardening by default 432 + # (see `defaultHardeningFlags` in `make-derivation.nix`). 433 + # But GHC cannot currently produce outputs that are ready for `-pie` linking. 434 + # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear. 435 + # See: 436 + # * https://github.com/NixOS/nixpkgs/issues/129247 437 + # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580 438 + ++ lib.optional stdenv.targetPlatform.isMusl "pie"; 439 + 440 + # big-parallel allows us to build with more than 2 cores on 441 + # Hydra which already warrants a significant speedup 442 + requiredSystemFeatures = [ "big-parallel" ]; 443 + 444 + outputs = [ "out" "doc" ]; 445 + 446 + # We need to configure the bindist *again* before installing 447 + # https://gitlab.haskell.org/ghc/ghc/-/issues/22058 448 + # TODO(@sternenseemann): it would be nice if the bindist could be an intermediate 449 + # derivation, but since it is > 2GB even on x86_64-linux, not a good idea? 450 + preInstall = '' 451 + pushd _build/bindist/* 452 + 453 + ./configure $configureFlags "''${configureFlagsArray[@]}" 454 + ''; 455 + 456 + postInstall = '' 457 + # leave bindist directory 458 + popd 459 + 460 + # Install the bash completion file. 461 + install -Dm 644 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 462 + ''; 463 + 464 + passthru = { 465 + inherit bootPkgs targetPrefix; 466 + 467 + inherit llvmPackages; 468 + inherit enableShared; 469 + 470 + # Our Cabal compiler name 471 + haskellCompilerName = "ghc-${version}"; 472 + 473 + # Expose hadrian used for bootstrapping, for debugging purposes 474 + inherit hadrian; 475 + }; 476 + 477 + meta = { 478 + homepage = "http://haskell.org/ghc"; 479 + description = "The Glasgow Haskell Compiler"; 480 + maintainers = with lib.maintainers; [ 481 + guibou 482 + ] ++ lib.teams.haskell.members; 483 + timeout = 24 * 3600; 484 + inherit (ghc.meta) license platforms; 485 + }; 486 + 487 + dontStrip = targetPlatform.useAndroidPrebuilt || targetPlatform.isWasm; 488 + } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { 489 + dontPatchELF = true; 490 + noAuditTmpdir = true; 491 + })
+5 -375
pkgs/development/compilers/ghc/head.nix
··· 1 - { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 2 - 3 - # build-tools 4 - , bootPkgs 5 - , autoconf, autoreconfHook, automake, coreutils, fetchgit, perl, python3, m4, sphinx 6 - , xattr, autoSignDarwinBinariesHook 7 - , bash 8 - 9 - , libiconv ? null, ncurses 10 - 11 - , # GHC can be built with system libffi or a bundled one. 12 - libffi ? null 13 - 14 - # Libdw.c only supports x86_64, i686 and s390x 15 - , enableDwarf ? (stdenv.targetPlatform.isx86 || 16 - (stdenv.targetPlatform.isS390 && stdenv.targetPlatform.is64bit)) && 17 - lib.meta.availableOn stdenv.hostPlatform elfutils && 18 - lib.meta.availableOn stdenv.targetPlatform elfutils 19 - , elfutils # for DWARF support 20 - 21 - , useLLVM ? !(stdenv.targetPlatform.isx86 22 - || stdenv.targetPlatform.isPower 23 - || stdenv.targetPlatform.isSparc 24 - || (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin)) 25 - , # LLVM is conceptually a run-time-only depedendency, but for 26 - # non-x86, we need LLVM to bootstrap later stages, so it becomes a 27 - # build-time dependency too. 28 - buildTargetLlvmPackages, llvmPackages 29 - 30 - , # If enabled, GHC will be built with the GPL-free but slightly slower native 31 - # bignum backend instead of the faster but GPLed gmp backend. 32 - enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp) 33 - , gmp 34 - 35 - , # If enabled, use -fPIC when compiling static libs. 36 - enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform 37 - 38 - # aarch64 outputs otherwise exceed 2GB limit 39 - , enableProfiledLibs ? !stdenv.targetPlatform.isAarch64 40 - 41 - , # Whether to build dynamic libs for the standard library (on the target 42 - # platform). Static libs are always built. 43 - enableShared ? !stdenv.targetPlatform.isWindows && !stdenv.targetPlatform.useiOSPrebuilt 44 - 45 - , version ? "9.3.20220406" 46 - , # What flavour to build. An empty string indicates no 47 - # specific flavour and falls back to ghc default values. 48 - ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 49 - (if useLLVM then "perf-cross" else "perf-cross-ncg") 50 - 51 - , # Whether to build sphinx documentation. 52 - enableDocs ? ( 53 - # Docs disabled for musl and cross because it's a large task to keep 54 - # all `sphinx` dependencies building in those environments. 55 - # `sphinx` pullls in among others: 56 - # Ruby, Python, Perl, Rust, OpenGL, Xorg, gtk, LLVM. 57 - (stdenv.targetPlatform == stdenv.hostPlatform) 58 - && !stdenv.hostPlatform.isMusl 59 - ) 60 - 61 - , enableHaddockProgram ? 62 - # Disabled for cross; see note [HADDOCK_DOCS]. 63 - (stdenv.targetPlatform == stdenv.hostPlatform) 64 - 65 - , # Whether to disable the large address space allocator 66 - # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 67 - disableLargeAddressSpace ? stdenv.targetPlatform.isiOS 68 - }: 69 - 70 - assert !enableNativeBignum -> gmp != null; 71 - 72 - # Cross cannot currently build the `haddock` program for silly reasons, 73 - # see note [HADDOCK_DOCS]. 74 - assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; 75 - 76 - let 77 - inherit (stdenv) buildPlatform hostPlatform targetPlatform; 78 - 79 - inherit (bootPkgs) ghc; 80 - 81 - # TODO(@Ericson2314) Make unconditional 82 - targetPrefix = lib.optionalString 83 - (targetPlatform != hostPlatform) 84 - "${targetPlatform.config}-"; 85 - 86 - buildMK = dontStrip: '' 87 - BuildFlavour = ${ghcFlavour} 88 - ifneq \"\$(BuildFlavour)\" \"\" 89 - include mk/flavours/\$(BuildFlavour).mk 90 - endif 91 - BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} 92 - BUILD_SPHINX_PDF = NO 93 - '' + 94 - # Note [HADDOCK_DOCS]: 95 - # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` 96 - # program is built (which we generally always want to have a complete GHC install) 97 - # and whether it is run on the GHC sources to generate hyperlinked source code 98 - # (which is impossible for cross-compilation); see: 99 - # https://gitlab.haskell.org/ghc/ghc/-/issues/20077 100 - # This implies that currently a cross-compiled GHC will never have a `haddock` 101 - # program, so it can never generate haddocks for any packages. 102 - # If this is solved in the future, we'd like to unconditionally 103 - # build the haddock program (removing the `enableHaddockProgram` option). 104 - '' 105 - HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"} 106 - DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} 107 - BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"} 108 - '' + lib.optionalString (targetPlatform != hostPlatform) '' 109 - Stage1Only = ${if (targetPlatform.system == hostPlatform.system && !targetPlatform.isiOS) then "NO" else "YES"} 110 - CrossCompilePrefix = ${targetPrefix} 111 - '' + lib.optionalString dontStrip '' 112 - STRIP_CMD = : 113 - '' + lib.optionalString (!enableProfiledLibs) '' 114 - GhcLibWays = "v dyn" 115 - '' + lib.optionalString enableRelocatedStaticLibs '' 116 - GhcLibHcOpts += -fPIC 117 - GhcRtsHcOpts += -fPIC 118 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 119 - EXTRA_CC_OPTS += -std=gnu99 120 - '' 121 - # While split sections are now enabled by default in ghc 8.8 for windows, 122 - # they seem to lead to `too many sections` errors when building base for 123 - # profiling. 124 - + lib.optionalString targetPlatform.isWindows '' 125 - SplitSections = NO 126 - ''; 127 - 128 - # Splicer will pull out correct variations 129 - libDeps = platform: 130 - [libffi ncurses] 131 - ++ lib.optional (!enableNativeBignum) gmp 132 - ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv 133 - ++ lib.optional enableDwarf elfutils; 134 - 135 - # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 136 - # GHC doesn't seem to have {LLC,OPT}_HOST 137 - toolsForTarget = [ 138 - pkgsBuildTarget.targetPackages.stdenv.cc 139 - ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 140 - 141 - targetCC = builtins.head toolsForTarget; 142 - 143 - # Sometimes we have to dispatch between the bintools wrapper and the unwrapped 144 - # derivation for certain tools depending on the platform. 145 - bintoolsFor = { 146 - # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is 147 - # part of the bintools wrapper (due to codesigning requirements), but not on 148 - # x86_64-darwin. 149 - install_name_tool = 150 - if stdenv.targetPlatform.isAarch64 151 - then targetCC.bintools 152 - else targetCC.bintools.bintools; 153 - # Same goes for strip. 154 - strip = 155 - # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 156 - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin 157 - then targetCC.bintools 158 - else targetCC.bintools.bintools; 159 - }; 160 - 161 - # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 162 - # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 163 - # see #84670 and #49071 for more background. 164 - useLdGold = targetPlatform.linker == "gold" || 165 - (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); 166 - 167 - # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 168 - variantSuffix = lib.concatStrings [ 169 - (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 170 - (lib.optionalString enableNativeBignum "-native-bignum") 171 - ]; 172 - 173 - in 174 - 175 - # C compiler, bintools and LLVM are used at build time, but will also leak into 176 - # the resulting GHC's settings file and used at runtime. This means that we are 177 - # currently only able to build GHC if hostPlatform == buildPlatform. 178 - assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; 179 - assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; 180 - assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 181 - 182 - stdenv.mkDerivation (rec { 183 - inherit version; 184 - inherit (src) rev; 185 - pname = "${targetPrefix}ghc${variantSuffix}"; 186 - 187 - src = fetchgit { 188 - url = "https://gitlab.haskell.org/ghc/ghc.git/"; 189 - rev = "c44432db254d2fc960d7864e080cb50e65dfa7c6"; 190 - sha256 = "0xagijcfcw3a19s6dmh6z7085lvkrakys3lcby4ncq1v0syh507h"; 191 - }; 192 - 193 - enableParallelBuilding = true; 194 - 195 - outputs = [ "out" "doc" ]; 196 - 197 - postPatch = "patchShebangs ."; 198 - 199 - # GHC is a bit confused on its cross terminology. 200 - # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 201 - preConfigure = '' 202 - for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 203 - export "''${env#TARGET_}=''${!env}" 204 - done 205 - # GHC is a bit confused on its cross terminology, as these would normally be 206 - # the *host* tools. 207 - export CC="${targetCC}/bin/${targetCC.targetPrefix}cc" 208 - export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++" 209 - # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 210 - # and more generally have a faster linker. 211 - export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}" 212 - export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as" 213 - export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar" 214 - export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" 215 - export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" 216 - export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" 217 - export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" 218 - '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 219 - export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" 220 - export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" 221 - '' + lib.optionalString useLLVM '' 222 - export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" 223 - export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" 224 - '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 225 - # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 226 - export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 227 - '' + '' 228 - 229 - # otherwise haddock fails when generating the compiler docs 230 - export LANG=C.UTF-8 231 - 232 - echo -n "${buildMK dontStrip}" > mk/build.mk 233 - echo ${version} > VERSION 234 - echo ${src.rev} > GIT_COMMIT_ID 235 - ./boot 236 - sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure 237 - '' + lib.optionalString (!stdenv.isDarwin) '' 238 - export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 239 - '' + lib.optionalString stdenv.isDarwin '' 240 - export NIX_LDFLAGS+=" -no_dtrace_dof" 241 - 242 - # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 243 - export XATTR=${lib.getBin xattr}/bin/xattr 244 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 245 - 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 246 - '' + lib.optionalString targetPlatform.isMusl '' 247 - echo "patching llvm-targets for musl targets..." 248 - echo "Cloning these existing '*-linux-gnu*' targets:" 249 - grep linux-gnu llvm-targets | sed 's/^/ /' 250 - echo "(go go gadget sed)" 251 - sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 252 - echo "llvm-targets now contains these '*-linux-musl*' targets:" 253 - grep linux-musl llvm-targets | sed 's/^/ /' 254 - 255 - echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 256 - # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen) 257 - for x in configure aclocal.m4; do 258 - substituteInPlace $x \ 259 - --replace '*-android*|*-gnueabi*)' \ 260 - '*-android*|*-gnueabi*|*-musleabi*)' 261 - done 262 - ''; 263 - 264 - # TODO(@Ericson2314): Always pass "--target" and always prefix. 265 - configurePlatforms = [ "build" "host" ] 266 - ++ lib.optional (targetPlatform != hostPlatform) "target"; 267 - 268 - # `--with` flags for libraries needed for RTS linker 269 - configureFlags = [ 270 - "--datadir=$doc/share/doc/ghc" 271 - "--with-curses-libraries=${ncurses.out}/lib" 272 - ] ++ lib.optionals (libffi != null) [ 273 - "--with-system-libffi" 274 - "--with-ffi-includes=${targetPackages.libffi.dev}/include" 275 - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" 276 - ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 277 - "--with-gmp-includes=${targetPackages.gmp.dev}/include" 278 - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" 279 - ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ 280 - "--with-iconv-includes=${libiconv}/include" 281 - "--with-iconv-libraries=${libiconv}/lib" 282 - ] ++ lib.optionals (targetPlatform != hostPlatform) [ 283 - "--enable-bootstrap-with-devel-snapshot" 284 - ] ++ lib.optionals useLdGold [ 285 - "CFLAGS=-fuse-ld=gold" 286 - "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 287 - "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 288 - ] ++ lib.optional disableLargeAddressSpace "--disable-large-address-space" 289 - ++ lib.optionals enableDwarf [ 290 - "--enable-dwarf-unwind" 291 - "--with-libdw-includes=${lib.getDev elfutils}/include" 292 - "--with-libdw-libraries=${lib.getLib elfutils}/lib" 293 - ]; 294 - 295 - # Make sure we never relax`$PATH` and hooks support for compatibility. 296 - strictDeps = true; 297 - 298 - # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 299 - dontAddExtraLibs = true; 300 - 301 - nativeBuildInputs = [ 302 - perl autoconf autoreconfHook automake m4 python3 303 - ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour 304 - ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 305 - autoSignDarwinBinariesHook 306 - ] ++ lib.optionals enableDocs [ 307 - sphinx 308 - ]; 309 - 310 - # For building runtime libs 311 - depsBuildTarget = toolsForTarget; 312 - 313 - buildInputs = [ perl bash ] ++ (libDeps hostPlatform); 314 - 315 - depsTargetTarget = map lib.getDev (libDeps targetPlatform); 316 - depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); 317 - 318 - # required, because otherwise all symbols from HSffi.o are stripped, and 319 - # that in turn causes GHCi to abort 320 - stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 321 - 322 - checkTarget = "test"; 323 - 324 - hardeningDisable = 325 - [ "format" ] 326 - # In nixpkgs, musl based builds currently enable `pie` hardening by default 327 - # (see `defaultHardeningFlags` in `make-derivation.nix`). 328 - # But GHC cannot currently produce outputs that are ready for `-pie` linking. 329 - # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear. 330 - # See: 331 - # * https://github.com/NixOS/nixpkgs/issues/129247 332 - # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580 333 - ++ lib.optional stdenv.targetPlatform.isMusl "pie"; 334 - 335 - # big-parallel allows us to build with more than 2 cores on 336 - # Hydra which already warrants a significant speedup 337 - requiredSystemFeatures = [ "big-parallel" ]; 338 - 339 - postInstall = '' 340 - # Install the bash completion file. 341 - install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 342 - ''; 343 - 344 - passthru = { 345 - inherit bootPkgs targetPrefix; 346 - 347 - inherit llvmPackages; 348 - inherit enableShared; 349 - 350 - # This is used by the haskell builder to query 351 - # the presence of the haddock program. 352 - hasHaddock = enableHaddockProgram; 353 - 354 - # Our Cabal compiler name 355 - haskellCompilerName = "ghc-${version}"; 356 - }; 357 - 358 - meta = { 359 - homepage = "http://haskell.org/ghc"; 360 - description = "The Glasgow Haskell Compiler"; 361 - maintainers = with lib.maintainers; [ 362 - guibou 363 - ] ++ lib.teams.haskell.members; 364 - timeout = 24 * 3600; 365 - inherit (ghc.meta) license platforms; 366 - # ghcHEAD times out on aarch64-linux on Hydra. 367 - hydraPlatforms = builtins.filter (p: p != "aarch64-linux") ghc.meta.platforms; 368 - }; 369 - 370 - dontStrip = (targetPlatform.useAndroidPrebuilt || targetPlatform.isWasm); 371 - 372 - } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt{ 373 - dontPatchELF = true; 374 - noAuditTmpdir = true; 375 - }) 1 + import ./common-hadrian.nix { 2 + version = "9.5.20220921"; 3 + rev = "2463df2fe21b5b37ecada3df8c6726c534d24590"; 4 + sha256 = "1k2h4myqbs31fdzw5n4iw0qn44mp7d33kjwrr15ix4r54r8yskzs"; 5 + }
+41
pkgs/development/tools/haskell/hadrian/default.nix
··· 1 + { # GHC source tree to build hadrian from 2 + ghcSrc ? null, ghcVersion ? null 3 + , mkDerivation, base, bytestring, Cabal, containers, directory 4 + , extra, filepath, lib, mtl, parsec, shake, text, transformers 5 + , unordered-containers 6 + , userSettings ? null 7 + , writeText 8 + }: 9 + 10 + if ghcSrc == null || ghcVersion == null 11 + then throw "hadrian: need to specify ghcSrc and ghcVersion arguments manually" 12 + else 13 + 14 + mkDerivation { 15 + pname = "hadrian"; 16 + version = ghcVersion; 17 + src = ghcSrc; 18 + postUnpack = '' 19 + sourceRoot="$sourceRoot/hadrian" 20 + ''; 21 + # Overwrite UserSettings.hs with a provided custom one 22 + postPatch = lib.optionalString (userSettings != null) '' 23 + install -m644 "${writeText "UserSettings.hs" userSettings}" src/UserSettings.hs 24 + ''; 25 + configureFlags = [ 26 + # avoid QuickCheck dep which needs shared libs / TH 27 + "-f-selftest" 28 + # Building hadrian with -O1 takes quite some time with little benefit. 29 + # Additionally we need to recompile it on every change of UserSettings.hs. 30 + # See https://gitlab.haskell.org/ghc/ghc/-/merge_requests/1190 31 + "-O0" 32 + ]; 33 + isLibrary = false; 34 + isExecutable = true; 35 + executableHaskellDepends = [ 36 + base bytestring Cabal containers directory extra filepath mtl 37 + parsec shake text transformers unordered-containers 38 + ]; 39 + description = "GHC build system"; 40 + license = lib.licenses.bsd3; 41 + }
+6 -4
pkgs/top-level/haskell-packages.nix
··· 192 192 ghc94 = ghc942; 193 193 ghcHEAD = callPackage ../development/compilers/ghc/head.nix { 194 194 bootPkgs = 195 - if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then 196 - packages.ghc8107 195 + if stdenv.isAarch64 || stdenv.isAarch32 then 196 + packages.ghc922BinaryMinimal 197 + else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then 198 + packages.ghc924 197 199 else 198 - packages.ghc8107Binary; 200 + packages.ghc922Binary; 199 201 inherit (buildPackages.python3Packages) sphinx; 200 202 # Need to use apple's patched xattr until 201 203 # https://github.com/xattr/xattr/issues/44 and 202 204 # https://github.com/xattr/xattr/issues/55 are solved. 203 205 inherit (buildPackages.darwin) xattr autoSignDarwinBinariesHook; 206 + # 2022-08-04: Support range >= 10 && < 14 204 207 buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_12; 205 208 llvmPackages = pkgs.llvmPackages_12; 206 - libffi = pkgs.libffi; 207 209 }; 208 210 209 211 ghcjs = compiler.ghcjs810;