···11+# DO NOT port this expression to hadrian. It is not possible to build a GHC22+# cross compiler with 9.4.* and hadrian.33+{ lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages44+55+# build-tools66+, bootPkgs77+, autoconf, automake, coreutils, fetchpatch, fetchurl, perl, python3, m4, sphinx88+, xattr, autoSignDarwinBinariesHook99+, bash1010+1111+, libiconv ? null, ncurses1212+, glibcLocales ? null1313+1414+, # GHC can be built with system libffi or a bundled one.1515+ libffi ? null1616+1717+, useLLVM ? !(stdenv.targetPlatform.isx861818+ || stdenv.targetPlatform.isPower1919+ || stdenv.targetPlatform.isSparc2020+ || stdenv.targetPlatform.isAarch64)2121+, # LLVM is conceptually a run-time-only dependency, but for2222+ # non-x86, we need LLVM to bootstrap later stages, so it becomes a2323+ # build-time dependency too.2424+ buildTargetLlvmPackages, llvmPackages2525+2626+, # If enabled, GHC will be built with the GPL-free but slightly slower native2727+ # bignum backend instead of the faster but GPLed gmp backend.2828+ enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp2929+ && lib.meta.availableOn stdenv.targetPlatform gmp)3030+, gmp3131+3232+, # If enabled, use -fPIC when compiling static libs.3333+ enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform3434+3535+, enableProfiledLibs ? true3636+3737+, # Whether to build dynamic libs for the standard library (on the target3838+ # platform). Static libs are always built.3939+ enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic4040+4141+, # Whether to build terminfo.4242+ enableTerminfo ? !stdenv.targetPlatform.isWindows4343+4444+, # What flavour to build. An empty string indicates no4545+ # specific flavour and falls back to ghc default values.4646+ ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)4747+ (if useLLVM then "perf-cross" else "perf-cross-ncg")4848+4949+, # Whether to build sphinx documentation.5050+ enableDocs ? (5151+ # Docs disabled for musl and cross because it's a large task to keep5252+ # all `sphinx` dependencies building in those environments.5353+ # `sphinx` pulls in among others:5454+ # Ruby, Python, Perl, Rust, OpenGL, Xorg, gtk, LLVM.5555+ (stdenv.targetPlatform == stdenv.hostPlatform)5656+ && !stdenv.hostPlatform.isMusl5757+ )5858+5959+, enableHaddockProgram ?6060+ # Disabled for cross; see note [HADDOCK_DOCS].6161+ (stdenv.targetPlatform == stdenv.hostPlatform)6262+6363+, # Whether to disable the large address space allocator6464+ # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/6565+ disableLargeAddressSpace ? stdenv.targetPlatform.isiOS6666+}:6767+6868+assert !enableNativeBignum -> gmp != null;6969+7070+# Cross cannot currently build the `haddock` program for silly reasons,7171+# see note [HADDOCK_DOCS].7272+assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram;7373+7474+let7575+ inherit (stdenv) buildPlatform hostPlatform targetPlatform;7676+7777+ inherit (bootPkgs) ghc;7878+7979+ # TODO(@Ericson2314) Make unconditional8080+ targetPrefix = lib.optionalString8181+ (targetPlatform != hostPlatform)8282+ "${targetPlatform.config}-";8383+8484+ buildMK = ''8585+ BuildFlavour = ${ghcFlavour}8686+ ifneq \"\$(BuildFlavour)\" \"\"8787+ include mk/flavours/\$(BuildFlavour).mk8888+ endif8989+ BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"}9090+ BUILD_SPHINX_PDF = NO9191+ '' +9292+ # Note [HADDOCK_DOCS]:9393+ # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock`9494+ # program is built (which we generally always want to have a complete GHC install)9595+ # and whether it is run on the GHC sources to generate hyperlinked source code9696+ # (which is impossible for cross-compilation); see:9797+ # https://gitlab.haskell.org/ghc/ghc/-/issues/200779898+ # This implies that currently a cross-compiled GHC will never have a `haddock`9999+ # program, so it can never generate haddocks for any packages.100100+ # If this is solved in the future, we'd like to unconditionally101101+ # build the haddock program (removing the `enableHaddockProgram` option).102102+ ''103103+ HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"}104104+ # Build haddocks for boot packages with hyperlinking105105+ EXTRA_HADDOCK_OPTS += --hyperlinked-source --quickjump106106+107107+ DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}108108+ BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"}109109+ '' + lib.optionalString (targetPlatform != hostPlatform) ''110110+ Stage1Only = ${if targetPlatform.system == hostPlatform.system then "NO" else "YES"}111111+ CrossCompilePrefix = ${targetPrefix}112112+ '' + lib.optionalString (!enableProfiledLibs) ''113113+ GhcLibWays = "v dyn"114114+ '' +115115+ # -fexternal-dynamic-refs apparently (because it's not clear from the documentation)116116+ # makes the GHC RTS able to load static libraries, which may be needed for TemplateHaskell.117117+ # This solution was described in https://www.tweag.io/blog/2020-09-30-bazel-static-haskell118118+ lib.optionalString enableRelocatedStaticLibs ''119119+ GhcLibHcOpts += -fPIC -fexternal-dynamic-refs120120+ GhcRtsHcOpts += -fPIC -fexternal-dynamic-refs121121+ '' + lib.optionalString targetPlatform.useAndroidPrebuilt ''122122+ EXTRA_CC_OPTS += -std=gnu99123123+ '';124124+125125+ # Splicer will pull out correct variations126126+ libDeps = platform: lib.optional enableTerminfo ncurses127127+ ++ [libffi]128128+ ++ lib.optional (!enableNativeBignum) gmp129129+ ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;130130+131131+ # TODO(@sternenseemann): is buildTarget LLVM unnecessary?132132+ # GHC doesn't seem to have {LLC,OPT}_HOST133133+ toolsForTarget = [134134+ pkgsBuildTarget.targetPackages.stdenv.cc135135+ ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;136136+137137+ targetCC = builtins.head toolsForTarget;138138+139139+ # Sometimes we have to dispatch between the bintools wrapper and the unwrapped140140+ # derivation for certain tools depending on the platform.141141+ bintoolsFor = {142142+ # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is143143+ # part of the bintools wrapper (due to codesigning requirements), but not on144144+ # x86_64-darwin.145145+ install_name_tool =146146+ if stdenv.targetPlatform.isAarch64147147+ then targetCC.bintools148148+ else targetCC.bintools.bintools;149149+ # Same goes for strip.150150+ strip =151151+ # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold"152152+ if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin153153+ then targetCC.bintools154154+ else targetCC.bintools.bintools;155155+ };156156+157157+ # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues.158158+ # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856159159+ # see #84670 and #49071 for more background.160160+ useLdGold = targetPlatform.linker == "gold" ||161161+ (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl);162162+163163+ # Makes debugging easier to see which variant is at play in `nix-store -q --tree`.164164+ variantSuffix = lib.concatStrings [165165+ (lib.optionalString stdenv.hostPlatform.isMusl "-musl")166166+ (lib.optionalString enableNativeBignum "-native-bignum")167167+ ];168168+169169+in170170+171171+# C compiler, bintools and LLVM are used at build time, but will also leak into172172+# the resulting GHC's settings file and used at runtime. This means that we are173173+# currently only able to build GHC if hostPlatform == buildPlatform.174174+assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc;175175+assert buildTargetLlvmPackages.llvm == llvmPackages.llvm;176176+assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang;177177+178178+stdenv.mkDerivation (rec {179179+ version = "9.4.8";180180+ pname = "${targetPrefix}ghc${variantSuffix}";181181+182182+ src = fetchurl {183183+ url = "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz";184184+ sha256 = "0bf407eb67fe3e3c24b0f4c8dea8cb63e07f63ca0f76cf2058565143507ab85e";185185+ };186186+187187+ enableParallelBuilding = true;188188+189189+ outputs = [ "out" "doc" ];190190+191191+ patches = [192192+ # Don't generate code that doesn't compile when --enable-relocatable is passed to Setup.hs193193+ # Can be removed if the Cabal library included with ghc backports the linked fix194194+ (fetchpatch {195195+ url = "https://github.com/haskell/cabal/commit/6c796218c92f93c95e94d5ec2d077f6956f68e98.patch";196196+ stripLen = 1;197197+ extraPrefix = "libraries/Cabal/";198198+ sha256 = "sha256-yRQ6YmMiwBwiYseC5BsrEtDgFbWvst+maGgDtdD0vAY=";199199+ })200200+201201+ # Fix docs build with Sphinx >= 7 https://gitlab.haskell.org/ghc/ghc/-/issues/24129202202+ ./docs-sphinx-7.patch203203+ ] ++ lib.optionals (stdenv.targetPlatform.isDarwin && stdenv.targetPlatform.isAarch64) [204204+ # Prevent the paths module from emitting symbols that we don't use205205+ # when building with separate outputs.206206+ #207207+ # These cause problems as they're not eliminated by GHC's dead code208208+ # elimination on aarch64-darwin. (see209209+ # https://github.com/NixOS/nixpkgs/issues/140774 for details).210210+ ./Cabal-3.6-3.8-paths-fix-cycle-aarch64-darwin.patch211211+ ];212212+213213+ postPatch = "patchShebangs .";214214+215215+ # GHC needs the locale configured during the Haddock phase.216216+ LANG = "en_US.UTF-8";217217+218218+ # GHC is a bit confused on its cross terminology.219219+ # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths220220+ preConfigure = ''221221+ for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do222222+ export "''${env#TARGET_}=''${!env}"223223+ done224224+ # GHC is a bit confused on its cross terminology, as these would normally be225225+ # the *host* tools.226226+ export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"227227+ export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++"228228+ # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177229229+ export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}"230230+ export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"231231+ export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"232232+ export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"233233+ export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"234234+ export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"235235+ export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip"236236+ '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") ''237237+ export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool"238238+ export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool"239239+ '' + lib.optionalString useLLVM ''240240+ export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc"241241+ export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt"242242+ '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) ''243243+ # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm244244+ export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang"245245+ '' + ''246246+247247+ echo -n "${buildMK}" > mk/build.mk248248+249249+ sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure250250+ '' + lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") ''251251+ export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive"252252+ '' + lib.optionalString (!stdenv.isDarwin) ''253253+ export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}"254254+ '' + lib.optionalString stdenv.isDarwin ''255255+ export NIX_LDFLAGS+=" -no_dtrace_dof"256256+257257+ # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7258258+ export XATTR=${lib.getBin xattr}/bin/xattr259259+ '' + lib.optionalString targetPlatform.useAndroidPrebuilt ''260260+ 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-targets261261+ '' + lib.optionalString targetPlatform.isMusl ''262262+ echo "patching llvm-targets for musl targets..."263263+ echo "Cloning these existing '*-linux-gnu*' targets:"264264+ grep linux-gnu llvm-targets | sed 's/^/ /'265265+ echo "(go go gadget sed)"266266+ sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets267267+ echo "llvm-targets now contains these '*-linux-musl*' targets:"268268+ grep linux-musl llvm-targets | sed 's/^/ /'269269+270270+ echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"271271+ # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)272272+ for x in configure aclocal.m4; do273273+ substituteInPlace $x \274274+ --replace '*-android*|*-gnueabi*)' \275275+ '*-android*|*-gnueabi*|*-musleabi*)'276276+ done277277+ ''278278+ # HACK: allow bootstrapping with GHC 8.10 which works fine, as we don't have279279+ # binary 9.0 packaged. Bootstrapping with 9.2 is broken without hadrian.280280+ + ''281281+ substituteInPlace configure --replace \282282+ 'MinBootGhcVersion="9.0"' \283283+ 'MinBootGhcVersion="8.10"'284284+ '';285285+286286+ # TODO(@Ericson2314): Always pass "--target" and always prefix.287287+ configurePlatforms = [ "build" "host" ]288288+ ++ lib.optional (targetPlatform != hostPlatform) "target";289289+290290+ # `--with` flags for libraries needed for RTS linker291291+ configureFlags = [292292+ "--datadir=$doc/share/doc/ghc"293293+ "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"294294+ ] ++ lib.optionals (libffi != null) [295295+ "--with-system-libffi"296296+ "--with-ffi-includes=${targetPackages.libffi.dev}/include"297297+ "--with-ffi-libraries=${targetPackages.libffi.out}/lib"298298+ ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [299299+ "--with-gmp-includes=${targetPackages.gmp.dev}/include"300300+ "--with-gmp-libraries=${targetPackages.gmp.out}/lib"301301+ ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [302302+ "--with-iconv-includes=${libiconv}/include"303303+ "--with-iconv-libraries=${libiconv}/lib"304304+ ] ++ lib.optionals (targetPlatform != hostPlatform) [305305+ "--enable-bootstrap-with-devel-snapshot"306306+ ] ++ lib.optionals useLdGold [307307+ "CFLAGS=-fuse-ld=gold"308308+ "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"309309+ "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"310310+ ] ++ lib.optionals (disableLargeAddressSpace) [311311+ "--disable-large-address-space"312312+ ];313313+314314+ # Make sure we never relax`$PATH` and hooks support for compatibility.315315+ strictDeps = true;316316+317317+ # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself.318318+ dontAddExtraLibs = true;319319+320320+ nativeBuildInputs = [321321+ perl autoconf automake m4 python3322322+ ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour323323+ ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [324324+ autoSignDarwinBinariesHook325325+ ] ++ lib.optionals enableDocs [326326+ sphinx327327+ ];328328+329329+ # For building runtime libs330330+ depsBuildTarget = toolsForTarget;331331+332332+ buildInputs = [ perl bash ] ++ (libDeps hostPlatform);333333+334334+ depsTargetTarget = map lib.getDev (libDeps targetPlatform);335335+ depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);336336+337337+ # required, because otherwise all symbols from HSffi.o are stripped, and338338+ # that in turn causes GHCi to abort339339+ stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols";340340+341341+ checkTarget = "test";342342+343343+ hardeningDisable =344344+ [ "format" ]345345+ # In nixpkgs, musl based builds currently enable `pie` hardening by default346346+ # (see `defaultHardeningFlags` in `make-derivation.nix`).347347+ # But GHC cannot currently produce outputs that are ready for `-pie` linking.348348+ # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear.349349+ # See:350350+ # * https://github.com/NixOS/nixpkgs/issues/129247351351+ # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580352352+ ++ lib.optional stdenv.targetPlatform.isMusl "pie";353353+354354+ # big-parallel allows us to build with more than 2 cores on355355+ # Hydra which already warrants a significant speedup356356+ requiredSystemFeatures = [ "big-parallel" ];357357+358358+ postInstall = ''359359+ # Install the bash completion file.360360+ install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc361361+ '';362362+363363+ passthru = {364364+ inherit bootPkgs targetPrefix;365365+366366+ inherit llvmPackages;367367+ inherit enableShared;368368+369369+ # This is used by the haskell builder to query370370+ # the presence of the haddock program.371371+ hasHaddock = enableHaddockProgram;372372+373373+ # Our Cabal compiler name374374+ haskellCompilerName = "ghc-${version}";375375+ };376376+377377+ meta = {378378+ homepage = "http://haskell.org/ghc";379379+ description = "The Glasgow Haskell Compiler";380380+ maintainers = with lib.maintainers; [381381+ guibou382382+ ] ++ lib.teams.haskell.members;383383+ timeout = 24 * 3600;384384+ inherit (ghc.meta) license platforms;385385+ };386386+387387+} // lib.optionalAttrs targetPlatform.useAndroidPrebuilt {388388+ dontStrip = true;389389+ dontPatchELF = true;390390+ noAuditTmpdir = true;391391+})
+33-2
pkgs/top-level/haskell-packages.nix
···2525 "ghc945"2626 "ghc946"2727 "ghc947"2828+ "ghc948"2829 "ghc94"2930 "ghc96"3031 "ghc962"···5150 "ghc945"5251 "ghc946"5352 "ghc947"5353+ "ghc948"5454 "ghc96"5555 "ghc962"5656 "ghc963"···365363 buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_12;366364 llvmPackages = pkgs.llvmPackages_12;367365 };368368- ghc94 = compiler.ghc947;366366+ ghc948 = callPackage ../development/compilers/ghc/9.4.8.nix {367367+ bootPkgs =368368+ # Building with 9.2 is broken due to369369+ # https://gitlab.haskell.org/ghc/ghc/-/issues/21914370370+ # Use 8.10 as a workaround where possible to keep bootstrap path short.371371+372372+ # On ARM text won't build with GHC 8.10.*373373+ if stdenv.hostPlatform.isAarch then374374+ # TODO(@sternenseemann): package bindist375375+ packages.ghc902376376+ # No suitable bindists for powerpc64le377377+ else if stdenv.hostPlatform.isPower64 && stdenv.hostPlatform.isLittleEndian then378378+ packages.ghc902379379+ else380380+ packages.ghc8107Binary;381381+ inherit (buildPackages.python3Packages) sphinx;382382+ # Need to use apple's patched xattr until383383+ # https://github.com/xattr/xattr/issues/44 and384384+ # https://github.com/xattr/xattr/issues/55 are solved.385385+ inherit (buildPackages.darwin) xattr autoSignDarwinBinariesHook;386386+ # Support range >= 10 && < 14387387+ buildTargetLlvmPackages = pkgsBuildTarget.llvmPackages_12;388388+ llvmPackages = pkgs.llvmPackages_12;389389+ };390390+ ghc94 = compiler.ghc948;369391 ghc962 = callPackage ../development/compilers/ghc/9.6.2.nix {370392 bootPkgs =371393 # For GHC 9.2 no armv7l bindists are available.···584558 ghc = bh.compiler.ghc947;585559 compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-9.4.x.nix { };586560 };587587- ghc94 = packages.ghc947;561561+ ghc948 = callPackage ../development/haskell-modules {562562+ buildHaskellPackages = bh.packages.ghc948;563563+ ghc = bh.compiler.ghc948;564564+ compilerConfig = callPackage ../development/haskell-modules/configuration-ghc-9.4.x.nix { };565565+ };566566+ ghc94 = packages.ghc948;588567 ghc962 = callPackage ../development/haskell-modules {589568 buildHaskellPackages = bh.packages.ghc962;590569 ghc = bh.compiler.ghc962;