haskell.compiler: port all make/native-bignum GHCs to common expr

The common expression is a little messy to avoid rebuilds. It can be
cleaned up in a second step.

`9.4.8.fixme.nix` is used temporarily so that git's rename detection
gets where common-make-native-bignum.nix is coming from.

8.10.7 keeps its expression since it uses integer-simple which changes
the expression's interface. This is unfortunately very annoying to
reflect in a common expression.

+125 -3123
+3 -392
pkgs/development/compilers/ghc/9.0.2.nix
··· 1 - { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 2 - 3 - # build-tools 4 - , bootPkgs 5 - , autoconf, automake, coreutils, fetchurl, perl, python3, m4, sphinx, xattr 6 - , autoSignDarwinBinariesHook 7 - , bash 8 - , fetchpatch 9 - 10 - , libiconv ? null, ncurses 11 - , glibcLocales ? null 12 - 13 - , # GHC can be built with system libffi or a bundled one. 14 - libffi ? null 15 - 16 - , useLLVM ? !(stdenv.targetPlatform.isx86 17 - || stdenv.targetPlatform.isPower 18 - || stdenv.targetPlatform.isSparc) 19 - , # LLVM is conceptually a run-time-only dependency, but for 20 - # non-x86, we need LLVM to bootstrap later stages, so it becomes a 21 - # build-time dependency too. 22 - buildTargetLlvmPackages, llvmPackages 23 - 24 - , # If enabled, GHC will be built with the GPL-free but slightly slower native 25 - # bignum backend instead of the faster but GPLed gmp backend. 26 - enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp 27 - && lib.meta.availableOn stdenv.targetPlatform gmp) 28 - , gmp 29 - 30 - , # If enabled, use -fPIC when compiling static libs. 31 - enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform 32 - 33 - , enableProfiledLibs ? true 34 - 35 - , # Whether to build dynamic libs for the standard library (on the target 36 - # platform). Static libs are always built. 37 - enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic 38 - 39 - , # Whether to build terminfo. 40 - enableTerminfo ? !stdenv.targetPlatform.isWindows 41 - 42 - , # What flavour to build. An empty string indicates no 43 - # specific flavour and falls back to ghc default values. 44 - ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 45 - (if useLLVM then "perf-cross" else "perf-cross-ncg") 46 - 47 - , # Whether to build sphinx documentation. 48 - enableDocs ? ( 49 - # Docs disabled if we are building on musl because it's a large task to keep 50 - # all `sphinx` dependencies building in this environment. 51 - !stdenv.buildPlatform.isMusl 52 - ) 53 - 54 - , enableHaddockProgram ? 55 - # Disabled for cross; see note [HADDOCK_DOCS]. 56 - (stdenv.targetPlatform == stdenv.hostPlatform) 57 - 58 - , # Whether to disable the large address space allocator 59 - # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 60 - disableLargeAddressSpace ? stdenv.targetPlatform.isiOS 61 - }: 62 - 63 - assert !enableNativeBignum -> gmp != null; 64 - 65 - # Cross cannot currently build the `haddock` program for silly reasons, 66 - # see note [HADDOCK_DOCS]. 67 - assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; 68 - 69 - let 70 - inherit (stdenv) buildPlatform hostPlatform targetPlatform; 71 - 72 - inherit (bootPkgs) ghc; 73 - 74 - # TODO(@Ericson2314) Make unconditional 75 - targetPrefix = lib.optionalString 76 - (targetPlatform != hostPlatform) 77 - "${targetPlatform.config}-"; 78 - 79 - buildMK = '' 80 - BuildFlavour = ${ghcFlavour} 81 - ifneq \"\$(BuildFlavour)\" \"\" 82 - include mk/flavours/\$(BuildFlavour).mk 83 - endif 84 - BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} 85 - BUILD_SPHINX_PDF = NO 86 - '' + 87 - # Note [HADDOCK_DOCS]: 88 - # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` 89 - # program is built (which we generally always want to have a complete GHC install) 90 - # and whether it is run on the GHC sources to generate hyperlinked source code 91 - # (which is impossible for cross-compilation); see: 92 - # https://gitlab.haskell.org/ghc/ghc/-/issues/20077 93 - # This implies that currently a cross-compiled GHC will never have a `haddock` 94 - # program, so it can never generate haddocks for any packages. 95 - # If this is solved in the future, we'd like to unconditionally 96 - # build the haddock program (removing the `enableHaddockProgram` option). 97 - '' 98 - HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"} 99 - # Build haddocks for boot packages with hyperlinking 100 - EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump 101 - 102 - DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} 103 - BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"} 104 - '' + lib.optionalString (targetPlatform != hostPlatform) '' 105 - Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"} 106 - CrossCompilePrefix = ${targetPrefix} 107 - '' + lib.optionalString (!enableProfiledLibs) '' 108 - BUILD_PROF_LIBS = NO 109 - '' + 110 - # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) 111 - # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. 112 - # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell 113 - lib.optionalString enableRelocatedStaticLibs '' 114 - GhcLibHcOpts += -fPIC -fexternal-dynamic-refs 115 - GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs 116 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 117 - EXTRA_CC_OPTS += -std=gnu99 118 - ''; 119 - 120 - # Splicer will pull out correct variations 121 - libDeps = platform: lib.optional enableTerminfo ncurses 122 - ++ [libffi] 123 - ++ lib.optional (!enableNativeBignum) gmp 124 - ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; 125 - 126 - # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 127 - # GHC doesn't seem to have {LLC,OPT}_HOST 128 - toolsForTarget = [ 129 - pkgsBuildTarget.targetPackages.stdenv.cc 130 - ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 131 - 132 - targetCC = builtins.head toolsForTarget; 133 - 134 - # Sometimes we have to dispatch between the bintools wrapper and the unwrapped 135 - # derivation for certain tools depending on the platform. 136 - bintoolsFor = { 137 - # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is 138 - # part of the bintools wrapper (due to codesigning requirements), but not on 139 - # x86_64-darwin. 140 - install_name_tool = 141 - if stdenv.targetPlatform.isAarch64 142 - then targetCC.bintools 143 - else targetCC.bintools.bintools; 144 - # Same goes for strip. 145 - strip = 146 - # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 147 - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin 148 - then targetCC.bintools 149 - else targetCC.bintools.bintools; 150 - }; 151 - 152 - # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 153 - # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 154 - # see #84670 and #49071 for more background. 155 - useLdGold = targetPlatform.linker == "gold" || 156 - (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); 157 - 158 - # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 159 - variantSuffix = lib.concatStrings [ 160 - (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 161 - (lib.optionalString enableNativeBignum "-native-bignum") 162 - ]; 163 - 164 - in 165 - 166 - # C compiler, bintools and LLVM are used at build time, but will also leak into 167 - # the resulting GHC's settings file and used at runtime. This means that we are 168 - # currently only able to build GHC if hostPlatform == buildPlatform. 169 - assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; 170 - assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; 171 - assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 172 - 173 - stdenv.mkDerivation (rec { 1 + import ./common-make-native-bignum.nix { 174 2 version = "9.0.2"; 175 - pname = "${targetPrefix}ghc${variantSuffix}"; 176 - 177 - src = fetchurl { 178 - url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"; 179 - sha256 = "140e42b96346322d1a39eb17602bcdc76e292028ad4a69286b230bab188a9197"; 180 - }; 181 - 182 - enableParallelBuilding = true; 183 - 184 - outputs = [ "out" "doc" ]; 185 - 186 - patches = [ 187 - # Fix docs build with sphinx >= 6.0 188 - # https://gitlab.haskell.org/ghc/ghc/-/issues/22766 189 - (fetchpatch { 190 - name = "ghc-docs-sphinx-6.0.patch"; 191 - url = "https://gitlab.haskell.org/ghc/ghc/-/commit/10e94a556b4f90769b7fd718b9790d58ae566600.patch"; 192 - sha256 = "0kmhfamr16w8gch0lgln2912r8aryjky1hfcda3jkcwa5cdzgjdv"; 193 - }) 194 - # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 195 - ./docs-sphinx-7.patch 196 - # fix hyperlinked haddock sources: https://github.com/haskell/haddock/pull/1482 197 - (fetchpatch { 198 - url = "https://patch-diff.githubusercontent.com/raw/haskell/haddock/pull/1482.patch"; 199 - sha256 = "sha256-8w8QUCsODaTvknCDGgTfFNZa8ZmvIKaKS+2ZJZ9foYk="; 200 - extraPrefix = "utils/haddock/"; 201 - stripLen = 1; 202 - }) 203 - 204 - # Add flag that fixes C++ exception handling; opt-in. Merged in 9.4 and 9.2.2. 205 - # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/7423 206 - (fetchpatch { 207 - name = "ghc-9.0.2-fcompact-unwind.patch"; 208 - # Note that the test suite is not packaged. 209 - url = "https://gitlab.haskell.org/ghc/ghc/-/commit/c6132c782d974a7701e7f6447bdcd2bf6db4299a.patch?merge_request_iid=7423"; 210 - sha256 = "sha256-b4feGZIaKDj/UKjWTNY6/jH4s2iate0wAgMxG3rAbZI="; 211 - }) 212 - ] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 213 - # Prevent the paths module from emitting symbols that we don't use 214 - # when building with separate outputs. 215 - # 216 - # These cause problems as they're not eliminated by GHC's dead code 217 - # elimination on aarch64-darwin. (see 218 - # https://github.com/NixOS/nixpkgs/issues/140774 for details). 219 - ./Cabal-3.2-3.4-paths-fix-cycle-aarch64-darwin.patch 220 - ]; 221 - 222 - postPatch = "patchShebangs ."; 223 - 224 - # GHC needs the locale configured during the Haddock phase. 225 - LANG = "en_US.UTF-8"; 226 - 227 - # GHC is a bit confused on its cross terminology. 228 - # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 229 - preConfigure = '' 230 - for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 231 - export "''${env#TARGET_}=''${!env}" 232 - done 233 - # GHC is a bit confused on its cross terminology, as these would normally be 234 - # the *host* tools. 235 - export CC="${targetCC}/bin/${targetCC.targetPrefix}cc" 236 - export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++" 237 - # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 238 - export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}" 239 - export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as" 240 - export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar" 241 - export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" 242 - export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" 243 - export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" 244 - export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" 245 - '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 246 - export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" 247 - export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" 248 - '' + lib.optionalString useLLVM '' 249 - export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" 250 - export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" 251 - '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 252 - # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 253 - export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 254 - '' + '' 255 - 256 - echo -n "${buildMK}" > mk/build.mk 257 - sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure 258 - '' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' 259 - export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" 260 - '' + lib.optionalString (!stdenv.isDarwin) '' 261 - export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 262 - '' + lib.optionalString stdenv.isDarwin '' 263 - export NIX_LDFLAGS+=" -no_dtrace_dof" 264 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 265 - 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 266 - '' + lib.optionalString targetPlatform.isMusl '' 267 - echo "patching llvm-targets for musl targets..." 268 - echo "Cloning these existing '*-linux-gnu*' targets:" 269 - grep linux-gnu llvm-targets | sed 's/^/ /' 270 - echo "(go go gadget sed)" 271 - sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 272 - echo "llvm-targets now contains these '*-linux-musl*' targets:" 273 - grep linux-musl llvm-targets | sed 's/^/ /' 274 - 275 - echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 276 - # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen) 277 - for x in configure aclocal.m4; do 278 - substituteInPlace $x \ 279 - --replace '*-android*|*-gnueabi*)' \ 280 - '*-android*|*-gnueabi*|*-musleabi*)' 281 - done 282 - ''; 283 - 284 - # TODO(@Ericson2314): Always pass "--target" and always prefix. 285 - configurePlatforms = [ "build" "host" ] 286 - ++ lib.optional (targetPlatform != hostPlatform) "target"; 287 - 288 - # `--with` flags for libraries needed for RTS linker 289 - configureFlags = [ 290 - "--datadir=$doc/share/doc/ghc" 291 - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" 292 - ] ++ lib.optionals (libffi != null) [ 293 - "--with-system-libffi" 294 - "--with-ffi-includes=${targetPackages.libffi.dev}/include" 295 - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" 296 - ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 297 - "--with-gmp-includes=${targetPackages.gmp.dev}/include" 298 - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" 299 - ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ 300 - "--with-iconv-includes=${libiconv}/include" 301 - "--with-iconv-libraries=${libiconv}/lib" 302 - ] ++ lib.optionals (targetPlatform != hostPlatform) [ 303 - "--enable-bootstrap-with-devel-snapshot" 304 - ] ++ lib.optionals useLdGold [ 305 - "CFLAGS=-fuse-ld=gold" 306 - "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 307 - "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 308 - ] ++ lib.optionals (disableLargeAddressSpace) [ 309 - "--disable-large-address-space" 310 - ]; 311 - 312 - # Make sure we never relax`$PATH` and hooks support for compatibility. 313 - strictDeps = true; 314 - 315 - # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 316 - dontAddExtraLibs = true; 317 - 318 - nativeBuildInputs = [ 319 - perl autoconf automake m4 python3 320 - ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour 321 - ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 322 - autoSignDarwinBinariesHook 323 - ] ++ lib.optionals enableDocs [ 324 - sphinx 325 - ] ++ lib.optionals stdenv.isDarwin [ 326 - # TODO(@sternenseemann): backport addition of XATTR env var like 327 - # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6447 328 - xattr 329 - ]; 330 - 331 - # For building runtime libs 332 - depsBuildTarget = toolsForTarget; 333 - 334 - buildInputs = [ perl bash ] ++ (libDeps hostPlatform); 335 - 336 - depsTargetTarget = map lib.getDev (libDeps targetPlatform); 337 - depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); 338 - 339 - # required, because otherwise all symbols from HSffi.o are stripped, and 340 - # that in turn causes GHCi to abort 341 - stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 342 - 343 - checkTarget = "test"; 344 - 345 - hardeningDisable = 346 - [ "format" ] 347 - # In nixpkgs, musl based builds currently enable `pie` hardening by default 348 - # (see `defaultHardeningFlags` in `make-derivation.nix`). 349 - # But GHC cannot currently produce outputs that are ready for `-pie` linking. 350 - # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear. 351 - # See: 352 - # * https://github.com/NixOS/nixpkgs/issues/129247 353 - # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580 354 - ++ lib.optional stdenv.targetPlatform.isMusl "pie"; 355 - 356 - # big-parallel allows us to build with more than 2 cores on 357 - # Hydra which already warrants a significant speedup 358 - requiredSystemFeatures = [ "big-parallel" ]; 359 - 360 - postInstall = '' 361 - # Install the bash completion file. 362 - install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 363 - ''; 364 - 365 - passthru = { 366 - inherit bootPkgs targetPrefix; 367 - 368 - inherit llvmPackages; 369 - inherit enableShared; 370 - 371 - # This is used by the haskell builder to query 372 - # the presence of the haddock program. 373 - hasHaddock = enableHaddockProgram; 374 - 375 - # Our Cabal compiler name 376 - haskellCompilerName = "ghc-${version}"; 377 - }; 378 - 379 - meta = { 380 - homepage = "http://haskell.org/ghc"; 381 - description = "The Glasgow Haskell Compiler"; 382 - maintainers = with lib.maintainers; [ 383 - guibou 384 - ] ++ lib.teams.haskell.members; 385 - timeout = 24 * 3600; 386 - inherit (ghc.meta) license platforms; 387 - }; 388 - 389 - } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { 390 - dontStrip = true; 391 - dontPatchELF = true; 392 - noAuditTmpdir = true; 393 - }) 3 + sha256 = "140e42b96346322d1a39eb17602bcdc76e292028ad4a69286b230bab188a9197"; 4 + }
+3 -388
pkgs/development/compilers/ghc/9.2.5.nix
··· 1 - { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 2 - 3 - # build-tools 4 - , bootPkgs 5 - , autoconf, automake, coreutils, fetchpatch, fetchurl, perl, python3, m4, sphinx 6 - , xattr, autoSignDarwinBinariesHook 7 - , bash 8 - 9 - , libiconv ? null, ncurses 10 - , glibcLocales ? null 11 - 12 - , # GHC can be built with system libffi or a bundled one. 13 - libffi ? null 14 - 15 - , useLLVM ? !(stdenv.targetPlatform.isx86 16 - || stdenv.targetPlatform.isPower 17 - || stdenv.targetPlatform.isSparc 18 - || stdenv.targetPlatform.isAarch64) 19 - , # LLVM is conceptually a run-time-only dependency, but for 20 - # non-x86, we need LLVM to bootstrap later stages, so it becomes a 21 - # build-time dependency too. 22 - buildTargetLlvmPackages, llvmPackages 23 - 24 - , # If enabled, GHC will be built with the GPL-free but slightly slower native 25 - # bignum backend instead of the faster but GPLed gmp backend. 26 - enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp 27 - && lib.meta.availableOn stdenv.targetPlatform gmp) 28 - , gmp 29 - 30 - , # If enabled, use -fPIC when compiling static libs. 31 - enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform 32 - 33 - , enableProfiledLibs ? true 34 - 35 - , # Whether to build dynamic libs for the standard library (on the target 36 - # platform). Static libs are always built. 37 - enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic 38 - 39 - , # Whether to build terminfo. 40 - enableTerminfo ? !stdenv.targetPlatform.isWindows 41 - 42 - , # What flavour to build. An empty string indicates no 43 - # specific flavour and falls back to ghc default values. 44 - ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 45 - (if useLLVM then "perf-cross" else "perf-cross-ncg") 46 - 47 - , # Whether to build sphinx documentation. 48 - enableDocs ? ( 49 - # Docs disabled if we are building on musl because it's a large task to keep 50 - # all `sphinx` dependencies building in this environment. 51 - !stdenv.buildPlatform.isMusl 52 - ) 53 - 54 - , enableHaddockProgram ? 55 - # Disabled for cross; see note [HADDOCK_DOCS]. 56 - (stdenv.targetPlatform == stdenv.hostPlatform) 57 - 58 - , # Whether to disable the large address space allocator 59 - # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 60 - disableLargeAddressSpace ? stdenv.targetPlatform.isiOS 61 - }: 62 - 63 - assert !enableNativeBignum -> gmp != null; 64 - 65 - # Cross cannot currently build the `haddock` program for silly reasons, 66 - # see note [HADDOCK_DOCS]. 67 - assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; 68 - 69 - let 70 - inherit (stdenv) buildPlatform hostPlatform targetPlatform; 71 - 72 - inherit (bootPkgs) ghc; 73 - 74 - # TODO(@Ericson2314) Make unconditional 75 - targetPrefix = lib.optionalString 76 - (targetPlatform != hostPlatform) 77 - "${targetPlatform.config}-"; 78 - 79 - buildMK = '' 80 - BuildFlavour = ${ghcFlavour} 81 - ifneq \"\$(BuildFlavour)\" \"\" 82 - include mk/flavours/\$(BuildFlavour).mk 83 - endif 84 - BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} 85 - BUILD_SPHINX_PDF = NO 86 - '' + 87 - # Note [HADDOCK_DOCS]: 88 - # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` 89 - # program is built (which we generally always want to have a complete GHC install) 90 - # and whether it is run on the GHC sources to generate hyperlinked source code 91 - # (which is impossible for cross-compilation); see: 92 - # https://gitlab.haskell.org/ghc/ghc/-/issues/20077 93 - # This implies that currently a cross-compiled GHC will never have a `haddock` 94 - # program, so it can never generate haddocks for any packages. 95 - # If this is solved in the future, we'd like to unconditionally 96 - # build the haddock program (removing the `enableHaddockProgram` option). 97 - '' 98 - HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"} 99 - # Build haddocks for boot packages with hyperlinking 100 - EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump 101 - 102 - DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} 103 - BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"} 104 - '' + lib.optionalString (targetPlatform != hostPlatform) '' 105 - Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"} 106 - CrossCompilePrefix = ${targetPrefix} 107 - '' + lib.optionalString (!enableProfiledLibs) '' 108 - BUILD_PROF_LIBS = NO 109 - '' + 110 - # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) 111 - # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. 112 - # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell 113 - lib.optionalString enableRelocatedStaticLibs '' 114 - GhcLibHcOpts += -fPIC -fexternal-dynamic-refs 115 - GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs 116 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 117 - EXTRA_CC_OPTS += -std=gnu99 118 - ''; 119 - 120 - # Splicer will pull out correct variations 121 - libDeps = platform: lib.optional enableTerminfo ncurses 122 - ++ [libffi] 123 - ++ lib.optional (!enableNativeBignum) gmp 124 - ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; 125 - 126 - # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 127 - # GHC doesn't seem to have {LLC,OPT}_HOST 128 - toolsForTarget = [ 129 - pkgsBuildTarget.targetPackages.stdenv.cc 130 - ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 131 - 132 - targetCC = builtins.head toolsForTarget; 133 - 134 - # Sometimes we have to dispatch between the bintools wrapper and the unwrapped 135 - # derivation for certain tools depending on the platform. 136 - bintoolsFor = { 137 - # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is 138 - # part of the bintools wrapper (due to codesigning requirements), but not on 139 - # x86_64-darwin. 140 - install_name_tool = 141 - if stdenv.targetPlatform.isAarch64 142 - then targetCC.bintools 143 - else targetCC.bintools.bintools; 144 - # Same goes for strip. 145 - strip = 146 - # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 147 - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin 148 - then targetCC.bintools 149 - else targetCC.bintools.bintools; 150 - }; 151 - 152 - # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 153 - # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 154 - # see #84670 and #49071 for more background. 155 - useLdGold = targetPlatform.linker == "gold" || 156 - (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); 157 - 158 - # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 159 - variantSuffix = lib.concatStrings [ 160 - (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 161 - (lib.optionalString enableNativeBignum "-native-bignum") 162 - ]; 163 - 164 - in 165 - 166 - # C compiler, bintools and LLVM are used at build time, but will also leak into 167 - # the resulting GHC's settings file and used at runtime. This means that we are 168 - # currently only able to build GHC if hostPlatform == buildPlatform. 169 - assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; 170 - assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; 171 - assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 172 - 173 - stdenv.mkDerivation (rec { 1 + import ./common-make-native-bignum.nix { 174 2 version = "9.2.5"; 175 - pname = "${targetPrefix}ghc${variantSuffix}"; 176 - 177 - src = fetchurl { 178 - url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"; 179 - sha256 = "0606797d1b38e2d88ee2243f38ec6b9a1aa93e9b578e95f0de9a9c0a4144021c"; 180 - }; 181 - 182 - enableParallelBuilding = true; 183 - 184 - outputs = [ "out" "doc" ]; 185 - 186 - patches = [ 187 - # Fix docs build with sphinx >= 6.0 188 - # https://gitlab.haskell.org/ghc/ghc/-/issues/22766 189 - (fetchpatch { 190 - name = "ghc-docs-sphinx-6.0.patch"; 191 - url = "https://gitlab.haskell.org/ghc/ghc/-/commit/10e94a556b4f90769b7fd718b9790d58ae566600.patch"; 192 - sha256 = "0kmhfamr16w8gch0lgln2912r8aryjky1hfcda3jkcwa5cdzgjdv"; 193 - }) 194 - # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 195 - ./docs-sphinx-7.patch 196 - # fix hyperlinked haddock sources: https://github.com/haskell/haddock/pull/1482 197 - (fetchpatch { 198 - url = "https://patch-diff.githubusercontent.com/raw/haskell/haddock/pull/1482.patch"; 199 - sha256 = "sha256-8w8QUCsODaTvknCDGgTfFNZa8ZmvIKaKS+2ZJZ9foYk="; 200 - extraPrefix = "utils/haddock/"; 201 - stripLen = 1; 202 - }) 203 - # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs 204 - # Can be removed if the Cabal library included with ghc backports the linked fix 205 - (fetchpatch { 206 - url = "https://github.com/haskell/cabal/commit/6c796218c92f93c95e94d5ec2d077f6956f68e98.patch"; 207 - stripLen = 1; 208 - extraPrefix = "libraries/Cabal/"; 209 - sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY="; 210 - }) 211 - ] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 212 - # Prevent the paths module from emitting symbols that we don't use 213 - # when building with separate outputs. 214 - # 215 - # These cause problems as they're not eliminated by GHC's dead code 216 - # elimination on aarch64-darwin. (see 217 - # https://github.com/NixOS/nixpkgs/issues/140774 for details). 218 - ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch 219 - ]; 220 - 221 - postPatch = "patchShebangs ."; 222 - 223 - # GHC needs the locale configured during the Haddock phase. 224 - LANG = "en_US.UTF-8"; 225 - 226 - # GHC is a bit confused on its cross terminology. 227 - # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 228 - preConfigure = '' 229 - for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 230 - export "''${env#TARGET_}=''${!env}" 231 - done 232 - # GHC is a bit confused on its cross terminology, as these would normally be 233 - # the *host* tools. 234 - export CC="${targetCC}/bin/${targetCC.targetPrefix}cc" 235 - export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++" 236 - # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 237 - export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}" 238 - export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as" 239 - export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar" 240 - export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" 241 - export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" 242 - export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" 243 - export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" 244 - '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 245 - export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" 246 - export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" 247 - '' + lib.optionalString useLLVM '' 248 - export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" 249 - export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" 250 - '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 251 - # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 252 - export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 253 - '' + '' 254 - echo -n "${buildMK}" > mk/build.mk 255 - '' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' 256 - export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" 257 - '' + lib.optionalString (!stdenv.isDarwin) '' 258 - export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 259 - '' + lib.optionalString stdenv.isDarwin '' 260 - export NIX_LDFLAGS+=" -no_dtrace_dof" 261 - 262 - # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 263 - export XATTR=${lib.getBin xattr}/bin/xattr 264 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 265 - 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 266 - '' + lib.optionalString targetPlatform.isMusl '' 267 - echo "patching llvm-targets for musl targets..." 268 - echo "Cloning these existing '*-linux-gnu*' targets:" 269 - grep linux-gnu llvm-targets | sed 's/^/ /' 270 - echo "(go go gadget sed)" 271 - sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 272 - echo "llvm-targets now contains these '*-linux-musl*' targets:" 273 - grep linux-musl llvm-targets | sed 's/^/ /' 274 - 275 - echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 276 - # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen) 277 - for x in configure aclocal.m4; do 278 - substituteInPlace $x \ 279 - --replace '*-android*|*-gnueabi*)' \ 280 - '*-android*|*-gnueabi*|*-musleabi*)' 281 - done 282 - ''; 283 - 284 - # TODO(@Ericson2314): Always pass "--target" and always prefix. 285 - configurePlatforms = [ "build" "host" ] 286 - ++ lib.optional (targetPlatform != hostPlatform) "target"; 287 - 288 - # `--with` flags for libraries needed for RTS linker 289 - configureFlags = [ 290 - "--datadir=$doc/share/doc/ghc" 291 - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" 292 - ] ++ lib.optionals (libffi != null) [ 293 - "--with-system-libffi" 294 - "--with-ffi-includes=${targetPackages.libffi.dev}/include" 295 - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" 296 - ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 297 - "--with-gmp-includes=${targetPackages.gmp.dev}/include" 298 - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" 299 - ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ 300 - "--with-iconv-includes=${libiconv}/include" 301 - "--with-iconv-libraries=${libiconv}/lib" 302 - ] ++ lib.optionals (targetPlatform != hostPlatform) [ 303 - "--enable-bootstrap-with-devel-snapshot" 304 - ] ++ lib.optionals useLdGold [ 305 - "CFLAGS=-fuse-ld=gold" 306 - "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 307 - "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 308 - ] ++ lib.optionals (disableLargeAddressSpace) [ 309 - "--disable-large-address-space" 310 - ]; 311 - 312 - # Make sure we never relax`$PATH` and hooks support for compatibility. 313 - strictDeps = true; 314 - 315 - # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 316 - dontAddExtraLibs = true; 317 - 318 - nativeBuildInputs = [ 319 - perl autoconf automake m4 python3 320 - ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour 321 - ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 322 - autoSignDarwinBinariesHook 323 - ] ++ lib.optionals enableDocs [ 324 - sphinx 325 - ]; 326 - 327 - # For building runtime libs 328 - depsBuildTarget = toolsForTarget; 329 - 330 - buildInputs = [ perl bash ] ++ (libDeps hostPlatform); 331 - 332 - depsTargetTarget = map lib.getDev (libDeps targetPlatform); 333 - depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); 334 - 335 - # required, because otherwise all symbols from HSffi.o are stripped, and 336 - # that in turn causes GHCi to abort 337 - stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 338 - 339 - checkTarget = "test"; 340 - 341 - hardeningDisable = 342 - [ "format" ] 343 - # In nixpkgs, musl based builds currently enable `pie` hardening by default 344 - # (see `defaultHardeningFlags` in `make-derivation.nix`). 345 - # But GHC cannot currently produce outputs that are ready for `-pie` linking. 346 - # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear. 347 - # See: 348 - # * https://github.com/NixOS/nixpkgs/issues/129247 349 - # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580 350 - ++ lib.optional stdenv.targetPlatform.isMusl "pie"; 351 - 352 - # big-parallel allows us to build with more than 2 cores on 353 - # Hydra which already warrants a significant speedup 354 - requiredSystemFeatures = [ "big-parallel" ]; 355 - 356 - postInstall = '' 357 - # Install the bash completion file. 358 - install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 359 - ''; 360 - 361 - passthru = { 362 - inherit bootPkgs targetPrefix; 363 - 364 - inherit llvmPackages; 365 - inherit enableShared; 366 - 367 - # This is used by the haskell builder to query 368 - # the presence of the haddock program. 369 - hasHaddock = enableHaddockProgram; 370 - 371 - # Our Cabal compiler name 372 - haskellCompilerName = "ghc-${version}"; 373 - }; 374 - 375 - meta = { 376 - homepage = "http://haskell.org/ghc"; 377 - description = "The Glasgow Haskell Compiler"; 378 - maintainers = with lib.maintainers; [ 379 - guibou 380 - ] ++ lib.teams.haskell.members; 381 - timeout = 24 * 3600; 382 - inherit (ghc.meta) license platforms; 383 - }; 384 - 385 - } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { 386 - dontStrip = true; 387 - dontPatchELF = true; 388 - noAuditTmpdir = true; 389 - }) 3 + sha256 = "0606797d1b38e2d88ee2243f38ec6b9a1aa93e9b578e95f0de9a9c0a4144021c"; 4 + }
+3 -388
pkgs/development/compilers/ghc/9.2.6.nix
··· 1 - { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 2 - 3 - # build-tools 4 - , bootPkgs 5 - , autoconf, automake, coreutils, fetchpatch, fetchurl, perl, python3, m4, sphinx 6 - , xattr, autoSignDarwinBinariesHook 7 - , bash 8 - 9 - , libiconv ? null, ncurses 10 - , glibcLocales ? null 11 - 12 - , # GHC can be built with system libffi or a bundled one. 13 - libffi ? null 14 - 15 - , useLLVM ? !(stdenv.targetPlatform.isx86 16 - || stdenv.targetPlatform.isPower 17 - || stdenv.targetPlatform.isSparc 18 - || stdenv.targetPlatform.isAarch64) 19 - , # LLVM is conceptually a run-time-only dependency, but for 20 - # non-x86, we need LLVM to bootstrap later stages, so it becomes a 21 - # build-time dependency too. 22 - buildTargetLlvmPackages, llvmPackages 23 - 24 - , # If enabled, GHC will be built with the GPL-free but slightly slower native 25 - # bignum backend instead of the faster but GPLed gmp backend. 26 - enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp 27 - && lib.meta.availableOn stdenv.targetPlatform gmp) 28 - , gmp 29 - 30 - , # If enabled, use -fPIC when compiling static libs. 31 - enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform 32 - 33 - , enableProfiledLibs ? true 34 - 35 - , # Whether to build dynamic libs for the standard library (on the target 36 - # platform). Static libs are always built. 37 - enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic 38 - 39 - , # Whether to build terminfo. 40 - enableTerminfo ? !stdenv.targetPlatform.isWindows 41 - 42 - , # What flavour to build. An empty string indicates no 43 - # specific flavour and falls back to ghc default values. 44 - ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 45 - (if useLLVM then "perf-cross" else "perf-cross-ncg") 46 - 47 - , # Whether to build sphinx documentation. 48 - enableDocs ? ( 49 - # Docs disabled if we are building on musl because it's a large task to keep 50 - # all `sphinx` dependencies building in this environment. 51 - !stdenv.buildPlatform.isMusl 52 - ) 53 - 54 - , enableHaddockProgram ? 55 - # Disabled for cross; see note [HADDOCK_DOCS]. 56 - (stdenv.targetPlatform == stdenv.hostPlatform) 57 - 58 - , # Whether to disable the large address space allocator 59 - # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 60 - disableLargeAddressSpace ? stdenv.targetPlatform.isiOS 61 - }: 62 - 63 - assert !enableNativeBignum -> gmp != null; 64 - 65 - # Cross cannot currently build the `haddock` program for silly reasons, 66 - # see note [HADDOCK_DOCS]. 67 - assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; 68 - 69 - let 70 - inherit (stdenv) buildPlatform hostPlatform targetPlatform; 71 - 72 - inherit (bootPkgs) ghc; 73 - 74 - # TODO(@Ericson2314) Make unconditional 75 - targetPrefix = lib.optionalString 76 - (targetPlatform != hostPlatform) 77 - "${targetPlatform.config}-"; 78 - 79 - buildMK = '' 80 - BuildFlavour = ${ghcFlavour} 81 - ifneq \"\$(BuildFlavour)\" \"\" 82 - include mk/flavours/\$(BuildFlavour).mk 83 - endif 84 - BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} 85 - BUILD_SPHINX_PDF = NO 86 - '' + 87 - # Note [HADDOCK_DOCS]: 88 - # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` 89 - # program is built (which we generally always want to have a complete GHC install) 90 - # and whether it is run on the GHC sources to generate hyperlinked source code 91 - # (which is impossible for cross-compilation); see: 92 - # https://gitlab.haskell.org/ghc/ghc/-/issues/20077 93 - # This implies that currently a cross-compiled GHC will never have a `haddock` 94 - # program, so it can never generate haddocks for any packages. 95 - # If this is solved in the future, we'd like to unconditionally 96 - # build the haddock program (removing the `enableHaddockProgram` option). 97 - '' 98 - HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"} 99 - # Build haddocks for boot packages with hyperlinking 100 - EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump 101 - 102 - DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} 103 - BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"} 104 - '' + lib.optionalString (targetPlatform != hostPlatform) '' 105 - Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"} 106 - CrossCompilePrefix = ${targetPrefix} 107 - '' + lib.optionalString (!enableProfiledLibs) '' 108 - BUILD_PROF_LIBS = NO 109 - '' + 110 - # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) 111 - # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. 112 - # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell 113 - lib.optionalString enableRelocatedStaticLibs '' 114 - GhcLibHcOpts += -fPIC -fexternal-dynamic-refs 115 - GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs 116 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 117 - EXTRA_CC_OPTS += -std=gnu99 118 - ''; 119 - 120 - # Splicer will pull out correct variations 121 - libDeps = platform: lib.optional enableTerminfo ncurses 122 - ++ [libffi] 123 - ++ lib.optional (!enableNativeBignum) gmp 124 - ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; 125 - 126 - # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 127 - # GHC doesn't seem to have {LLC,OPT}_HOST 128 - toolsForTarget = [ 129 - pkgsBuildTarget.targetPackages.stdenv.cc 130 - ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 131 - 132 - targetCC = builtins.head toolsForTarget; 133 - 134 - # Sometimes we have to dispatch between the bintools wrapper and the unwrapped 135 - # derivation for certain tools depending on the platform. 136 - bintoolsFor = { 137 - # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is 138 - # part of the bintools wrapper (due to codesigning requirements), but not on 139 - # x86_64-darwin. 140 - install_name_tool = 141 - if stdenv.targetPlatform.isAarch64 142 - then targetCC.bintools 143 - else targetCC.bintools.bintools; 144 - # Same goes for strip. 145 - strip = 146 - # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 147 - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin 148 - then targetCC.bintools 149 - else targetCC.bintools.bintools; 150 - }; 151 - 152 - # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 153 - # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 154 - # see #84670 and #49071 for more background. 155 - useLdGold = targetPlatform.linker == "gold" || 156 - (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); 157 - 158 - # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 159 - variantSuffix = lib.concatStrings [ 160 - (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 161 - (lib.optionalString enableNativeBignum "-native-bignum") 162 - ]; 163 - 164 - in 165 - 166 - # C compiler, bintools and LLVM are used at build time, but will also leak into 167 - # the resulting GHC's settings file and used at runtime. This means that we are 168 - # currently only able to build GHC if hostPlatform == buildPlatform. 169 - assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; 170 - assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; 171 - assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 172 - 173 - stdenv.mkDerivation (rec { 1 + import ./common-make-native-bignum.nix { 174 2 version = "9.2.6"; 175 - pname = "${targetPrefix}ghc${variantSuffix}"; 176 - 177 - src = fetchurl { 178 - url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"; 179 - sha256 = "7a54cf0398ad488b4ed219e15d1d1e64c0b6876c43a0564550dd11f0540d7305"; 180 - }; 181 - 182 - enableParallelBuilding = true; 183 - 184 - outputs = [ "out" "doc" ]; 185 - 186 - patches = [ 187 - # Fix docs build with sphinx >= 6.0 188 - # https://gitlab.haskell.org/ghc/ghc/-/issues/22766 189 - (fetchpatch { 190 - name = "ghc-docs-sphinx-6.0.patch"; 191 - url = "https://gitlab.haskell.org/ghc/ghc/-/commit/10e94a556b4f90769b7fd718b9790d58ae566600.patch"; 192 - sha256 = "0kmhfamr16w8gch0lgln2912r8aryjky1hfcda3jkcwa5cdzgjdv"; 193 - }) 194 - # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 195 - ./docs-sphinx-7.patch 196 - # fix hyperlinked haddock sources: https://github.com/haskell/haddock/pull/1482 197 - (fetchpatch { 198 - url = "https://patch-diff.githubusercontent.com/raw/haskell/haddock/pull/1482.patch"; 199 - sha256 = "sha256-8w8QUCsODaTvknCDGgTfFNZa8ZmvIKaKS+2ZJZ9foYk="; 200 - extraPrefix = "utils/haddock/"; 201 - stripLen = 1; 202 - }) 203 - # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs 204 - # Can be removed if the Cabal library included with ghc backports the linked fix 205 - (fetchpatch { 206 - url = "https://github.com/haskell/cabal/commit/6c796218c92f93c95e94d5ec2d077f6956f68e98.patch"; 207 - stripLen = 1; 208 - extraPrefix = "libraries/Cabal/"; 209 - sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY="; 210 - }) 211 - ] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 212 - # Prevent the paths module from emitting symbols that we don't use 213 - # when building with separate outputs. 214 - # 215 - # These cause problems as they're not eliminated by GHC's dead code 216 - # elimination on aarch64-darwin. (see 217 - # https://github.com/NixOS/nixpkgs/issues/140774 for details). 218 - ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch 219 - ]; 220 - 221 - postPatch = "patchShebangs ."; 222 - 223 - # GHC needs the locale configured during the Haddock phase. 224 - LANG = "en_US.UTF-8"; 225 - 226 - # GHC is a bit confused on its cross terminology. 227 - # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 228 - preConfigure = '' 229 - for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 230 - export "''${env#TARGET_}=''${!env}" 231 - done 232 - # GHC is a bit confused on its cross terminology, as these would normally be 233 - # the *host* tools. 234 - export CC="${targetCC}/bin/${targetCC.targetPrefix}cc" 235 - export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++" 236 - # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 237 - export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}" 238 - export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as" 239 - export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar" 240 - export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" 241 - export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" 242 - export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" 243 - export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" 244 - '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 245 - export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" 246 - export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" 247 - '' + lib.optionalString useLLVM '' 248 - export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" 249 - export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" 250 - '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 251 - # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 252 - export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 253 - '' + '' 254 - echo -n "${buildMK}" > mk/build.mk 255 - '' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' 256 - export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" 257 - '' + lib.optionalString (!stdenv.isDarwin) '' 258 - export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 259 - '' + lib.optionalString stdenv.isDarwin '' 260 - export NIX_LDFLAGS+=" -no_dtrace_dof" 261 - 262 - # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 263 - export XATTR=${lib.getBin xattr}/bin/xattr 264 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 265 - 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 266 - '' + lib.optionalString targetPlatform.isMusl '' 267 - echo "patching llvm-targets for musl targets..." 268 - echo "Cloning these existing '*-linux-gnu*' targets:" 269 - grep linux-gnu llvm-targets | sed 's/^/ /' 270 - echo "(go go gadget sed)" 271 - sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 272 - echo "llvm-targets now contains these '*-linux-musl*' targets:" 273 - grep linux-musl llvm-targets | sed 's/^/ /' 274 - 275 - echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 276 - # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen) 277 - for x in configure aclocal.m4; do 278 - substituteInPlace $x \ 279 - --replace '*-android*|*-gnueabi*)' \ 280 - '*-android*|*-gnueabi*|*-musleabi*)' 281 - done 282 - ''; 283 - 284 - # TODO(@Ericson2314): Always pass "--target" and always prefix. 285 - configurePlatforms = [ "build" "host" ] 286 - ++ lib.optional (targetPlatform != hostPlatform) "target"; 287 - 288 - # `--with` flags for libraries needed for RTS linker 289 - configureFlags = [ 290 - "--datadir=$doc/share/doc/ghc" 291 - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" 292 - ] ++ lib.optionals (libffi != null) [ 293 - "--with-system-libffi" 294 - "--with-ffi-includes=${targetPackages.libffi.dev}/include" 295 - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" 296 - ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 297 - "--with-gmp-includes=${targetPackages.gmp.dev}/include" 298 - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" 299 - ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ 300 - "--with-iconv-includes=${libiconv}/include" 301 - "--with-iconv-libraries=${libiconv}/lib" 302 - ] ++ lib.optionals (targetPlatform != hostPlatform) [ 303 - "--enable-bootstrap-with-devel-snapshot" 304 - ] ++ lib.optionals useLdGold [ 305 - "CFLAGS=-fuse-ld=gold" 306 - "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 307 - "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 308 - ] ++ lib.optionals (disableLargeAddressSpace) [ 309 - "--disable-large-address-space" 310 - ]; 311 - 312 - # Make sure we never relax`$PATH` and hooks support for compatibility. 313 - strictDeps = true; 314 - 315 - # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 316 - dontAddExtraLibs = true; 317 - 318 - nativeBuildInputs = [ 319 - perl autoconf automake m4 python3 320 - ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour 321 - ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 322 - autoSignDarwinBinariesHook 323 - ] ++ lib.optionals enableDocs [ 324 - sphinx 325 - ]; 326 - 327 - # For building runtime libs 328 - depsBuildTarget = toolsForTarget; 329 - 330 - buildInputs = [ perl bash ] ++ (libDeps hostPlatform); 331 - 332 - depsTargetTarget = map lib.getDev (libDeps targetPlatform); 333 - depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); 334 - 335 - # required, because otherwise all symbols from HSffi.o are stripped, and 336 - # that in turn causes GHCi to abort 337 - stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 338 - 339 - checkTarget = "test"; 340 - 341 - hardeningDisable = 342 - [ "format" ] 343 - # In nixpkgs, musl based builds currently enable `pie` hardening by default 344 - # (see `defaultHardeningFlags` in `make-derivation.nix`). 345 - # But GHC cannot currently produce outputs that are ready for `-pie` linking. 346 - # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear. 347 - # See: 348 - # * https://github.com/NixOS/nixpkgs/issues/129247 349 - # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580 350 - ++ lib.optional stdenv.targetPlatform.isMusl "pie"; 351 - 352 - # big-parallel allows us to build with more than 2 cores on 353 - # Hydra which already warrants a significant speedup 354 - requiredSystemFeatures = [ "big-parallel" ]; 355 - 356 - postInstall = '' 357 - # Install the bash completion file. 358 - install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 359 - ''; 360 - 361 - passthru = { 362 - inherit bootPkgs targetPrefix; 363 - 364 - inherit llvmPackages; 365 - inherit enableShared; 366 - 367 - # This is used by the haskell builder to query 368 - # the presence of the haddock program. 369 - hasHaddock = enableHaddockProgram; 370 - 371 - # Our Cabal compiler name 372 - haskellCompilerName = "ghc-${version}"; 373 - }; 374 - 375 - meta = { 376 - homepage = "http://haskell.org/ghc"; 377 - description = "The Glasgow Haskell Compiler"; 378 - maintainers = with lib.maintainers; [ 379 - guibou 380 - ] ++ lib.teams.haskell.members; 381 - timeout = 24 * 3600; 382 - inherit (ghc.meta) license platforms; 383 - }; 384 - 385 - } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { 386 - dontStrip = true; 387 - dontPatchELF = true; 388 - noAuditTmpdir = true; 389 - }) 3 + sha256 = "7a54cf0398ad488b4ed219e15d1d1e64c0b6876c43a0564550dd11f0540d7305"; 4 + }
+3 -388
pkgs/development/compilers/ghc/9.2.7.nix
··· 1 - { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 2 - 3 - # build-tools 4 - , bootPkgs 5 - , autoconf, automake, coreutils, fetchpatch, fetchurl, perl, python3, m4, sphinx 6 - , xattr, autoSignDarwinBinariesHook 7 - , bash 8 - 9 - , libiconv ? null, ncurses 10 - , glibcLocales ? null 11 - 12 - , # GHC can be built with system libffi or a bundled one. 13 - libffi ? null 14 - 15 - , useLLVM ? !(stdenv.targetPlatform.isx86 16 - || stdenv.targetPlatform.isPower 17 - || stdenv.targetPlatform.isSparc 18 - || stdenv.targetPlatform.isAarch64) 19 - , # LLVM is conceptually a run-time-only dependency, but for 20 - # non-x86, we need LLVM to bootstrap later stages, so it becomes a 21 - # build-time dependency too. 22 - buildTargetLlvmPackages, llvmPackages 23 - 24 - , # If enabled, GHC will be built with the GPL-free but slightly slower native 25 - # bignum backend instead of the faster but GPLed gmp backend. 26 - enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp 27 - && lib.meta.availableOn stdenv.targetPlatform gmp) 28 - , gmp 29 - 30 - , # If enabled, use -fPIC when compiling static libs. 31 - enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform 32 - 33 - , enableProfiledLibs ? true 34 - 35 - , # Whether to build dynamic libs for the standard library (on the target 36 - # platform). Static libs are always built. 37 - enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic 38 - 39 - , # Whether to build terminfo. 40 - enableTerminfo ? !stdenv.targetPlatform.isWindows 41 - 42 - , # What flavour to build. An empty string indicates no 43 - # specific flavour and falls back to ghc default values. 44 - ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 45 - (if useLLVM then "perf-cross" else "perf-cross-ncg") 46 - 47 - , # Whether to build sphinx documentation. 48 - enableDocs ? ( 49 - # Docs disabled if we are building on musl because it's a large task to keep 50 - # all `sphinx` dependencies building in this environment. 51 - !stdenv.buildPlatform.isMusl 52 - ) 53 - 54 - , enableHaddockProgram ? 55 - # Disabled for cross; see note [HADDOCK_DOCS]. 56 - (stdenv.targetPlatform == stdenv.hostPlatform) 57 - 58 - , # Whether to disable the large address space allocator 59 - # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 60 - disableLargeAddressSpace ? stdenv.targetPlatform.isiOS 61 - }: 62 - 63 - assert !enableNativeBignum -> gmp != null; 64 - 65 - # Cross cannot currently build the `haddock` program for silly reasons, 66 - # see note [HADDOCK_DOCS]. 67 - assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; 68 - 69 - let 70 - inherit (stdenv) buildPlatform hostPlatform targetPlatform; 71 - 72 - inherit (bootPkgs) ghc; 73 - 74 - # TODO(@Ericson2314) Make unconditional 75 - targetPrefix = lib.optionalString 76 - (targetPlatform != hostPlatform) 77 - "${targetPlatform.config}-"; 78 - 79 - buildMK = '' 80 - BuildFlavour = ${ghcFlavour} 81 - ifneq \"\$(BuildFlavour)\" \"\" 82 - include mk/flavours/\$(BuildFlavour).mk 83 - endif 84 - BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} 85 - BUILD_SPHINX_PDF = NO 86 - '' + 87 - # Note [HADDOCK_DOCS]: 88 - # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` 89 - # program is built (which we generally always want to have a complete GHC install) 90 - # and whether it is run on the GHC sources to generate hyperlinked source code 91 - # (which is impossible for cross-compilation); see: 92 - # https://gitlab.haskell.org/ghc/ghc/-/issues/20077 93 - # This implies that currently a cross-compiled GHC will never have a `haddock` 94 - # program, so it can never generate haddocks for any packages. 95 - # If this is solved in the future, we'd like to unconditionally 96 - # build the haddock program (removing the `enableHaddockProgram` option). 97 - '' 98 - HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"} 99 - # Build haddocks for boot packages with hyperlinking 100 - EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump 101 - 102 - DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} 103 - BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"} 104 - '' + lib.optionalString (targetPlatform != hostPlatform) '' 105 - Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"} 106 - CrossCompilePrefix = ${targetPrefix} 107 - '' + lib.optionalString (!enableProfiledLibs) '' 108 - BUILD_PROF_LIBS = NO 109 - '' + 110 - # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) 111 - # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. 112 - # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell 113 - lib.optionalString enableRelocatedStaticLibs '' 114 - GhcLibHcOpts += -fPIC -fexternal-dynamic-refs 115 - GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs 116 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 117 - EXTRA_CC_OPTS += -std=gnu99 118 - ''; 119 - 120 - # Splicer will pull out correct variations 121 - libDeps = platform: lib.optional enableTerminfo ncurses 122 - ++ [libffi] 123 - ++ lib.optional (!enableNativeBignum) gmp 124 - ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; 125 - 126 - # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 127 - # GHC doesn't seem to have {LLC,OPT}_HOST 128 - toolsForTarget = [ 129 - pkgsBuildTarget.targetPackages.stdenv.cc 130 - ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 131 - 132 - targetCC = builtins.head toolsForTarget; 133 - 134 - # Sometimes we have to dispatch between the bintools wrapper and the unwrapped 135 - # derivation for certain tools depending on the platform. 136 - bintoolsFor = { 137 - # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is 138 - # part of the bintools wrapper (due to codesigning requirements), but not on 139 - # x86_64-darwin. 140 - install_name_tool = 141 - if stdenv.targetPlatform.isAarch64 142 - then targetCC.bintools 143 - else targetCC.bintools.bintools; 144 - # Same goes for strip. 145 - strip = 146 - # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 147 - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin 148 - then targetCC.bintools 149 - else targetCC.bintools.bintools; 150 - }; 151 - 152 - # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 153 - # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 154 - # see #84670 and #49071 for more background. 155 - useLdGold = targetPlatform.linker == "gold" || 156 - (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); 157 - 158 - # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 159 - variantSuffix = lib.concatStrings [ 160 - (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 161 - (lib.optionalString enableNativeBignum "-native-bignum") 162 - ]; 163 - 164 - in 165 - 166 - # C compiler, bintools and LLVM are used at build time, but will also leak into 167 - # the resulting GHC's settings file and used at runtime. This means that we are 168 - # currently only able to build GHC if hostPlatform == buildPlatform. 169 - assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; 170 - assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; 171 - assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 172 - 173 - stdenv.mkDerivation (rec { 1 + import ./common-make-native-bignum.nix { 174 2 version = "9.2.7"; 175 - pname = "${targetPrefix}ghc${variantSuffix}"; 176 - 177 - src = fetchurl { 178 - url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"; 179 - sha256 = "a253567a17b734a4c0dd0ffa296d33c2a5b5a54a77df988806a2a1e1ca7e88b8"; 180 - }; 181 - 182 - enableParallelBuilding = true; 183 - 184 - outputs = [ "out" "doc" ]; 185 - 186 - patches = [ 187 - # Fix docs build with sphinx >= 6.0 188 - # https://gitlab.haskell.org/ghc/ghc/-/issues/22766 189 - (fetchpatch { 190 - name = "ghc-docs-sphinx-6.0.patch"; 191 - url = "https://gitlab.haskell.org/ghc/ghc/-/commit/10e94a556b4f90769b7fd718b9790d58ae566600.patch"; 192 - sha256 = "0kmhfamr16w8gch0lgln2912r8aryjky1hfcda3jkcwa5cdzgjdv"; 193 - }) 194 - # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 195 - ./docs-sphinx-7.patch 196 - # fix hyperlinked haddock sources: https://github.com/haskell/haddock/pull/1482 197 - (fetchpatch { 198 - url = "https://patch-diff.githubusercontent.com/raw/haskell/haddock/pull/1482.patch"; 199 - sha256 = "sha256-8w8QUCsODaTvknCDGgTfFNZa8ZmvIKaKS+2ZJZ9foYk="; 200 - extraPrefix = "utils/haddock/"; 201 - stripLen = 1; 202 - }) 203 - # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs 204 - # Can be removed if the Cabal library included with ghc backports the linked fix 205 - (fetchpatch { 206 - url = "https://github.com/haskell/cabal/commit/6c796218c92f93c95e94d5ec2d077f6956f68e98.patch"; 207 - stripLen = 1; 208 - extraPrefix = "libraries/Cabal/"; 209 - sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY="; 210 - }) 211 - ] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 212 - # Prevent the paths module from emitting symbols that we don't use 213 - # when building with separate outputs. 214 - # 215 - # These cause problems as they're not eliminated by GHC's dead code 216 - # elimination on aarch64-darwin. (see 217 - # https://github.com/NixOS/nixpkgs/issues/140774 for details). 218 - ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch 219 - ]; 220 - 221 - postPatch = "patchShebangs ."; 222 - 223 - # GHC needs the locale configured during the Haddock phase. 224 - LANG = "en_US.UTF-8"; 225 - 226 - # GHC is a bit confused on its cross terminology. 227 - # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 228 - preConfigure = '' 229 - for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 230 - export "''${env#TARGET_}=''${!env}" 231 - done 232 - # GHC is a bit confused on its cross terminology, as these would normally be 233 - # the *host* tools. 234 - export CC="${targetCC}/bin/${targetCC.targetPrefix}cc" 235 - export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++" 236 - # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 237 - export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}" 238 - export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as" 239 - export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar" 240 - export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" 241 - export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" 242 - export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" 243 - export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" 244 - '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 245 - export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" 246 - export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" 247 - '' + lib.optionalString useLLVM '' 248 - export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" 249 - export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" 250 - '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 251 - # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 252 - export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 253 - '' + '' 254 - echo -n "${buildMK}" > mk/build.mk 255 - '' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' 256 - export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" 257 - '' + lib.optionalString (!stdenv.isDarwin) '' 258 - export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 259 - '' + lib.optionalString stdenv.isDarwin '' 260 - export NIX_LDFLAGS+=" -no_dtrace_dof" 261 - 262 - # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 263 - export XATTR=${lib.getBin xattr}/bin/xattr 264 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 265 - 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 266 - '' + lib.optionalString targetPlatform.isMusl '' 267 - echo "patching llvm-targets for musl targets..." 268 - echo "Cloning these existing '*-linux-gnu*' targets:" 269 - grep linux-gnu llvm-targets | sed 's/^/ /' 270 - echo "(go go gadget sed)" 271 - sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 272 - echo "llvm-targets now contains these '*-linux-musl*' targets:" 273 - grep linux-musl llvm-targets | sed 's/^/ /' 274 - 275 - echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 276 - # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen) 277 - for x in configure aclocal.m4; do 278 - substituteInPlace $x \ 279 - --replace '*-android*|*-gnueabi*)' \ 280 - '*-android*|*-gnueabi*|*-musleabi*)' 281 - done 282 - ''; 283 - 284 - # TODO(@Ericson2314): Always pass "--target" and always prefix. 285 - configurePlatforms = [ "build" "host" ] 286 - ++ lib.optional (targetPlatform != hostPlatform) "target"; 287 - 288 - # `--with` flags for libraries needed for RTS linker 289 - configureFlags = [ 290 - "--datadir=$doc/share/doc/ghc" 291 - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" 292 - ] ++ lib.optionals (libffi != null) [ 293 - "--with-system-libffi" 294 - "--with-ffi-includes=${targetPackages.libffi.dev}/include" 295 - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" 296 - ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 297 - "--with-gmp-includes=${targetPackages.gmp.dev}/include" 298 - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" 299 - ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ 300 - "--with-iconv-includes=${libiconv}/include" 301 - "--with-iconv-libraries=${libiconv}/lib" 302 - ] ++ lib.optionals (targetPlatform != hostPlatform) [ 303 - "--enable-bootstrap-with-devel-snapshot" 304 - ] ++ lib.optionals useLdGold [ 305 - "CFLAGS=-fuse-ld=gold" 306 - "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 307 - "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 308 - ] ++ lib.optionals (disableLargeAddressSpace) [ 309 - "--disable-large-address-space" 310 - ]; 311 - 312 - # Make sure we never relax`$PATH` and hooks support for compatibility. 313 - strictDeps = true; 314 - 315 - # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 316 - dontAddExtraLibs = true; 317 - 318 - nativeBuildInputs = [ 319 - perl autoconf automake m4 python3 320 - ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour 321 - ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 322 - autoSignDarwinBinariesHook 323 - ] ++ lib.optionals enableDocs [ 324 - sphinx 325 - ]; 326 - 327 - # For building runtime libs 328 - depsBuildTarget = toolsForTarget; 329 - 330 - buildInputs = [ perl bash ] ++ (libDeps hostPlatform); 331 - 332 - depsTargetTarget = map lib.getDev (libDeps targetPlatform); 333 - depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); 334 - 335 - # required, because otherwise all symbols from HSffi.o are stripped, and 336 - # that in turn causes GHCi to abort 337 - stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 338 - 339 - checkTarget = "test"; 340 - 341 - hardeningDisable = 342 - [ "format" ] 343 - # In nixpkgs, musl based builds currently enable `pie` hardening by default 344 - # (see `defaultHardeningFlags` in `make-derivation.nix`). 345 - # But GHC cannot currently produce outputs that are ready for `-pie` linking. 346 - # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear. 347 - # See: 348 - # * https://github.com/NixOS/nixpkgs/issues/129247 349 - # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580 350 - ++ lib.optional stdenv.targetPlatform.isMusl "pie"; 351 - 352 - # big-parallel allows us to build with more than 2 cores on 353 - # Hydra which already warrants a significant speedup 354 - requiredSystemFeatures = [ "big-parallel" ]; 355 - 356 - postInstall = '' 357 - # Install the bash completion file. 358 - install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 359 - ''; 360 - 361 - passthru = { 362 - inherit bootPkgs targetPrefix; 363 - 364 - inherit llvmPackages; 365 - inherit enableShared; 366 - 367 - # This is used by the haskell builder to query 368 - # the presence of the haddock program. 369 - hasHaddock = enableHaddockProgram; 370 - 371 - # Our Cabal compiler name 372 - haskellCompilerName = "ghc-${version}"; 373 - }; 374 - 375 - meta = { 376 - homepage = "http://haskell.org/ghc"; 377 - description = "The Glasgow Haskell Compiler"; 378 - maintainers = with lib.maintainers; [ 379 - guibou 380 - ] ++ lib.teams.haskell.members; 381 - timeout = 24 * 3600; 382 - inherit (ghc.meta) license platforms; 383 - }; 384 - 385 - } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { 386 - dontStrip = true; 387 - dontPatchELF = true; 388 - noAuditTmpdir = true; 389 - }) 3 + sha256 = "a253567a17b734a4c0dd0ffa296d33c2a5b5a54a77df988806a2a1e1ca7e88b8"; 4 + }
+3 -388
pkgs/development/compilers/ghc/9.2.8.nix
··· 1 - { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 2 - 3 - # build-tools 4 - , bootPkgs 5 - , autoconf, automake, coreutils, fetchpatch, fetchurl, perl, python3, m4, sphinx 6 - , xattr, autoSignDarwinBinariesHook 7 - , bash 8 - 9 - , libiconv ? null, ncurses 10 - , glibcLocales ? null 11 - 12 - , # GHC can be built with system libffi or a bundled one. 13 - libffi ? null 14 - 15 - , useLLVM ? !(stdenv.targetPlatform.isx86 16 - || stdenv.targetPlatform.isPower 17 - || stdenv.targetPlatform.isSparc 18 - || stdenv.targetPlatform.isAarch64) 19 - , # LLVM is conceptually a run-time-only dependency, but for 20 - # non-x86, we need LLVM to bootstrap later stages, so it becomes a 21 - # build-time dependency too. 22 - buildTargetLlvmPackages, llvmPackages 23 - 24 - , # If enabled, GHC will be built with the GPL-free but slightly slower native 25 - # bignum backend instead of the faster but GPLed gmp backend. 26 - enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp 27 - && lib.meta.availableOn stdenv.targetPlatform gmp) 28 - , gmp 29 - 30 - , # If enabled, use -fPIC when compiling static libs. 31 - enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform 32 - 33 - , enableProfiledLibs ? true 34 - 35 - , # Whether to build dynamic libs for the standard library (on the target 36 - # platform). Static libs are always built. 37 - enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic 38 - 39 - , # Whether to build terminfo. 40 - enableTerminfo ? !stdenv.targetPlatform.isWindows 41 - 42 - , # What flavour to build. An empty string indicates no 43 - # specific flavour and falls back to ghc default values. 44 - ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 45 - (if useLLVM then "perf-cross" else "perf-cross-ncg") 46 - 47 - , # Whether to build sphinx documentation. 48 - enableDocs ? ( 49 - # Docs disabled if we are building on musl because it's a large task to keep 50 - # all `sphinx` dependencies building in this environment. 51 - !stdenv.buildPlatform.isMusl 52 - ) 53 - 54 - , enableHaddockProgram ? 55 - # Disabled for cross; see note [HADDOCK_DOCS]. 56 - (stdenv.targetPlatform == stdenv.hostPlatform) 57 - 58 - , # Whether to disable the large address space allocator 59 - # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 60 - disableLargeAddressSpace ? stdenv.targetPlatform.isiOS 61 - }: 62 - 63 - assert !enableNativeBignum -> gmp != null; 64 - 65 - # Cross cannot currently build the `haddock` program for silly reasons, 66 - # see note [HADDOCK_DOCS]. 67 - assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; 68 - 69 - let 70 - inherit (stdenv) buildPlatform hostPlatform targetPlatform; 71 - 72 - inherit (bootPkgs) ghc; 73 - 74 - # TODO(@Ericson2314) Make unconditional 75 - targetPrefix = lib.optionalString 76 - (targetPlatform != hostPlatform) 77 - "${targetPlatform.config}-"; 78 - 79 - buildMK = '' 80 - BuildFlavour = ${ghcFlavour} 81 - ifneq \"\$(BuildFlavour)\" \"\" 82 - include mk/flavours/\$(BuildFlavour).mk 83 - endif 84 - BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} 85 - BUILD_SPHINX_PDF = NO 86 - '' + 87 - # Note [HADDOCK_DOCS]: 88 - # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` 89 - # program is built (which we generally always want to have a complete GHC install) 90 - # and whether it is run on the GHC sources to generate hyperlinked source code 91 - # (which is impossible for cross-compilation); see: 92 - # https://gitlab.haskell.org/ghc/ghc/-/issues/20077 93 - # This implies that currently a cross-compiled GHC will never have a `haddock` 94 - # program, so it can never generate haddocks for any packages. 95 - # If this is solved in the future, we'd like to unconditionally 96 - # build the haddock program (removing the `enableHaddockProgram` option). 97 - '' 98 - HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"} 99 - # Build haddocks for boot packages with hyperlinking 100 - EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump 101 - 102 - DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} 103 - BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"} 104 - '' + lib.optionalString (targetPlatform != hostPlatform) '' 105 - Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"} 106 - CrossCompilePrefix = ${targetPrefix} 107 - '' + lib.optionalString (!enableProfiledLibs) '' 108 - BUILD_PROF_LIBS = NO 109 - '' + 110 - # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) 111 - # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. 112 - # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell 113 - lib.optionalString enableRelocatedStaticLibs '' 114 - GhcLibHcOpts += -fPIC -fexternal-dynamic-refs 115 - GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs 116 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 117 - EXTRA_CC_OPTS += -std=gnu99 118 - ''; 119 - 120 - # Splicer will pull out correct variations 121 - libDeps = platform: lib.optional enableTerminfo ncurses 122 - ++ [libffi] 123 - ++ lib.optional (!enableNativeBignum) gmp 124 - ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; 125 - 126 - # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 127 - # GHC doesn't seem to have {LLC,OPT}_HOST 128 - toolsForTarget = [ 129 - pkgsBuildTarget.targetPackages.stdenv.cc 130 - ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 131 - 132 - targetCC = builtins.head toolsForTarget; 133 - 134 - # Sometimes we have to dispatch between the bintools wrapper and the unwrapped 135 - # derivation for certain tools depending on the platform. 136 - bintoolsFor = { 137 - # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is 138 - # part of the bintools wrapper (due to codesigning requirements), but not on 139 - # x86_64-darwin. 140 - install_name_tool = 141 - if stdenv.targetPlatform.isAarch64 142 - then targetCC.bintools 143 - else targetCC.bintools.bintools; 144 - # Same goes for strip. 145 - strip = 146 - # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 147 - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin 148 - then targetCC.bintools 149 - else targetCC.bintools.bintools; 150 - }; 151 - 152 - # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 153 - # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 154 - # see #84670 and #49071 for more background. 155 - useLdGold = targetPlatform.linker == "gold" || 156 - (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); 157 - 158 - # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 159 - variantSuffix = lib.concatStrings [ 160 - (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 161 - (lib.optionalString enableNativeBignum "-native-bignum") 162 - ]; 163 - 164 - in 165 - 166 - # C compiler, bintools and LLVM are used at build time, but will also leak into 167 - # the resulting GHC's settings file and used at runtime. This means that we are 168 - # currently only able to build GHC if hostPlatform == buildPlatform. 169 - assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; 170 - assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; 171 - assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 172 - 173 - stdenv.mkDerivation (rec { 1 + import ./common-make-native-bignum.nix { 174 2 version = "9.2.8"; 175 - pname = "${targetPrefix}ghc${variantSuffix}"; 176 - 177 - src = fetchurl { 178 - url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"; 179 - sha256 = "sha256-XxPReGv0/RL0tF+qN6vttbs/NtXlj32lMH6L/oilZ6E="; 180 - }; 181 - 182 - enableParallelBuilding = true; 183 - 184 - outputs = [ "out" "doc" ]; 185 - 186 - patches = [ 187 - # Fix docs build with sphinx >= 6.0 188 - # https://gitlab.haskell.org/ghc/ghc/-/issues/22766 189 - (fetchpatch { 190 - name = "ghc-docs-sphinx-6.0.patch"; 191 - url = "https://gitlab.haskell.org/ghc/ghc/-/commit/10e94a556b4f90769b7fd718b9790d58ae566600.patch"; 192 - sha256 = "0kmhfamr16w8gch0lgln2912r8aryjky1hfcda3jkcwa5cdzgjdv"; 193 - }) 194 - # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 195 - ./docs-sphinx-7.patch 196 - # fix hyperlinked haddock sources: https://github.com/haskell/haddock/pull/1482 197 - (fetchpatch { 198 - url = "https://patch-diff.githubusercontent.com/raw/haskell/haddock/pull/1482.patch"; 199 - sha256 = "sha256-8w8QUCsODaTvknCDGgTfFNZa8ZmvIKaKS+2ZJZ9foYk="; 200 - extraPrefix = "utils/haddock/"; 201 - stripLen = 1; 202 - }) 203 - # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs 204 - # Can be removed if the Cabal library included with ghc backports the linked fix 205 - (fetchpatch { 206 - url = "https://github.com/haskell/cabal/commit/6c796218c92f93c95e94d5ec2d077f6956f68e98.patch"; 207 - stripLen = 1; 208 - extraPrefix = "libraries/Cabal/"; 209 - sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY="; 210 - }) 211 - ] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 212 - # Prevent the paths module from emitting symbols that we don't use 213 - # when building with separate outputs. 214 - # 215 - # These cause problems as they're not eliminated by GHC's dead code 216 - # elimination on aarch64-darwin. (see 217 - # https://github.com/NixOS/nixpkgs/issues/140774 for details). 218 - ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch 219 - ]; 220 - 221 - postPatch = "patchShebangs ."; 222 - 223 - # GHC needs the locale configured during the Haddock phase. 224 - LANG = "en_US.UTF-8"; 225 - 226 - # GHC is a bit confused on its cross terminology. 227 - # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 228 - preConfigure = '' 229 - for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 230 - export "''${env#TARGET_}=''${!env}" 231 - done 232 - # GHC is a bit confused on its cross terminology, as these would normally be 233 - # the *host* tools. 234 - export CC="${targetCC}/bin/${targetCC.targetPrefix}cc" 235 - export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++" 236 - # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 237 - export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}" 238 - export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as" 239 - export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar" 240 - export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" 241 - export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" 242 - export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" 243 - export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" 244 - '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 245 - export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" 246 - export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" 247 - '' + lib.optionalString useLLVM '' 248 - export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" 249 - export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" 250 - '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 251 - # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 252 - export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 253 - '' + '' 254 - echo -n "${buildMK}" > mk/build.mk 255 - '' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' 256 - export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" 257 - '' + lib.optionalString (!stdenv.isDarwin) '' 258 - export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 259 - '' + lib.optionalString stdenv.isDarwin '' 260 - export NIX_LDFLAGS+=" -no_dtrace_dof" 261 - 262 - # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 263 - export XATTR=${lib.getBin xattr}/bin/xattr 264 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 265 - 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 266 - '' + lib.optionalString targetPlatform.isMusl '' 267 - echo "patching llvm-targets for musl targets..." 268 - echo "Cloning these existing '*-linux-gnu*' targets:" 269 - grep linux-gnu llvm-targets | sed 's/^/ /' 270 - echo "(go go gadget sed)" 271 - sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 272 - echo "llvm-targets now contains these '*-linux-musl*' targets:" 273 - grep linux-musl llvm-targets | sed 's/^/ /' 274 - 275 - echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 276 - # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen) 277 - for x in configure aclocal.m4; do 278 - substituteInPlace $x \ 279 - --replace '*-android*|*-gnueabi*)' \ 280 - '*-android*|*-gnueabi*|*-musleabi*)' 281 - done 282 - ''; 283 - 284 - # TODO(@Ericson2314): Always pass "--target" and always prefix. 285 - configurePlatforms = [ "build" "host" ] 286 - ++ lib.optional (targetPlatform != hostPlatform) "target"; 287 - 288 - # `--with` flags for libraries needed for RTS linker 289 - configureFlags = [ 290 - "--datadir=$doc/share/doc/ghc" 291 - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" 292 - ] ++ lib.optionals (libffi != null) [ 293 - "--with-system-libffi" 294 - "--with-ffi-includes=${targetPackages.libffi.dev}/include" 295 - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" 296 - ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 297 - "--with-gmp-includes=${targetPackages.gmp.dev}/include" 298 - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" 299 - ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ 300 - "--with-iconv-includes=${libiconv}/include" 301 - "--with-iconv-libraries=${libiconv}/lib" 302 - ] ++ lib.optionals (targetPlatform != hostPlatform) [ 303 - "--enable-bootstrap-with-devel-snapshot" 304 - ] ++ lib.optionals useLdGold [ 305 - "CFLAGS=-fuse-ld=gold" 306 - "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 307 - "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 308 - ] ++ lib.optionals (disableLargeAddressSpace) [ 309 - "--disable-large-address-space" 310 - ]; 311 - 312 - # Make sure we never relax`$PATH` and hooks support for compatibility. 313 - strictDeps = true; 314 - 315 - # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 316 - dontAddExtraLibs = true; 317 - 318 - nativeBuildInputs = [ 319 - perl autoconf automake m4 python3 320 - ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour 321 - ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 322 - autoSignDarwinBinariesHook 323 - ] ++ lib.optionals enableDocs [ 324 - sphinx 325 - ]; 326 - 327 - # For building runtime libs 328 - depsBuildTarget = toolsForTarget; 329 - 330 - buildInputs = [ perl bash ] ++ (libDeps hostPlatform); 331 - 332 - depsTargetTarget = map lib.getDev (libDeps targetPlatform); 333 - depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); 334 - 335 - # required, because otherwise all symbols from HSffi.o are stripped, and 336 - # that in turn causes GHCi to abort 337 - stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 338 - 339 - checkTarget = "test"; 340 - 341 - hardeningDisable = 342 - [ "format" ] 343 - # In nixpkgs, musl based builds currently enable `pie` hardening by default 344 - # (see `defaultHardeningFlags` in `make-derivation.nix`). 345 - # But GHC cannot currently produce outputs that are ready for `-pie` linking. 346 - # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear. 347 - # See: 348 - # * https://github.com/NixOS/nixpkgs/issues/129247 349 - # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580 350 - ++ lib.optional stdenv.targetPlatform.isMusl "pie"; 351 - 352 - # big-parallel allows us to build with more than 2 cores on 353 - # Hydra which already warrants a significant speedup 354 - requiredSystemFeatures = [ "big-parallel" ]; 355 - 356 - postInstall = '' 357 - # Install the bash completion file. 358 - install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 359 - ''; 360 - 361 - passthru = { 362 - inherit bootPkgs targetPrefix; 363 - 364 - inherit llvmPackages; 365 - inherit enableShared; 366 - 367 - # This is used by the haskell builder to query 368 - # the presence of the haddock program. 369 - hasHaddock = enableHaddockProgram; 370 - 371 - # Our Cabal compiler name 372 - haskellCompilerName = "ghc-${version}"; 373 - }; 374 - 375 - meta = { 376 - homepage = "http://haskell.org/ghc"; 377 - description = "The Glasgow Haskell Compiler"; 378 - maintainers = with lib.maintainers; [ 379 - guibou 380 - ] ++ lib.teams.haskell.members; 381 - timeout = 24 * 3600; 382 - inherit (ghc.meta) license platforms; 383 - }; 384 - 385 - } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { 386 - dontStrip = true; 387 - dontPatchELF = true; 388 - noAuditTmpdir = true; 389 - }) 3 + sha256 = "sha256-XxPReGv0/RL0tF+qN6vttbs/NtXlj32lMH6L/oilZ6E="; 4 + }
+3 -393
pkgs/development/compilers/ghc/9.4.5.nix
··· 1 1 # DO NOT port this expression to hadrian. It is not possible to build a GHC 2 2 # cross compiler with 9.4.* and hadrian. 3 - { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 4 - 5 - # build-tools 6 - , bootPkgs 7 - , autoconf, automake, coreutils, fetchpatch, fetchurl, perl, python3, m4, sphinx 8 - , xattr, autoSignDarwinBinariesHook 9 - , bash 10 - 11 - , libiconv ? null, ncurses 12 - , glibcLocales ? null 13 - 14 - , # GHC can be built with system libffi or a bundled one. 15 - libffi ? null 16 - 17 - , useLLVM ? !(stdenv.targetPlatform.isx86 18 - || stdenv.targetPlatform.isPower 19 - || stdenv.targetPlatform.isSparc 20 - || stdenv.targetPlatform.isAarch64) 21 - , # LLVM is conceptually a run-time-only dependency, but for 22 - # non-x86, we need LLVM to bootstrap later stages, so it becomes a 23 - # build-time dependency too. 24 - buildTargetLlvmPackages, llvmPackages 25 - 26 - , # If enabled, GHC will be built with the GPL-free but slightly slower native 27 - # bignum backend instead of the faster but GPLed gmp backend. 28 - enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp 29 - && lib.meta.availableOn stdenv.targetPlatform gmp) 30 - , gmp 31 - 32 - , # If enabled, use -fPIC when compiling static libs. 33 - enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform 34 - 35 - , enableProfiledLibs ? true 36 - 37 - , # Whether to build dynamic libs for the standard library (on the target 38 - # platform). Static libs are always built. 39 - enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic 40 - 41 - , # Whether to build terminfo. 42 - enableTerminfo ? !stdenv.targetPlatform.isWindows 43 - 44 - , # What flavour to build. An empty string indicates no 45 - # specific flavour and falls back to ghc default values. 46 - ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 47 - (if useLLVM then "perf-cross" else "perf-cross-ncg") 48 - 49 - , # Whether to build sphinx documentation. 50 - enableDocs ? ( 51 - # Docs disabled if we are building on musl because it's a large task to keep 52 - # all `sphinx` dependencies building in this environment. 53 - !stdenv.buildPlatform.isMusl 54 - ) 55 - 56 - , enableHaddockProgram ? 57 - # Disabled for cross; see note [HADDOCK_DOCS]. 58 - (stdenv.targetPlatform == stdenv.hostPlatform) 59 - 60 - , # Whether to disable the large address space allocator 61 - # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 62 - disableLargeAddressSpace ? stdenv.targetPlatform.isiOS 63 - }: 64 - 65 - assert !enableNativeBignum -> gmp != null; 66 - 67 - # Cross cannot currently build the `haddock` program for silly reasons, 68 - # see note [HADDOCK_DOCS]. 69 - assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; 70 - 71 - let 72 - inherit (stdenv) buildPlatform hostPlatform targetPlatform; 73 - 74 - inherit (bootPkgs) ghc; 75 - 76 - # TODO(@Ericson2314) Make unconditional 77 - targetPrefix = lib.optionalString 78 - (targetPlatform != hostPlatform) 79 - "${targetPlatform.config}-"; 80 - 81 - buildMK = '' 82 - BuildFlavour = ${ghcFlavour} 83 - ifneq \"\$(BuildFlavour)\" \"\" 84 - include mk/flavours/\$(BuildFlavour).mk 85 - endif 86 - BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} 87 - BUILD_SPHINX_PDF = NO 88 - '' + 89 - # Note [HADDOCK_DOCS]: 90 - # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` 91 - # program is built (which we generally always want to have a complete GHC install) 92 - # and whether it is run on the GHC sources to generate hyperlinked source code 93 - # (which is impossible for cross-compilation); see: 94 - # https://gitlab.haskell.org/ghc/ghc/-/issues/20077 95 - # This implies that currently a cross-compiled GHC will never have a `haddock` 96 - # program, so it can never generate haddocks for any packages. 97 - # If this is solved in the future, we'd like to unconditionally 98 - # build the haddock program (removing the `enableHaddockProgram` option). 99 - '' 100 - HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"} 101 - # Build haddocks for boot packages with hyperlinking 102 - EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump 103 - 104 - DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} 105 - BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"} 106 - '' + lib.optionalString (targetPlatform != hostPlatform) '' 107 - Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"} 108 - CrossCompilePrefix = ${targetPrefix} 109 - '' + lib.optionalString (!enableProfiledLibs) '' 110 - BUILD_PROF_LIBS = NO 111 - '' + 112 - # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) 113 - # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. 114 - # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell 115 - lib.optionalString enableRelocatedStaticLibs '' 116 - GhcLibHcOpts += -fPIC -fexternal-dynamic-refs 117 - GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs 118 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 119 - EXTRA_CC_OPTS += -std=gnu99 120 - ''; 121 - 122 - # Splicer will pull out correct variations 123 - libDeps = platform: lib.optional enableTerminfo ncurses 124 - ++ [libffi] 125 - ++ lib.optional (!enableNativeBignum) gmp 126 - ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; 127 - 128 - # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 129 - # GHC doesn't seem to have {LLC,OPT}_HOST 130 - toolsForTarget = [ 131 - pkgsBuildTarget.targetPackages.stdenv.cc 132 - ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 133 - 134 - targetCC = builtins.head toolsForTarget; 135 - 136 - # Sometimes we have to dispatch between the bintools wrapper and the unwrapped 137 - # derivation for certain tools depending on the platform. 138 - bintoolsFor = { 139 - # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is 140 - # part of the bintools wrapper (due to codesigning requirements), but not on 141 - # x86_64-darwin. 142 - install_name_tool = 143 - if stdenv.targetPlatform.isAarch64 144 - then targetCC.bintools 145 - else targetCC.bintools.bintools; 146 - # Same goes for strip. 147 - strip = 148 - # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 149 - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin 150 - then targetCC.bintools 151 - else targetCC.bintools.bintools; 152 - }; 153 - 154 - # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 155 - # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 156 - # see #84670 and #49071 for more background. 157 - useLdGold = targetPlatform.linker == "gold" || 158 - (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); 159 - 160 - # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 161 - variantSuffix = lib.concatStrings [ 162 - (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 163 - (lib.optionalString enableNativeBignum "-native-bignum") 164 - ]; 165 - 166 - in 167 - 168 - # C compiler, bintools and LLVM are used at build time, but will also leak into 169 - # the resulting GHC's settings file and used at runtime. This means that we are 170 - # currently only able to build GHC if hostPlatform == buildPlatform. 171 - assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; 172 - assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; 173 - assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 174 - 175 - stdenv.mkDerivation (rec { 3 + import ./common-make-native-bignum.nix { 176 4 version = "9.4.5"; 177 - pname = "${targetPrefix}ghc${variantSuffix}"; 178 - 179 - src = fetchurl { 180 - url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"; 181 - sha256 = "6256cf9caf6d6dc7b611dcfbb247df2d528e85aa39d22a698e870e5a590e8601"; 182 - }; 183 - 184 - enableParallelBuilding = true; 185 - 186 - outputs = [ "out" "doc" ]; 187 - 188 - patches = [ 189 - # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs 190 - # Can be removed if the Cabal library included with ghc backports the linked fix 191 - (fetchpatch { 192 - url = "https://github.com/haskell/cabal/commit/6c796218c92f93c95e94d5ec2d077f6956f68e98.patch"; 193 - stripLen = 1; 194 - extraPrefix = "libraries/Cabal/"; 195 - sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY="; 196 - }) 197 - 198 - # Fix docs build with sphinx >= 6.0 199 - # https://gitlab.haskell.org/ghc/ghc/-/issues/22766 200 - (fetchpatch { 201 - name = "ghc-docs-sphinx-6.0.patch"; 202 - url = "https://gitlab.haskell.org/ghc/ghc/-/commit/10e94a556b4f90769b7fd718b9790d58ae566600.patch"; 203 - sha256 = "0kmhfamr16w8gch0lgln2912r8aryjky1hfcda3jkcwa5cdzgjdv"; 204 - }) 205 - 206 - # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 207 - ./docs-sphinx-7.patch 208 - ] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 209 - # Prevent the paths module from emitting symbols that we don't use 210 - # when building with separate outputs. 211 - # 212 - # These cause problems as they're not eliminated by GHC's dead code 213 - # elimination on aarch64-darwin. (see 214 - # https://github.com/NixOS/nixpkgs/issues/140774 for details). 215 - ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch 216 - ]; 217 - 218 - postPatch = "patchShebangs ."; 219 - 220 - # GHC needs the locale configured during the Haddock phase. 221 - LANG = "en_US.UTF-8"; 222 - 223 - # GHC is a bit confused on its cross terminology. 224 - # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 225 - preConfigure = '' 226 - for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 227 - export "''${env#TARGET_}=''${!env}" 228 - done 229 - # GHC is a bit confused on its cross terminology, as these would normally be 230 - # the *host* tools. 231 - export CC="${targetCC}/bin/${targetCC.targetPrefix}cc" 232 - export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++" 233 - # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 234 - export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}" 235 - export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as" 236 - export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar" 237 - export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" 238 - export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" 239 - export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" 240 - export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" 241 - '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 242 - export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" 243 - export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" 244 - '' + lib.optionalString useLLVM '' 245 - export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" 246 - export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" 247 - '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 248 - # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 249 - export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 250 - '' + '' 251 - 252 - echo -n "${buildMK}" > mk/build.mk 253 - 254 - sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure 255 - '' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' 256 - export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" 257 - '' + lib.optionalString (!stdenv.isDarwin) '' 258 - export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 259 - '' + lib.optionalString stdenv.isDarwin '' 260 - export NIX_LDFLAGS+=" -no_dtrace_dof" 261 - 262 - # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 263 - export XATTR=${lib.getBin xattr}/bin/xattr 264 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 265 - 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 266 - '' + lib.optionalString targetPlatform.isMusl '' 267 - echo "patching llvm-targets for musl targets..." 268 - echo "Cloning these existing '*-linux-gnu*' targets:" 269 - grep linux-gnu llvm-targets | sed 's/^/ /' 270 - echo "(go go gadget sed)" 271 - sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 272 - echo "llvm-targets now contains these '*-linux-musl*' targets:" 273 - grep linux-musl llvm-targets | sed 's/^/ /' 274 - 275 - echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 276 - # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen) 277 - for x in configure aclocal.m4; do 278 - substituteInPlace $x \ 279 - --replace '*-android*|*-gnueabi*)' \ 280 - '*-android*|*-gnueabi*|*-musleabi*)' 281 - done 282 - '' 283 - # HACK: allow bootstrapping with GHC 8.10 which works fine, as we don't have 284 - # binary 9.0 packaged. Bootstrapping with 9.2 is broken without hadrian. 285 - + '' 286 - substituteInPlace configure --replace \ 287 - 'MinBootGhcVersion="9.0"' \ 288 - 'MinBootGhcVersion="8.10"' 289 - ''; 290 - 291 - # TODO(@Ericson2314): Always pass "--target" and always prefix. 292 - configurePlatforms = [ "build" "host" ] 293 - ++ lib.optional (targetPlatform != hostPlatform) "target"; 294 - 295 - # `--with` flags for libraries needed for RTS linker 296 - configureFlags = [ 297 - "--datadir=$doc/share/doc/ghc" 298 - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" 299 - ] ++ lib.optionals (libffi != null) [ 300 - "--with-system-libffi" 301 - "--with-ffi-includes=${targetPackages.libffi.dev}/include" 302 - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" 303 - ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 304 - "--with-gmp-includes=${targetPackages.gmp.dev}/include" 305 - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" 306 - ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ 307 - "--with-iconv-includes=${libiconv}/include" 308 - "--with-iconv-libraries=${libiconv}/lib" 309 - ] ++ lib.optionals (targetPlatform != hostPlatform) [ 310 - "--enable-bootstrap-with-devel-snapshot" 311 - ] ++ lib.optionals useLdGold [ 312 - "CFLAGS=-fuse-ld=gold" 313 - "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 314 - "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 315 - ] ++ lib.optionals (disableLargeAddressSpace) [ 316 - "--disable-large-address-space" 317 - ]; 318 - 319 - # Make sure we never relax`$PATH` and hooks support for compatibility. 320 - strictDeps = true; 321 - 322 - # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 323 - dontAddExtraLibs = true; 324 - 325 - nativeBuildInputs = [ 326 - perl autoconf automake m4 python3 327 - ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour 328 - ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 329 - autoSignDarwinBinariesHook 330 - ] ++ lib.optionals enableDocs [ 331 - sphinx 332 - ]; 333 - 334 - # For building runtime libs 335 - depsBuildTarget = toolsForTarget; 336 - 337 - buildInputs = [ perl bash ] ++ (libDeps hostPlatform); 338 - 339 - depsTargetTarget = map lib.getDev (libDeps targetPlatform); 340 - depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); 341 - 342 - # required, because otherwise all symbols from HSffi.o are stripped, and 343 - # that in turn causes GHCi to abort 344 - stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 345 - 346 - checkTarget = "test"; 347 - 348 - hardeningDisable = 349 - [ "format" ] 350 - # In nixpkgs, musl based builds currently enable `pie` hardening by default 351 - # (see `defaultHardeningFlags` in `make-derivation.nix`). 352 - # But GHC cannot currently produce outputs that are ready for `-pie` linking. 353 - # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear. 354 - # See: 355 - # * https://github.com/NixOS/nixpkgs/issues/129247 356 - # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580 357 - ++ lib.optional stdenv.targetPlatform.isMusl "pie"; 358 - 359 - # big-parallel allows us to build with more than 2 cores on 360 - # Hydra which already warrants a significant speedup 361 - requiredSystemFeatures = [ "big-parallel" ]; 362 - 363 - postInstall = '' 364 - # Install the bash completion file. 365 - install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 366 - ''; 367 - 368 - passthru = { 369 - inherit bootPkgs targetPrefix; 370 - 371 - inherit llvmPackages; 372 - inherit enableShared; 373 - 374 - # This is used by the haskell builder to query 375 - # the presence of the haddock program. 376 - hasHaddock = enableHaddockProgram; 377 - 378 - # Our Cabal compiler name 379 - haskellCompilerName = "ghc-${version}"; 380 - }; 381 - 382 - meta = { 383 - homepage = "http://haskell.org/ghc"; 384 - description = "The Glasgow Haskell Compiler"; 385 - maintainers = with lib.maintainers; [ 386 - guibou 387 - ] ++ lib.teams.haskell.members; 388 - timeout = 24 * 3600; 389 - inherit (ghc.meta) license platforms; 390 - }; 391 - 392 - } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { 393 - dontStrip = true; 394 - dontPatchELF = true; 395 - noAuditTmpdir = true; 396 - }) 5 + sha256 = "6256cf9caf6d6dc7b611dcfbb247df2d528e85aa39d22a698e870e5a590e8601"; 6 + }
+3 -389
pkgs/development/compilers/ghc/9.4.6.nix
··· 1 1 # DO NOT port this expression to hadrian. It is not possible to build a GHC 2 2 # cross compiler with 9.4.* and hadrian. 3 - { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 4 - 5 - # build-tools 6 - , bootPkgs 7 - , autoconf, automake, coreutils, fetchpatch, fetchurl, perl, python3, m4, sphinx 8 - , xattr, autoSignDarwinBinariesHook 9 - , bash 10 - 11 - , libiconv ? null, ncurses 12 - , glibcLocales ? null 13 - 14 - , # GHC can be built with system libffi or a bundled one. 15 - libffi ? null 16 - 17 - , useLLVM ? !(stdenv.targetPlatform.isx86 18 - || stdenv.targetPlatform.isPower 19 - || stdenv.targetPlatform.isSparc 20 - || stdenv.targetPlatform.isAarch64) 21 - , # LLVM is conceptually a run-time-only dependency, but for 22 - # non-x86, we need LLVM to bootstrap later stages, so it becomes a 23 - # build-time dependency too. 24 - buildTargetLlvmPackages, llvmPackages 25 - 26 - , # If enabled, GHC will be built with the GPL-free but slightly slower native 27 - # bignum backend instead of the faster but GPLed gmp backend. 28 - enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp 29 - && lib.meta.availableOn stdenv.targetPlatform gmp) 30 - , gmp 31 - 32 - , # If enabled, use -fPIC when compiling static libs. 33 - enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform 34 - 35 - , enableProfiledLibs ? true 36 - 37 - , # Whether to build dynamic libs for the standard library (on the target 38 - # platform). Static libs are always built. 39 - enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic 40 - 41 - , # Whether to build terminfo. 42 - enableTerminfo ? !stdenv.targetPlatform.isWindows 43 - 44 - , # What flavour to build. An empty string indicates no 45 - # specific flavour and falls back to ghc default values. 46 - ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 47 - (if useLLVM then "perf-cross" else "perf-cross-ncg") 48 - 49 - , # Whether to build sphinx documentation. 50 - enableDocs ? ( 51 - # Docs disabled if we are building on musl because it's a large task to keep 52 - # all `sphinx` dependencies building in this environment. 53 - !stdenv.buildPlatform.isMusl 54 - ) 55 - 56 - , enableHaddockProgram ? 57 - # Disabled for cross; see note [HADDOCK_DOCS]. 58 - (stdenv.targetPlatform == stdenv.hostPlatform) 59 - 60 - , # Whether to disable the large address space allocator 61 - # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 62 - disableLargeAddressSpace ? stdenv.targetPlatform.isiOS 63 - }: 64 - 65 - assert !enableNativeBignum -> gmp != null; 66 - 67 - # Cross cannot currently build the `haddock` program for silly reasons, 68 - # see note [HADDOCK_DOCS]. 69 - assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; 70 - 71 - let 72 - inherit (stdenv) buildPlatform hostPlatform targetPlatform; 73 - 74 - inherit (bootPkgs) ghc; 75 - 76 - # TODO(@Ericson2314) Make unconditional 77 - targetPrefix = lib.optionalString 78 - (targetPlatform != hostPlatform) 79 - "${targetPlatform.config}-"; 80 - 81 - buildMK = '' 82 - BuildFlavour = ${ghcFlavour} 83 - ifneq \"\$(BuildFlavour)\" \"\" 84 - include mk/flavours/\$(BuildFlavour).mk 85 - endif 86 - BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} 87 - BUILD_SPHINX_PDF = NO 88 - '' + 89 - # Note [HADDOCK_DOCS]: 90 - # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` 91 - # program is built (which we generally always want to have a complete GHC install) 92 - # and whether it is run on the GHC sources to generate hyperlinked source code 93 - # (which is impossible for cross-compilation); see: 94 - # https://gitlab.haskell.org/ghc/ghc/-/issues/20077 95 - # This implies that currently a cross-compiled GHC will never have a `haddock` 96 - # program, so it can never generate haddocks for any packages. 97 - # If this is solved in the future, we'd like to unconditionally 98 - # build the haddock program (removing the `enableHaddockProgram` option). 99 - '' 100 - HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"} 101 - # Build haddocks for boot packages with hyperlinking 102 - EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump 103 - 104 - DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} 105 - BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"} 106 - '' + lib.optionalString (targetPlatform != hostPlatform) '' 107 - Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"} 108 - CrossCompilePrefix = ${targetPrefix} 109 - '' + lib.optionalString (!enableProfiledLibs) '' 110 - BUILD_PROF_LIBS = NO 111 - '' + 112 - # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) 113 - # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. 114 - # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell 115 - lib.optionalString enableRelocatedStaticLibs '' 116 - GhcLibHcOpts += -fPIC -fexternal-dynamic-refs 117 - GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs 118 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 119 - EXTRA_CC_OPTS += -std=gnu99 120 - ''; 121 - 122 - # Splicer will pull out correct variations 123 - libDeps = platform: lib.optional enableTerminfo ncurses 124 - ++ [libffi] 125 - ++ lib.optional (!enableNativeBignum) gmp 126 - ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; 127 - 128 - # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 129 - # GHC doesn't seem to have {LLC,OPT}_HOST 130 - toolsForTarget = [ 131 - pkgsBuildTarget.targetPackages.stdenv.cc 132 - ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 133 - 134 - targetCC = builtins.head toolsForTarget; 135 - 136 - # Sometimes we have to dispatch between the bintools wrapper and the unwrapped 137 - # derivation for certain tools depending on the platform. 138 - bintoolsFor = { 139 - # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is 140 - # part of the bintools wrapper (due to codesigning requirements), but not on 141 - # x86_64-darwin. 142 - install_name_tool = 143 - if stdenv.targetPlatform.isAarch64 144 - then targetCC.bintools 145 - else targetCC.bintools.bintools; 146 - # Same goes for strip. 147 - strip = 148 - # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 149 - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin 150 - then targetCC.bintools 151 - else targetCC.bintools.bintools; 152 - }; 153 - 154 - # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 155 - # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 156 - # see #84670 and #49071 for more background. 157 - useLdGold = targetPlatform.linker == "gold" || 158 - (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); 159 - 160 - # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 161 - variantSuffix = lib.concatStrings [ 162 - (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 163 - (lib.optionalString enableNativeBignum "-native-bignum") 164 - ]; 165 - 166 - in 167 - 168 - # C compiler, bintools and LLVM are used at build time, but will also leak into 169 - # the resulting GHC's settings file and used at runtime. This means that we are 170 - # currently only able to build GHC if hostPlatform == buildPlatform. 171 - assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; 172 - assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; 173 - assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 174 - 175 - stdenv.mkDerivation (rec { 3 + import ./common-make-native-bignum.nix { 176 4 version = "9.4.6"; 177 - pname = "${targetPrefix}ghc${variantSuffix}"; 178 - 179 - src = fetchurl { 180 - url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"; 181 - sha256 = "1b705cf52692f9d4d6707cdf8e761590f5f56ec8ea6a65e36610db392d3d24b9"; 182 - }; 183 - 184 - enableParallelBuilding = true; 185 - 186 - outputs = [ "out" "doc" ]; 187 - 188 - patches = [ 189 - # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs 190 - # Can be removed if the Cabal library included with ghc backports the linked fix 191 - (fetchpatch { 192 - url = "https://github.com/haskell/cabal/commit/6c796218c92f93c95e94d5ec2d077f6956f68e98.patch"; 193 - stripLen = 1; 194 - extraPrefix = "libraries/Cabal/"; 195 - sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY="; 196 - }) 197 - 198 - # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 199 - ./docs-sphinx-7.patch 200 - 201 - # Work around a type not being defined when including Rts.h in bytestring's cbits 202 - # due to missing feature macros. See https://gitlab.haskell.org/ghc/ghc/-/issues/23810. 203 - ./9.4.6-bytestring-posix-source.patch 204 - ] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 205 - # Prevent the paths module from emitting symbols that we don't use 206 - # when building with separate outputs. 207 - # 208 - # These cause problems as they're not eliminated by GHC's dead code 209 - # elimination on aarch64-darwin. (see 210 - # https://github.com/NixOS/nixpkgs/issues/140774 for details). 211 - ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch 212 - ]; 213 - 214 - postPatch = "patchShebangs ."; 215 - 216 - # GHC needs the locale configured during the Haddock phase. 217 - LANG = "en_US.UTF-8"; 218 - 219 - # GHC is a bit confused on its cross terminology. 220 - # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 221 - preConfigure = '' 222 - for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 223 - export "''${env#TARGET_}=''${!env}" 224 - done 225 - # GHC is a bit confused on its cross terminology, as these would normally be 226 - # the *host* tools. 227 - export CC="${targetCC}/bin/${targetCC.targetPrefix}cc" 228 - export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++" 229 - # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 230 - export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}" 231 - export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as" 232 - export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar" 233 - export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" 234 - export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" 235 - export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" 236 - export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" 237 - '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 238 - export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" 239 - export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" 240 - '' + lib.optionalString useLLVM '' 241 - export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" 242 - export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" 243 - '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 244 - # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 245 - export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 246 - '' + '' 247 - 248 - echo -n "${buildMK}" > mk/build.mk 249 - 250 - sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure 251 - '' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' 252 - export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" 253 - '' + lib.optionalString (!stdenv.isDarwin) '' 254 - export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 255 - '' + lib.optionalString stdenv.isDarwin '' 256 - export NIX_LDFLAGS+=" -no_dtrace_dof" 257 - 258 - # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 259 - export XATTR=${lib.getBin xattr}/bin/xattr 260 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 261 - 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 262 - '' + lib.optionalString targetPlatform.isMusl '' 263 - echo "patching llvm-targets for musl targets..." 264 - echo "Cloning these existing '*-linux-gnu*' targets:" 265 - grep linux-gnu llvm-targets | sed 's/^/ /' 266 - echo "(go go gadget sed)" 267 - sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 268 - echo "llvm-targets now contains these '*-linux-musl*' targets:" 269 - grep linux-musl llvm-targets | sed 's/^/ /' 270 - 271 - echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 272 - # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen) 273 - for x in configure aclocal.m4; do 274 - substituteInPlace $x \ 275 - --replace '*-android*|*-gnueabi*)' \ 276 - '*-android*|*-gnueabi*|*-musleabi*)' 277 - done 278 - '' 279 - # HACK: allow bootstrapping with GHC 8.10 which works fine, as we don't have 280 - # binary 9.0 packaged. Bootstrapping with 9.2 is broken without hadrian. 281 - + '' 282 - substituteInPlace configure --replace \ 283 - 'MinBootGhcVersion="9.0"' \ 284 - 'MinBootGhcVersion="8.10"' 285 - ''; 286 - 287 - # TODO(@Ericson2314): Always pass "--target" and always prefix. 288 - configurePlatforms = [ "build" "host" ] 289 - ++ lib.optional (targetPlatform != hostPlatform) "target"; 290 - 291 - # `--with` flags for libraries needed for RTS linker 292 - configureFlags = [ 293 - "--datadir=$doc/share/doc/ghc" 294 - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" 295 - ] ++ lib.optionals (libffi != null) [ 296 - "--with-system-libffi" 297 - "--with-ffi-includes=${targetPackages.libffi.dev}/include" 298 - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" 299 - ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 300 - "--with-gmp-includes=${targetPackages.gmp.dev}/include" 301 - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" 302 - ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ 303 - "--with-iconv-includes=${libiconv}/include" 304 - "--with-iconv-libraries=${libiconv}/lib" 305 - ] ++ lib.optionals (targetPlatform != hostPlatform) [ 306 - "--enable-bootstrap-with-devel-snapshot" 307 - ] ++ lib.optionals useLdGold [ 308 - "CFLAGS=-fuse-ld=gold" 309 - "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 310 - "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 311 - ] ++ lib.optionals (disableLargeAddressSpace) [ 312 - "--disable-large-address-space" 313 - ]; 314 - 315 - # Make sure we never relax`$PATH` and hooks support for compatibility. 316 - strictDeps = true; 317 - 318 - # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 319 - dontAddExtraLibs = true; 320 - 321 - nativeBuildInputs = [ 322 - perl autoconf automake m4 python3 323 - ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour 324 - ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 325 - autoSignDarwinBinariesHook 326 - ] ++ lib.optionals enableDocs [ 327 - sphinx 328 - ]; 329 - 330 - # For building runtime libs 331 - depsBuildTarget = toolsForTarget; 332 - 333 - buildInputs = [ perl bash ] ++ (libDeps hostPlatform); 334 - 335 - depsTargetTarget = map lib.getDev (libDeps targetPlatform); 336 - depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); 337 - 338 - # required, because otherwise all symbols from HSffi.o are stripped, and 339 - # that in turn causes GHCi to abort 340 - stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 341 - 342 - checkTarget = "test"; 343 - 344 - hardeningDisable = 345 - [ "format" ] 346 - # In nixpkgs, musl based builds currently enable `pie` hardening by default 347 - # (see `defaultHardeningFlags` in `make-derivation.nix`). 348 - # But GHC cannot currently produce outputs that are ready for `-pie` linking. 349 - # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear. 350 - # See: 351 - # * https://github.com/NixOS/nixpkgs/issues/129247 352 - # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580 353 - ++ lib.optional stdenv.targetPlatform.isMusl "pie"; 354 - 355 - # big-parallel allows us to build with more than 2 cores on 356 - # Hydra which already warrants a significant speedup 357 - requiredSystemFeatures = [ "big-parallel" ]; 358 - 359 - postInstall = '' 360 - # Install the bash completion file. 361 - install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 362 - ''; 363 - 364 - passthru = { 365 - inherit bootPkgs targetPrefix; 366 - 367 - inherit llvmPackages; 368 - inherit enableShared; 369 - 370 - # This is used by the haskell builder to query 371 - # the presence of the haddock program. 372 - hasHaddock = enableHaddockProgram; 373 - 374 - # Our Cabal compiler name 375 - haskellCompilerName = "ghc-${version}"; 376 - }; 377 - 378 - meta = { 379 - homepage = "http://haskell.org/ghc"; 380 - description = "The Glasgow Haskell Compiler"; 381 - maintainers = with lib.maintainers; [ 382 - guibou 383 - ] ++ lib.teams.haskell.members; 384 - timeout = 24 * 3600; 385 - inherit (ghc.meta) license platforms; 386 - }; 387 - 388 - } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { 389 - dontStrip = true; 390 - dontPatchELF = true; 391 - noAuditTmpdir = true; 392 - }) 5 + sha256 = "1b705cf52692f9d4d6707cdf8e761590f5f56ec8ea6a65e36610db392d3d24b9"; 6 + }
+3 -385
pkgs/development/compilers/ghc/9.4.7.nix
··· 1 1 # DO NOT port this expression to hadrian. It is not possible to build a GHC 2 2 # cross compiler with 9.4.* and hadrian. 3 - { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 4 - 5 - # build-tools 6 - , bootPkgs 7 - , autoconf, automake, coreutils, fetchpatch, fetchurl, perl, python3, m4, sphinx 8 - , xattr, autoSignDarwinBinariesHook 9 - , bash 10 - 11 - , libiconv ? null, ncurses 12 - , glibcLocales ? null 13 - 14 - , # GHC can be built with system libffi or a bundled one. 15 - libffi ? null 16 - 17 - , useLLVM ? !(stdenv.targetPlatform.isx86 18 - || stdenv.targetPlatform.isPower 19 - || stdenv.targetPlatform.isSparc 20 - || stdenv.targetPlatform.isAarch64) 21 - , # LLVM is conceptually a run-time-only dependency, but for 22 - # non-x86, we need LLVM to bootstrap later stages, so it becomes a 23 - # build-time dependency too. 24 - buildTargetLlvmPackages, llvmPackages 25 - 26 - , # If enabled, GHC will be built with the GPL-free but slightly slower native 27 - # bignum backend instead of the faster but GPLed gmp backend. 28 - enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp 29 - && lib.meta.availableOn stdenv.targetPlatform gmp) 30 - , gmp 31 - 32 - , # If enabled, use -fPIC when compiling static libs. 33 - enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform 34 - 35 - , enableProfiledLibs ? true 36 - 37 - , # Whether to build dynamic libs for the standard library (on the target 38 - # platform). Static libs are always built. 39 - enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic 40 - 41 - , # Whether to build terminfo. 42 - enableTerminfo ? !stdenv.targetPlatform.isWindows 43 - 44 - , # What flavour to build. An empty string indicates no 45 - # specific flavour and falls back to ghc default values. 46 - ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform) 47 - (if useLLVM then "perf-cross" else "perf-cross-ncg") 48 - 49 - , # Whether to build sphinx documentation. 50 - enableDocs ? ( 51 - # Docs disabled if we are building on musl because it's a large task to keep 52 - # all `sphinx` dependencies building in this environment. 53 - !stdenv.buildPlatform.isMusl 54 - ) 55 - 56 - , enableHaddockProgram ? 57 - # Disabled for cross; see note [HADDOCK_DOCS]. 58 - (stdenv.targetPlatform == stdenv.hostPlatform) 59 - 60 - , # Whether to disable the large address space allocator 61 - # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/ 62 - disableLargeAddressSpace ? stdenv.targetPlatform.isiOS 63 - }: 64 - 65 - assert !enableNativeBignum -> gmp != null; 66 - 67 - # Cross cannot currently build the `haddock` program for silly reasons, 68 - # see note [HADDOCK_DOCS]. 69 - assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram; 70 - 71 - let 72 - inherit (stdenv) buildPlatform hostPlatform targetPlatform; 73 - 74 - inherit (bootPkgs) ghc; 75 - 76 - # TODO(@Ericson2314) Make unconditional 77 - targetPrefix = lib.optionalString 78 - (targetPlatform != hostPlatform) 79 - "${targetPlatform.config}-"; 80 - 81 - buildMK = '' 82 - BuildFlavour = ${ghcFlavour} 83 - ifneq \"\$(BuildFlavour)\" \"\" 84 - include mk/flavours/\$(BuildFlavour).mk 85 - endif 86 - BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"} 87 - BUILD_SPHINX_PDF = NO 88 - '' + 89 - # Note [HADDOCK_DOCS]: 90 - # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock` 91 - # program is built (which we generally always want to have a complete GHC install) 92 - # and whether it is run on the GHC sources to generate hyperlinked source code 93 - # (which is impossible for cross-compilation); see: 94 - # https://gitlab.haskell.org/ghc/ghc/-/issues/20077 95 - # This implies that currently a cross-compiled GHC will never have a `haddock` 96 - # program, so it can never generate haddocks for any packages. 97 - # If this is solved in the future, we'd like to unconditionally 98 - # build the haddock program (removing the `enableHaddockProgram` option). 99 - '' 100 - HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"} 101 - # Build haddocks for boot packages with hyperlinking 102 - EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump 103 - 104 - DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"} 105 - BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"} 106 - '' + lib.optionalString (targetPlatform != hostPlatform) '' 107 - Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"} 108 - CrossCompilePrefix = ${targetPrefix} 109 - '' + lib.optionalString (!enableProfiledLibs) '' 110 - BUILD_PROF_LIBS = NO 111 - '' + 112 - # -fexternal-dynamic-refs apparently (because it's not clear from the documentation) 113 - # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell. 114 - # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell 115 - lib.optionalString enableRelocatedStaticLibs '' 116 - GhcLibHcOpts += -fPIC -fexternal-dynamic-refs 117 - GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs 118 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 119 - EXTRA_CC_OPTS += -std=gnu99 120 - ''; 121 - 122 - # Splicer will pull out correct variations 123 - libDeps = platform: lib.optional enableTerminfo ncurses 124 - ++ [libffi] 125 - ++ lib.optional (!enableNativeBignum) gmp 126 - ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv; 127 - 128 - # TODO(@sternenseemann): is buildTarget LLVM unnecessary? 129 - # GHC doesn't seem to have {LLC,OPT}_HOST 130 - toolsForTarget = [ 131 - pkgsBuildTarget.targetPackages.stdenv.cc 132 - ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm; 133 - 134 - targetCC = builtins.head toolsForTarget; 135 - 136 - # Sometimes we have to dispatch between the bintools wrapper and the unwrapped 137 - # derivation for certain tools depending on the platform. 138 - bintoolsFor = { 139 - # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is 140 - # part of the bintools wrapper (due to codesigning requirements), but not on 141 - # x86_64-darwin. 142 - install_name_tool = 143 - if stdenv.targetPlatform.isAarch64 144 - then targetCC.bintools 145 - else targetCC.bintools.bintools; 146 - # Same goes for strip. 147 - strip = 148 - # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold" 149 - if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin 150 - then targetCC.bintools 151 - else targetCC.bintools.bintools; 152 - }; 153 - 154 - # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues. 155 - # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856 156 - # see #84670 and #49071 for more background. 157 - useLdGold = targetPlatform.linker == "gold" || 158 - (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl); 159 - 160 - # Makes debugging easier to see which variant is at play in `nix-store -q --tree`. 161 - variantSuffix = lib.concatStrings [ 162 - (lib.optionalString stdenv.hostPlatform.isMusl "-musl") 163 - (lib.optionalString enableNativeBignum "-native-bignum") 164 - ]; 165 - 166 - in 167 - 168 - # C compiler, bintools and LLVM are used at build time, but will also leak into 169 - # the resulting GHC's settings file and used at runtime. This means that we are 170 - # currently only able to build GHC if hostPlatform == buildPlatform. 171 - assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc; 172 - assert buildTargetLlvmPackages.llvm == llvmPackages.llvm; 173 - assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 174 - 175 - stdenv.mkDerivation (rec { 3 + import ./common-make-native-bignum.nix { 176 4 version = "9.4.7"; 177 - pname = "${targetPrefix}ghc${variantSuffix}"; 178 - 179 - src = fetchurl { 180 - url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"; 181 - sha256 = "06775a52b4d13ac09edc6dabc299fd11e59d8886bbcae450af367baee2684c8f"; 182 - }; 183 - 184 - enableParallelBuilding = true; 185 - 186 - outputs = [ "out" "doc" ]; 187 - 188 - patches = [ 189 - # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs 190 - # Can be removed if the Cabal library included with ghc backports the linked fix 191 - (fetchpatch { 192 - url = "https://github.com/haskell/cabal/commit/6c796218c92f93c95e94d5ec2d077f6956f68e98.patch"; 193 - stripLen = 1; 194 - extraPrefix = "libraries/Cabal/"; 195 - sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY="; 196 - }) 197 - 198 - # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 199 - ./docs-sphinx-7.patch 200 - ] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 201 - # Prevent the paths module from emitting symbols that we don't use 202 - # when building with separate outputs. 203 - # 204 - # These cause problems as they're not eliminated by GHC's dead code 205 - # elimination on aarch64-darwin. (see 206 - # https://github.com/NixOS/nixpkgs/issues/140774 for details). 207 - ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch 208 - ]; 209 - 210 - postPatch = "patchShebangs ."; 211 - 212 - # GHC needs the locale configured during the Haddock phase. 213 - LANG = "en_US.UTF-8"; 214 - 215 - # GHC is a bit confused on its cross terminology. 216 - # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths 217 - preConfigure = '' 218 - for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do 219 - export "''${env#TARGET_}=''${!env}" 220 - done 221 - # GHC is a bit confused on its cross terminology, as these would normally be 222 - # the *host* tools. 223 - export CC="${targetCC}/bin/${targetCC.targetPrefix}cc" 224 - export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++" 225 - # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177 226 - export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}" 227 - export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as" 228 - export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar" 229 - export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm" 230 - export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib" 231 - export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf" 232 - export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip" 233 - '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") '' 234 - export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool" 235 - export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool" 236 - '' + lib.optionalString useLLVM '' 237 - export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc" 238 - export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt" 239 - '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 240 - # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 241 - export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 242 - '' + '' 243 - 244 - echo -n "${buildMK}" > mk/build.mk 245 - 246 - sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure 247 - '' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' 248 - export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" 249 - '' + lib.optionalString (!stdenv.isDarwin) '' 250 - export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 251 - '' + lib.optionalString stdenv.isDarwin '' 252 - export NIX_LDFLAGS+=" -no_dtrace_dof" 253 - 254 - # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 255 - export XATTR=${lib.getBin xattr}/bin/xattr 256 - '' + lib.optionalString targetPlatform.useAndroidPrebuilt '' 257 - 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 258 - '' + lib.optionalString targetPlatform.isMusl '' 259 - echo "patching llvm-targets for musl targets..." 260 - echo "Cloning these existing '*-linux-gnu*' targets:" 261 - grep linux-gnu llvm-targets | sed 's/^/ /' 262 - echo "(go go gadget sed)" 263 - sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets 264 - echo "llvm-targets now contains these '*-linux-musl*' targets:" 265 - grep linux-musl llvm-targets | sed 's/^/ /' 266 - 267 - echo "And now patching to preserve '-musleabi' as done with '-gnueabi'" 268 - # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen) 269 - for x in configure aclocal.m4; do 270 - substituteInPlace $x \ 271 - --replace '*-android*|*-gnueabi*)' \ 272 - '*-android*|*-gnueabi*|*-musleabi*)' 273 - done 274 - '' 275 - # HACK: allow bootstrapping with GHC 8.10 which works fine, as we don't have 276 - # binary 9.0 packaged. Bootstrapping with 9.2 is broken without hadrian. 277 - + '' 278 - substituteInPlace configure --replace \ 279 - 'MinBootGhcVersion="9.0"' \ 280 - 'MinBootGhcVersion="8.10"' 281 - ''; 282 - 283 - # TODO(@Ericson2314): Always pass "--target" and always prefix. 284 - configurePlatforms = [ "build" "host" ] 285 - ++ lib.optional (targetPlatform != hostPlatform) "target"; 286 - 287 - # `--with` flags for libraries needed for RTS linker 288 - configureFlags = [ 289 - "--datadir=$doc/share/doc/ghc" 290 - "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib" 291 - ] ++ lib.optionals (libffi != null) [ 292 - "--with-system-libffi" 293 - "--with-ffi-includes=${targetPackages.libffi.dev}/include" 294 - "--with-ffi-libraries=${targetPackages.libffi.out}/lib" 295 - ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [ 296 - "--with-gmp-includes=${targetPackages.gmp.dev}/include" 297 - "--with-gmp-libraries=${targetPackages.gmp.out}/lib" 298 - ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [ 299 - "--with-iconv-includes=${libiconv}/include" 300 - "--with-iconv-libraries=${libiconv}/lib" 301 - ] ++ lib.optionals (targetPlatform != hostPlatform) [ 302 - "--enable-bootstrap-with-devel-snapshot" 303 - ] ++ lib.optionals useLdGold [ 304 - "CFLAGS=-fuse-ld=gold" 305 - "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold" 306 - "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold" 307 - ] ++ lib.optionals (disableLargeAddressSpace) [ 308 - "--disable-large-address-space" 309 - ]; 310 - 311 - # Make sure we never relax`$PATH` and hooks support for compatibility. 312 - strictDeps = true; 313 - 314 - # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself. 315 - dontAddExtraLibs = true; 316 - 317 - nativeBuildInputs = [ 318 - perl autoconf automake m4 python3 319 - ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour 320 - ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [ 321 - autoSignDarwinBinariesHook 322 - ] ++ lib.optionals enableDocs [ 323 - sphinx 324 - ]; 325 - 326 - # For building runtime libs 327 - depsBuildTarget = toolsForTarget; 328 - 329 - buildInputs = [ perl bash ] ++ (libDeps hostPlatform); 330 - 331 - depsTargetTarget = map lib.getDev (libDeps targetPlatform); 332 - depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform); 333 - 334 - # required, because otherwise all symbols from HSffi.o are stripped, and 335 - # that in turn causes GHCi to abort 336 - stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols"; 337 - 338 - checkTarget = "test"; 339 - 340 - hardeningDisable = 341 - [ "format" ] 342 - # In nixpkgs, musl based builds currently enable `pie` hardening by default 343 - # (see `defaultHardeningFlags` in `make-derivation.nix`). 344 - # But GHC cannot currently produce outputs that are ready for `-pie` linking. 345 - # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear. 346 - # See: 347 - # * https://github.com/NixOS/nixpkgs/issues/129247 348 - # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580 349 - ++ lib.optional stdenv.targetPlatform.isMusl "pie"; 350 - 351 - # big-parallel allows us to build with more than 2 cores on 352 - # Hydra which already warrants a significant speedup 353 - requiredSystemFeatures = [ "big-parallel" ]; 354 - 355 - postInstall = '' 356 - # Install the bash completion file. 357 - install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc 358 - ''; 359 - 360 - passthru = { 361 - inherit bootPkgs targetPrefix; 362 - 363 - inherit llvmPackages; 364 - inherit enableShared; 365 - 366 - # This is used by the haskell builder to query 367 - # the presence of the haddock program. 368 - hasHaddock = enableHaddockProgram; 369 - 370 - # Our Cabal compiler name 371 - haskellCompilerName = "ghc-${version}"; 372 - }; 373 - 374 - meta = { 375 - homepage = "http://haskell.org/ghc"; 376 - description = "The Glasgow Haskell Compiler"; 377 - maintainers = with lib.maintainers; [ 378 - guibou 379 - ] ++ lib.teams.haskell.members; 380 - timeout = 24 * 3600; 381 - inherit (ghc.meta) license platforms; 382 - }; 383 - 384 - } // lib.optionalAttrs targetPlatform.useAndroidPrebuilt { 385 - dontStrip = true; 386 - dontPatchELF = true; 387 - noAuditTmpdir = true; 388 - }) 5 + sha256 = "06775a52b4d13ac09edc6dabc299fd11e59d8886bbcae450af367baee2684c8f"; 6 + }
+6
pkgs/development/compilers/ghc/9.4.8.fixme.nix
··· 1 + # DO NOT port this expression to hadrian. It is not possible to build a GHC 2 + # cross compiler with 9.4.* and hadrian. 3 + import ./common-make-native-bignum.nix { 4 + version = "9.4.8"; 5 + sha256 = "0bf407eb67fe3e3c24b0f4c8dea8cb63e07f63ca0f76cf2058565143507ab85e"; 6 + }
+94 -11
pkgs/development/compilers/ghc/9.4.8.nix pkgs/development/compilers/ghc/common-make-native-bignum.nix
··· 1 - # DO NOT port this expression to hadrian. It is not possible to build a GHC 2 - # cross compiler with 9.4.* and hadrian. 1 + { version 2 + , sha256 3 + , url ? "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz" 4 + }: 5 + 3 6 { lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages 4 7 5 8 # build-tools ··· 17 20 , useLLVM ? !(stdenv.targetPlatform.isx86 18 21 || stdenv.targetPlatform.isPower 19 22 || stdenv.targetPlatform.isSparc 20 - || stdenv.targetPlatform.isAarch64) 23 + || (lib.versionAtLeast version "9.2" && stdenv.targetPlatform.isAarch64)) 21 24 , # LLVM is conceptually a run-time-only dependency, but for 22 25 # non-x86, we need LLVM to bootstrap later stages, so it becomes a 23 26 # build-time dependency too. ··· 173 176 assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang; 174 177 175 178 stdenv.mkDerivation (rec { 176 - version = "9.4.8"; 177 179 pname = "${targetPrefix}ghc${variantSuffix}"; 180 + inherit version; 178 181 179 182 src = fetchurl { 180 - url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"; 181 - sha256 = "0bf407eb67fe3e3c24b0f4c8dea8cb63e07f63ca0f76cf2058565143507ab85e"; 183 + inherit url sha256; 182 184 }; 183 185 184 186 enableParallelBuilding = true; 185 187 186 188 outputs = [ "out" "doc" ]; 187 189 188 - patches = [ 190 + # FIXME(@sternenseemann): This can be simplified a lot (causing a rebuild) 191 + patches = (if lib.versions.majorMinor version == "9.0" then [ 192 + # Fix docs build with sphinx >= 6.0 193 + # https://gitlab.haskell.org/ghc/ghc/-/issues/22766 194 + (fetchpatch { 195 + name = "ghc-docs-sphinx-6.0.patch"; 196 + url = "https://gitlab.haskell.org/ghc/ghc/-/commit/10e94a556b4f90769b7fd718b9790d58ae566600.patch"; 197 + sha256 = "0kmhfamr16w8gch0lgln2912r8aryjky1hfcda3jkcwa5cdzgjdv"; 198 + }) 199 + # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 200 + ./docs-sphinx-7.patch 201 + # fix hyperlinked haddock sources: https://github.com/haskell/haddock/pull/1482 202 + (fetchpatch { 203 + url = "https://patch-diff.githubusercontent.com/raw/haskell/haddock/pull/1482.patch"; 204 + sha256 = "sha256-8w8QUCsODaTvknCDGgTfFNZa8ZmvIKaKS+2ZJZ9foYk="; 205 + extraPrefix = "utils/haddock/"; 206 + stripLen = 1; 207 + }) 208 + 209 + # Add flag that fixes C++ exception handling; opt-in. Merged in 9.4 and 9.2.2. 210 + # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/7423 211 + (fetchpatch { 212 + name = "ghc-9.0.2-fcompact-unwind.patch"; 213 + # Note that the test suite is not packaged. 214 + url = "https://gitlab.haskell.org/ghc/ghc/-/commit/c6132c782d974a7701e7f6447bdcd2bf6db4299a.patch?merge_request_iid=7423"; 215 + sha256 = "sha256-b4feGZIaKDj/UKjWTNY6/jH4s2iate0wAgMxG3rAbZI="; 216 + }) 217 + ] else if lib.versions.majorMinor version == "9.2" then [ 218 + # Fix docs build with sphinx >= 6.0 219 + # https://gitlab.haskell.org/ghc/ghc/-/issues/22766 220 + (fetchpatch { 221 + name = "ghc-docs-sphinx-6.0.patch"; 222 + url = "https://gitlab.haskell.org/ghc/ghc/-/commit/10e94a556b4f90769b7fd718b9790d58ae566600.patch"; 223 + sha256 = "0kmhfamr16w8gch0lgln2912r8aryjky1hfcda3jkcwa5cdzgjdv"; 224 + }) 225 + # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 226 + ./docs-sphinx-7.patch 227 + # fix hyperlinked haddock sources: https://github.com/haskell/haddock/pull/1482 228 + (fetchpatch { 229 + url = "https://patch-diff.githubusercontent.com/raw/haskell/haddock/pull/1482.patch"; 230 + sha256 = "sha256-8w8QUCsODaTvknCDGgTfFNZa8ZmvIKaKS+2ZJZ9foYk="; 231 + extraPrefix = "utils/haddock/"; 232 + stripLen = 1; 233 + }) 189 234 # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs 190 235 # Can be removed if the Cabal library included with ghc backports the linked fix 191 236 (fetchpatch { ··· 194 239 extraPrefix = "libraries/Cabal/"; 195 240 sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY="; 196 241 }) 242 + ] else if lib.versions.majorMinor version == "9.4" then [ 243 + # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs 244 + # Can be removed if the Cabal library included with ghc backports the linked fix 245 + (fetchpatch { 246 + url = "https://github.com/haskell/cabal/commit/6c796218c92f93c95e94d5ec2d077f6956f68e98.patch"; 247 + stripLen = 1; 248 + extraPrefix = "libraries/Cabal/"; 249 + sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY="; 250 + }) 251 + ] 252 + ++ lib.optionals (version == "9.4.5") [ 253 + # Fix docs build with sphinx >= 6.0 254 + # https://gitlab.haskell.org/ghc/ghc/-/issues/22766 255 + (fetchpatch { 256 + name = "ghc-docs-sphinx-6.0.patch"; 257 + url = "https://gitlab.haskell.org/ghc/ghc/-/commit/10e94a556b4f90769b7fd718b9790d58ae566600.patch"; 258 + sha256 = "0kmhfamr16w8gch0lgln2912r8aryjky1hfcda3jkcwa5cdzgjdv"; 259 + }) 260 + ] 261 + ++ [ 197 262 198 263 # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129 199 264 ./docs-sphinx-7.patch 200 - ] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 265 + ] 266 + ++ lib.optionals (version == "9.4.6") [ 267 + # Work around a type not being defined when including Rts.h in bytestring's cbits 268 + # due to missing feature macros. See https://gitlab.haskell.org/ghc/ghc/-/issues/23810. 269 + ./9.4.6-bytestring-posix-source.patch 270 + ] else [ ]) 271 + ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [ 201 272 # Prevent the paths module from emitting symbols that we don't use 202 273 # when building with separate outputs. 203 274 # 204 275 # These cause problems as they're not eliminated by GHC's dead code 205 276 # elimination on aarch64-darwin. (see 206 277 # https://github.com/NixOS/nixpkgs/issues/140774 for details). 207 - ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch 278 + (if lib.versionAtLeast version "9.2" 279 + then ./Cabal-at-least-3.6-paths-fix-cycle-aarch64-darwin.patch 280 + else ./Cabal-3.2-3.4-paths-fix-cycle-aarch64-darwin.patch) 208 281 ]; 209 282 210 283 postPatch = "patchShebangs ."; ··· 239 312 '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) '' 240 313 # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm 241 314 export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang" 242 - '' + '' 315 + '' 316 + + lib.optionalString (version == "9.0.2" || lib.versionAtLeast version "9.4") '' 243 317 318 + '' + '' 244 319 echo -n "${buildMK}" > mk/build.mk 320 + '' + lib.optionalString (lib.versionAtLeast version "9.4") '' 245 321 322 + '' 323 + + lib.optionalString (lib.versionOlder version "9.2" || lib.versionAtLeast version "9.4") '' 246 324 sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure 247 325 '' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") '' 248 326 export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" ··· 250 328 export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}" 251 329 '' + lib.optionalString stdenv.isDarwin '' 252 330 export NIX_LDFLAGS+=" -no_dtrace_dof" 331 + '' + lib.optionalString (stdenv.isDarwin && lib.versionAtLeast version "9.2") '' 253 332 254 333 # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7 255 334 export XATTR=${lib.getBin xattr}/bin/xattr ··· 274 353 '' 275 354 # HACK: allow bootstrapping with GHC 8.10 which works fine, as we don't have 276 355 # binary 9.0 packaged. Bootstrapping with 9.2 is broken without hadrian. 277 - + '' 356 + + lib.optionalString (lib.versions.majorMinor version == "9.4") '' 278 357 substituteInPlace configure --replace \ 279 358 'MinBootGhcVersion="9.0"' \ 280 359 'MinBootGhcVersion="8.10"' ··· 321 400 autoSignDarwinBinariesHook 322 401 ] ++ lib.optionals enableDocs [ 323 402 sphinx 403 + ] ++ lib.optionals (stdenv.isDarwin && lib.versions.majorMinor version == "9.0") [ 404 + # TODO(@sternenseemann): backport addition of XATTR env var like 405 + # https://gitlab.haskell.org/ghc/ghc/-/merge_requests/6447 406 + xattr 324 407 ]; 325 408 326 409 # For building runtime libs
+1 -1
pkgs/top-level/haskell-packages.nix
··· 229 229 buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_12; 230 230 llvmPackages = pkgs.llvmPackages_12; 231 231 }; 232 - ghc948 = callPackage ../development/compilers/ghc/9.4.8.nix { 232 + ghc948 = callPackage ../development/compilers/ghc/9.4.8.fixme.nix { 233 233 bootPkgs = 234 234 # Building with 9.2 is broken due to 235 235 # https://gitlab.haskell.org/ghc/ghc/-/issues/21914