···11{
22- "commit": "e456824564bb5457549a70dc03c7ae00b3dfaec3",
33- "url": "https://github.com/commercialhaskell/all-cabal-hashes/archive/e456824564bb5457549a70dc03c7ae00b3dfaec3.tar.gz",
44- "sha256": "0kvjhghjhs5b6ldp4yyyy158lqk54aahqqp4n0mm67p7qv09i5xr",
55- "msg": "Update from Hackage at 2022-09-19T12:29:18Z"
22+ "commit": "12bd870a1ed095ff74dbe08ef4d5d930821e878d",
33+ "url": "https://github.com/commercialhaskell/all-cabal-hashes/archive/12bd870a1ed095ff74dbe08ef4d5d930821e878d.tar.gz",
44+ "sha256": "196pl60xyv4ij1nxz4hv5fhmliisb5dmxl8w1jfl07z22cpd92p5",
55+ "msg": "Update from Hackage at 2022-09-21T15:25:15Z"
66}
+2-3
pkgs/development/compilers/ghc/9.4.2.nix
···11-# Preliminary GHC 9.4.2 expression using the make build system.
22-# TODO(@sternenseemann): port to hadrian, so we are prepared for 9.6
33-# where make support will be dropped.
11+# DO NOT port this expression to hadrian. It is not possible to build a GHC
22+# cross compiler with 9.4.* and hadrian.
43{ lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages
5465# build-tools
+491
pkgs/development/compilers/ghc/common-hadrian.nix
···11+{ version
22+, rev ? null
33+, sha256
44+, url ?
55+ if rev != null
66+ then "https://gitlab.haskell.org/ghc/ghc.git"
77+ else "https://downloads.haskell.org/ghc/${version}/ghc-${version}-src.tar.xz"
88+99+}:
1010+1111+{ lib
1212+, stdenv
1313+, pkgsBuildTarget
1414+, pkgsHostTarget
1515+, targetPackages
1616+1717+# build-tools
1818+, bootPkgs
1919+, autoconf
2020+, automake
2121+, coreutils
2222+, fetchpatch
2323+, fetchurl
2424+, fetchgit
2525+, perl
2626+, python3
2727+, m4
2828+, sphinx
2929+, xattr
3030+, autoSignDarwinBinariesHook
3131+, bash
3232+3333+, libiconv ? null, ncurses
3434+, glibcLocales ? null
3535+3636+, # GHC can be built with system libffi or a bundled one.
3737+ libffi ? null
3838+3939+, useLLVM ? !(stdenv.targetPlatform.isx86
4040+ || stdenv.targetPlatform.isPower
4141+ || stdenv.targetPlatform.isSparc
4242+ || (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin))
4343+, # LLVM is conceptually a run-time-only depedendency, but for
4444+ # non-x86, we need LLVM to bootstrap later stages, so it becomes a
4545+ # build-time dependency too.
4646+ buildTargetLlvmPackages
4747+, llvmPackages
4848+4949+, # If enabled, GHC will be built with the GPL-free but slightly slower native
5050+ # bignum backend instead of the faster but GPLed gmp backend.
5151+ enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp)
5252+, gmp
5353+5454+, # If enabled, use -fPIC when compiling static libs.
5555+ enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform
5656+5757+ # aarch64 outputs otherwise exceed 2GB limit
5858+, enableProfiledLibs ? !stdenv.targetPlatform.isAarch64
5959+6060+, # Whether to build dynamic libs for the standard library (on the target
6161+ # platform). Static libs are always built.
6262+ enableShared ? with stdenv.targetPlatform; !isWindows && !useiOSPrebuilt && !isStatic
6363+6464+, # Whether to build terminfo.
6565+ enableTerminfo ? !stdenv.targetPlatform.isWindows
6666+6767+, # Libdw.c only supports x86_64, i686 and s390x as of 2022-08-04
6868+ enableDwarf ? (stdenv.targetPlatform.isx86 ||
6969+ (stdenv.targetPlatform.isS390 && stdenv.targetPlatform.is64bit)) &&
7070+ lib.meta.availableOn stdenv.hostPlatform elfutils &&
7171+ lib.meta.availableOn stdenv.targetPlatform elfutils &&
7272+ # HACK: elfutils is marked as broken on static platforms
7373+ # which availableOn can't tell.
7474+ !stdenv.targetPlatform.isStatic &&
7575+ !stdenv.hostPlatform.isStatic
7676+, elfutils
7777+7878+, # What flavour to build. Flavour string may contain a flavour and flavour
7979+ # transformers as accepted by hadrian.
8080+ ghcFlavour ?
8181+ let
8282+ # TODO(@sternenseemann): does using the static flavour make sense?
8383+ baseFlavour = "release";
8484+ # Note: in case hadrian's flavour transformers cease being expressive
8585+ # enough for us, we'll need to resort to defining a "nixpkgs" flavour
8686+ # in hadrianUserSettings and using that instead.
8787+ transformers =
8888+ lib.optionals useLLVM [ "llvm" ]
8989+ ++ lib.optionals (!enableShared) [
9090+ "fully_static"
9191+ "no_dynamic_ghc"
9292+ ]
9393+ ++ lib.optionals (!enableProfiledLibs) [ "no_profiled_libs" ]
9494+ # While split sections are now enabled by default in ghc 8.8 for windows,
9595+ # they seem to lead to `too many sections` errors when building base for
9696+ # profiling.
9797+ ++ lib.optionals (!stdenv.targetPlatform.isWindows) [ "split_sections" ]
9898+ ;
9999+ in
100100+ baseFlavour + lib.concatMapStrings (t: "+${t}") transformers
101101+102102+, # Contents of the UserSettings.hs file to use when compiling hadrian.
103103+ hadrianUserSettings ? ''
104104+ module UserSettings (
105105+ userFlavours, userPackages, userDefaultFlavour,
106106+ verboseCommand, buildProgressColour, successColour, finalStage
107107+ ) where
108108+109109+ import Flavour.Type
110110+ import Expression
111111+ import {-# SOURCE #-} Settings.Default
112112+113113+ -- no way to set this via the command line
114114+ finalStage :: Stage
115115+ finalStage = ${
116116+ if stdenv.hostPlatform == stdenv.targetPlatform
117117+ then "Stage2" # native compiler
118118+ else "Stage1" # cross compiler
119119+ }
120120+121121+ userDefaultFlavour :: String
122122+ userDefaultFlavour = "release"
123123+124124+ userFlavours :: [Flavour]
125125+ userFlavours = []
126126+127127+ -- Disable Colours
128128+ buildProgressColour :: BuildProgressColour
129129+ buildProgressColour = mkBuildProgressColour (Dull Reset)
130130+ successColour :: SuccessColour
131131+ successColour = mkSuccessColour (Dull Reset)
132132+133133+ -- taken from src/UserSettings.hs unchanged, need to be there
134134+ userPackages :: [Package]
135135+ userPackages = []
136136+ verboseCommand :: Predicate
137137+ verboseCommand = do
138138+ verbosity <- expr getVerbosity
139139+ return $ verbosity >= Verbose
140140+ ''
141141+142142+, # Whether to build sphinx documentation.
143143+ enableDocs ? (
144144+ # Docs disabled for musl and cross because it's a large task to keep
145145+ # all `sphinx` dependencies building in those environments.
146146+ # `sphinx` pulls in among others:
147147+ # Ruby, Python, Perl, Rust, OpenGL, Xorg, gtk, LLVM.
148148+ (stdenv.targetPlatform == stdenv.hostPlatform)
149149+ && !stdenv.hostPlatform.isMusl
150150+ )
151151+152152+, # Whether to disable the large address space allocator
153153+ # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
154154+ disableLargeAddressSpace ? stdenv.targetPlatform.isiOS
155155+}:
156156+157157+assert !enableNativeBignum -> gmp != null;
158158+159159+assert stdenv.hostPlatform == stdenv.targetPlatform || throw ''
160160+ hadrian doesn't support building an installable GHC cross-compiler at the moment.
161161+ Consider using GHC 9.4.2 or lower which support this via the make build system.
162162+ See also: https://gitlab.haskell.org/ghc/ghc/-/issues/22090
163163+'';
164164+165165+let
166166+ src = (if rev != null then fetchgit else fetchurl) ({
167167+ inherit url sha256;
168168+ } // lib.optionalAttrs (rev != null) {
169169+ inherit rev;
170170+ });
171171+172172+ inherit (stdenv) buildPlatform hostPlatform targetPlatform;
173173+174174+ inherit (bootPkgs) ghc;
175175+176176+ # TODO(@Ericson2314) Make unconditional
177177+ targetPrefix = lib.optionalString
178178+ (targetPlatform != hostPlatform)
179179+ "${targetPlatform.config}-";
180180+181181+ hadrianSettings =
182182+ # -fexternal-dynamic-refs apparently (because it's not clear from the
183183+ # documentation) makes the GHC RTS able to load static libraries, which may
184184+ # be needed for TemplateHaskell. This solution was described in
185185+ # https://www.tweag.io/blog/2020-09-30-bazel-static-haskell
186186+ lib.optionals enableRelocatedStaticLibs [
187187+ "*.*.rts.*.opts += -fPIC -fexternal-dynamic-refs"
188188+ "*.*.ghc.*.opts += -fPIC -fexternal-dynamic-refs"
189189+ ]
190190+ ++ lib.optionals targetPlatform.useAndroidPrebuilt [
191191+ "*.*.ghc.c.opts += -optc-std=gnu99"
192192+ ];
193193+194194+ # GHC's build system hadrian built from the GHC-to-build's source tree
195195+ # using our bootstrap GHC.
196196+ hadrian = bootPkgs.callPackage ../../tools/haskell/hadrian {
197197+ ghcSrc = src;
198198+ ghcVersion = version;
199199+ userSettings = hadrianUserSettings;
200200+ };
201201+202202+ # Splicer will pull out correct variations
203203+ libDeps = platform: lib.optional enableTerminfo ncurses
204204+ ++ [libffi]
205205+ # Bindist configure script fails w/o elfutils in linker search path
206206+ # https://gitlab.haskell.org/ghc/ghc/-/issues/22081
207207+ ++ lib.optional enableDwarf elfutils
208208+ ++ lib.optional (!enableNativeBignum) gmp
209209+ ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv;
210210+211211+ # TODO(@sternenseemann): is buildTarget LLVM unnecessary?
212212+ # GHC doesn't seem to have {LLC,OPT}_HOST
213213+ toolsForTarget = [
214214+ pkgsBuildTarget.targetPackages.stdenv.cc
215215+ ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;
216216+217217+ targetCC = builtins.head toolsForTarget;
218218+219219+ # Sometimes we have to dispatch between the bintools wrapper and the unwrapped
220220+ # derivation for certain tools depending on the platform.
221221+ bintoolsFor = {
222222+ # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is
223223+ # part of the bintools wrapper (due to codesigning requirements), but not on
224224+ # x86_64-darwin.
225225+ install_name_tool =
226226+ if stdenv.targetPlatform.isAarch64
227227+ then targetCC.bintools
228228+ else targetCC.bintools.bintools;
229229+ # Same goes for strip.
230230+ strip =
231231+ # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold"
232232+ if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin
233233+ then targetCC.bintools
234234+ else targetCC.bintools.bintools;
235235+ };
236236+237237+ # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues.
238238+ # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856
239239+ # see #84670 and #49071 for more background.
240240+ useLdGold = targetPlatform.linker == "gold" ||
241241+ (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl);
242242+243243+ # Makes debugging easier to see which variant is at play in `nix-store -q --tree`.
244244+ variantSuffix = lib.concatStrings [
245245+ (lib.optionalString stdenv.hostPlatform.isMusl "-musl")
246246+ (lib.optionalString enableNativeBignum "-native-bignum")
247247+ ];
248248+249249+in
250250+251251+# C compiler, bintools and LLVM are used at build time, but will also leak into
252252+# the resulting GHC's settings file and used at runtime. This means that we are
253253+# currently only able to build GHC if hostPlatform == buildPlatform.
254254+assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc;
255255+assert buildTargetLlvmPackages.llvm == llvmPackages.llvm;
256256+assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang;
257257+258258+stdenv.mkDerivation ({
259259+ pname = "${targetPrefix}ghc${variantSuffix}";
260260+ inherit version;
261261+262262+ inherit src;
263263+264264+ enableParallelBuilding = true;
265265+266266+ postPatch = ''
267267+ patchShebangs --build .
268268+ '';
269269+270270+ # GHC needs the locale configured during the Haddock phase.
271271+ LANG = "en_US.UTF-8";
272272+273273+ # GHC is a bit confused on its cross terminology.
274274+ # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths
275275+ preConfigure = ''
276276+ for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
277277+ export "''${env#TARGET_}=''${!env}"
278278+ done
279279+ # GHC is a bit confused on its cross terminology, as these would normally be
280280+ # the *host* tools.
281281+ export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
282282+ export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++"
283283+ # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
284284+ export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}"
285285+ export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
286286+ export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
287287+ export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
288288+ export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
289289+ export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
290290+ export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip"
291291+ '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") ''
292292+ export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool"
293293+ export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool"
294294+ '' + lib.optionalString useLLVM ''
295295+ export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc"
296296+ export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt"
297297+ '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) ''
298298+ # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm
299299+ export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang"
300300+ '' +
301301+ lib.optionalString (stdenv.isLinux && hostPlatform.libc == "glibc") ''
302302+ export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive"
303303+ '' + lib.optionalString (!stdenv.isDarwin) ''
304304+ export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}"
305305+ '' + lib.optionalString stdenv.isDarwin ''
306306+ export NIX_LDFLAGS+=" -no_dtrace_dof"
307307+308308+ # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7
309309+ export XATTR=${lib.getBin xattr}/bin/xattr
310310+ ''
311311+ # If we are not using release tarballs, some files need to be generated using
312312+ # the boot script.
313313+ + lib.optionalString (rev != null) ''
314314+ echo ${version} > VERSION
315315+ echo ${rev} > GIT_COMMIT_ID
316316+ ./boot
317317+ ''
318318+ + lib.optionalString targetPlatform.useAndroidPrebuilt ''
319319+ 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
320320+ '' + lib.optionalString targetPlatform.isMusl ''
321321+ echo "patching llvm-targets for musl targets..."
322322+ echo "Cloning these existing '*-linux-gnu*' targets:"
323323+ grep linux-gnu llvm-targets | sed 's/^/ /'
324324+ echo "(go go gadget sed)"
325325+ sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets
326326+ echo "llvm-targets now contains these '*-linux-musl*' targets:"
327327+ grep linux-musl llvm-targets | sed 's/^/ /'
328328+329329+ echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"
330330+ # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)
331331+ for x in configure aclocal.m4; do
332332+ substituteInPlace $x \
333333+ --replace '*-android*|*-gnueabi*)' \
334334+ '*-android*|*-gnueabi*|*-musleabi*)'
335335+ done
336336+ ''
337337+ # Create bash array hadrianFlagsArray for use in buildPhase. Do it in
338338+ # preConfigure, so overrideAttrs can be used to modify it effectively.
339339+ # hadrianSettings are passed via the command line so they are more visible
340340+ # in the build log.
341341+ + ''
342342+ hadrianFlagsArray=(
343343+ "-j$NIX_BUILD_CORES"
344344+ ${lib.escapeShellArgs hadrianSettings}
345345+ )
346346+ '';
347347+348348+ # TODO(@Ericson2314): Always pass "--target" and always prefix.
349349+ configurePlatforms = [ "build" "host" ]
350350+ ++ lib.optional (targetPlatform != hostPlatform) "target";
351351+352352+ # `--with` flags for libraries needed for RTS linker
353353+ configureFlags = [
354354+ "--datadir=$doc/share/doc/ghc"
355355+ "--with-curses-includes=${ncurses.dev}/include" "--with-curses-libraries=${ncurses.out}/lib"
356356+ ] ++ lib.optionals (libffi != null) [
357357+ "--with-system-libffi"
358358+ "--with-ffi-includes=${targetPackages.libffi.dev}/include"
359359+ "--with-ffi-libraries=${targetPackages.libffi.out}/lib"
360360+ ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [
361361+ "--with-gmp-includes=${targetPackages.gmp.dev}/include"
362362+ "--with-gmp-libraries=${targetPackages.gmp.out}/lib"
363363+ ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
364364+ "--with-iconv-includes=${libiconv}/include"
365365+ "--with-iconv-libraries=${libiconv}/lib"
366366+ ] ++ lib.optionals (targetPlatform != hostPlatform) [
367367+ "--enable-bootstrap-with-devel-snapshot"
368368+ ] ++ lib.optionals useLdGold [
369369+ "CFLAGS=-fuse-ld=gold"
370370+ "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
371371+ "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
372372+ ] ++ lib.optionals (disableLargeAddressSpace) [
373373+ "--disable-large-address-space"
374374+ ] ++ lib.optionals enableDwarf [
375375+ "--enable-dwarf-unwind"
376376+ "--with-libdw-includes=${lib.getDev elfutils}/include"
377377+ "--with-libdw-libraries=${lib.getLib elfutils}/lib"
378378+ ];
379379+380380+ # Make sure we never relax`$PATH` and hooks support for compatibility.
381381+ strictDeps = true;
382382+383383+ # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself.
384384+ dontAddExtraLibs = true;
385385+386386+ nativeBuildInputs = [
387387+ perl ghc hadrian bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
388388+ ] ++ lib.optionals (rev != null) [
389389+ # We need to execute the boot script
390390+ autoconf automake m4 python3
391391+ ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
392392+ autoSignDarwinBinariesHook
393393+ ] ++ lib.optionals enableDocs [
394394+ sphinx
395395+ ];
396396+397397+ # For building runtime libs
398398+ depsBuildTarget = toolsForTarget;
399399+400400+ buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
401401+402402+ depsTargetTarget = map lib.getDev (libDeps targetPlatform);
403403+ depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);
404404+405405+ hadrianFlags = [
406406+ "--flavour=${ghcFlavour}"
407407+ "--bignum=${if enableNativeBignum then "native" else "gmp"}"
408408+ "--docs=${if enableDocs then "no-sphinx-pdfs" else "no-sphinx"}"
409409+ ];
410410+411411+ buildPhase = ''
412412+ runHook preBuild
413413+414414+ # hadrianFlagsArray is created in preConfigure
415415+ echo "hadrianFlags: $hadrianFlags ''${hadrianFlagsArray}"
416416+417417+ # We need to go via the bindist for installing
418418+ hadrian $hadrianFlags "''${hadrianFlagsArray}" binary-dist-dir
419419+420420+ runHook postBuild
421421+ '';
422422+423423+ # required, because otherwise all symbols from HSffi.o are stripped, and
424424+ # that in turn causes GHCi to abort
425425+ stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols";
426426+427427+ checkTarget = "test";
428428+429429+ hardeningDisable =
430430+ [ "format" ]
431431+ # In nixpkgs, musl based builds currently enable `pie` hardening by default
432432+ # (see `defaultHardeningFlags` in `make-derivation.nix`).
433433+ # But GHC cannot currently produce outputs that are ready for `-pie` linking.
434434+ # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear.
435435+ # See:
436436+ # * https://github.com/NixOS/nixpkgs/issues/129247
437437+ # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580
438438+ ++ lib.optional stdenv.targetPlatform.isMusl "pie";
439439+440440+ # big-parallel allows us to build with more than 2 cores on
441441+ # Hydra which already warrants a significant speedup
442442+ requiredSystemFeatures = [ "big-parallel" ];
443443+444444+ outputs = [ "out" "doc" ];
445445+446446+ # We need to configure the bindist *again* before installing
447447+ # https://gitlab.haskell.org/ghc/ghc/-/issues/22058
448448+ # TODO(@sternenseemann): it would be nice if the bindist could be an intermediate
449449+ # derivation, but since it is > 2GB even on x86_64-linux, not a good idea?
450450+ preInstall = ''
451451+ pushd _build/bindist/*
452452+453453+ ./configure $configureFlags "''${configureFlagsArray[@]}"
454454+ '';
455455+456456+ postInstall = ''
457457+ # leave bindist directory
458458+ popd
459459+460460+ # Install the bash completion file.
461461+ install -Dm 644 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
462462+ '';
463463+464464+ passthru = {
465465+ inherit bootPkgs targetPrefix;
466466+467467+ inherit llvmPackages;
468468+ inherit enableShared;
469469+470470+ # Our Cabal compiler name
471471+ haskellCompilerName = "ghc-${version}";
472472+473473+ # Expose hadrian used for bootstrapping, for debugging purposes
474474+ inherit hadrian;
475475+ };
476476+477477+ meta = {
478478+ homepage = "http://haskell.org/ghc";
479479+ description = "The Glasgow Haskell Compiler";
480480+ maintainers = with lib.maintainers; [
481481+ guibou
482482+ ] ++ lib.teams.haskell.members;
483483+ timeout = 24 * 3600;
484484+ inherit (ghc.meta) license platforms;
485485+ };
486486+487487+ dontStrip = targetPlatform.useAndroidPrebuilt || targetPlatform.isWasm;
488488+} // lib.optionalAttrs targetPlatform.useAndroidPrebuilt {
489489+ dontPatchELF = true;
490490+ noAuditTmpdir = true;
491491+})
+5-375
pkgs/development/compilers/ghc/head.nix
···11-{ lib, stdenv, pkgsBuildTarget, pkgsHostTarget, targetPackages
22-33-# build-tools
44-, bootPkgs
55-, autoconf, autoreconfHook, automake, coreutils, fetchgit, perl, python3, m4, sphinx
66-, xattr, autoSignDarwinBinariesHook
77-, bash
88-99-, libiconv ? null, ncurses
1010-1111-, # GHC can be built with system libffi or a bundled one.
1212- libffi ? null
1313-1414- # Libdw.c only supports x86_64, i686 and s390x
1515-, enableDwarf ? (stdenv.targetPlatform.isx86 ||
1616- (stdenv.targetPlatform.isS390 && stdenv.targetPlatform.is64bit)) &&
1717- lib.meta.availableOn stdenv.hostPlatform elfutils &&
1818- lib.meta.availableOn stdenv.targetPlatform elfutils
1919-, elfutils # for DWARF support
2020-2121-, useLLVM ? !(stdenv.targetPlatform.isx86
2222- || stdenv.targetPlatform.isPower
2323- || stdenv.targetPlatform.isSparc
2424- || (stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin))
2525-, # LLVM is conceptually a run-time-only depedendency, but for
2626- # non-x86, we need LLVM to bootstrap later stages, so it becomes a
2727- # build-time dependency too.
2828- buildTargetLlvmPackages, llvmPackages
2929-3030-, # If enabled, GHC will be built with the GPL-free but slightly slower native
3131- # bignum backend instead of the faster but GPLed gmp backend.
3232- enableNativeBignum ? !(lib.meta.availableOn stdenv.hostPlatform gmp)
3333-, gmp
3434-3535-, # If enabled, use -fPIC when compiling static libs.
3636- enableRelocatedStaticLibs ? stdenv.targetPlatform != stdenv.hostPlatform
3737-3838- # aarch64 outputs otherwise exceed 2GB limit
3939-, enableProfiledLibs ? !stdenv.targetPlatform.isAarch64
4040-4141-, # Whether to build dynamic libs for the standard library (on the target
4242- # platform). Static libs are always built.
4343- enableShared ? !stdenv.targetPlatform.isWindows && !stdenv.targetPlatform.useiOSPrebuilt
4444-4545-, version ? "9.3.20220406"
4646-, # What flavour to build. An empty string indicates no
4747- # specific flavour and falls back to ghc default values.
4848- ghcFlavour ? lib.optionalString (stdenv.targetPlatform != stdenv.hostPlatform)
4949- (if useLLVM then "perf-cross" else "perf-cross-ncg")
5050-5151-, # Whether to build sphinx documentation.
5252- enableDocs ? (
5353- # Docs disabled for musl and cross because it's a large task to keep
5454- # all `sphinx` dependencies building in those environments.
5555- # `sphinx` pullls in among others:
5656- # Ruby, Python, Perl, Rust, OpenGL, Xorg, gtk, LLVM.
5757- (stdenv.targetPlatform == stdenv.hostPlatform)
5858- && !stdenv.hostPlatform.isMusl
5959- )
6060-6161-, enableHaddockProgram ?
6262- # Disabled for cross; see note [HADDOCK_DOCS].
6363- (stdenv.targetPlatform == stdenv.hostPlatform)
6464-6565-, # Whether to disable the large address space allocator
6666- # necessary fix for iOS: https://www.reddit.com/r/haskell/comments/4ttdz1/building_an_osxi386_to_iosarm64_cross_compiler/d5qvd67/
6767- disableLargeAddressSpace ? stdenv.targetPlatform.isiOS
6868-}:
6969-7070-assert !enableNativeBignum -> gmp != null;
7171-7272-# Cross cannot currently build the `haddock` program for silly reasons,
7373-# see note [HADDOCK_DOCS].
7474-assert (stdenv.targetPlatform != stdenv.hostPlatform) -> !enableHaddockProgram;
7575-7676-let
7777- inherit (stdenv) buildPlatform hostPlatform targetPlatform;
7878-7979- inherit (bootPkgs) ghc;
8080-8181- # TODO(@Ericson2314) Make unconditional
8282- targetPrefix = lib.optionalString
8383- (targetPlatform != hostPlatform)
8484- "${targetPlatform.config}-";
8585-8686- buildMK = dontStrip: ''
8787- BuildFlavour = ${ghcFlavour}
8888- ifneq \"\$(BuildFlavour)\" \"\"
8989- include mk/flavours/\$(BuildFlavour).mk
9090- endif
9191- BUILD_SPHINX_HTML = ${if enableDocs then "YES" else "NO"}
9292- BUILD_SPHINX_PDF = NO
9393- '' +
9494- # Note [HADDOCK_DOCS]:
9595- # Unfortunately currently `HADDOCK_DOCS` controls both whether the `haddock`
9696- # program is built (which we generally always want to have a complete GHC install)
9797- # and whether it is run on the GHC sources to generate hyperlinked source code
9898- # (which is impossible for cross-compilation); see:
9999- # https://gitlab.haskell.org/ghc/ghc/-/issues/20077
100100- # This implies that currently a cross-compiled GHC will never have a `haddock`
101101- # program, so it can never generate haddocks for any packages.
102102- # If this is solved in the future, we'd like to unconditionally
103103- # build the haddock program (removing the `enableHaddockProgram` option).
104104- ''
105105- HADDOCK_DOCS = ${if enableHaddockProgram then "YES" else "NO"}
106106- DYNAMIC_GHC_PROGRAMS = ${if enableShared then "YES" else "NO"}
107107- BIGNUM_BACKEND = ${if enableNativeBignum then "native" else "gmp"}
108108- '' + lib.optionalString (targetPlatform != hostPlatform) ''
109109- Stage1Only = ${if (targetPlatform.system == hostPlatform.system && !targetPlatform.isiOS) then "NO" else "YES"}
110110- CrossCompilePrefix = ${targetPrefix}
111111- '' + lib.optionalString dontStrip ''
112112- STRIP_CMD = :
113113- '' + lib.optionalString (!enableProfiledLibs) ''
114114- GhcLibWays = "v dyn"
115115- '' + lib.optionalString enableRelocatedStaticLibs ''
116116- GhcLibHcOpts += -fPIC
117117- GhcRtsHcOpts += -fPIC
118118- '' + lib.optionalString targetPlatform.useAndroidPrebuilt ''
119119- EXTRA_CC_OPTS += -std=gnu99
120120- ''
121121- # While split sections are now enabled by default in ghc 8.8 for windows,
122122- # they seem to lead to `too many sections` errors when building base for
123123- # profiling.
124124- + lib.optionalString targetPlatform.isWindows ''
125125- SplitSections = NO
126126- '';
127127-128128- # Splicer will pull out correct variations
129129- libDeps = platform:
130130- [libffi ncurses]
131131- ++ lib.optional (!enableNativeBignum) gmp
132132- ++ lib.optional (platform.libc != "glibc" && !targetPlatform.isWindows) libiconv
133133- ++ lib.optional enableDwarf elfutils;
134134-135135- # TODO(@sternenseemann): is buildTarget LLVM unnecessary?
136136- # GHC doesn't seem to have {LLC,OPT}_HOST
137137- toolsForTarget = [
138138- pkgsBuildTarget.targetPackages.stdenv.cc
139139- ] ++ lib.optional useLLVM buildTargetLlvmPackages.llvm;
140140-141141- targetCC = builtins.head toolsForTarget;
142142-143143- # Sometimes we have to dispatch between the bintools wrapper and the unwrapped
144144- # derivation for certain tools depending on the platform.
145145- bintoolsFor = {
146146- # GHC needs install_name_tool on all darwin platforms. On aarch64-darwin it is
147147- # part of the bintools wrapper (due to codesigning requirements), but not on
148148- # x86_64-darwin.
149149- install_name_tool =
150150- if stdenv.targetPlatform.isAarch64
151151- then targetCC.bintools
152152- else targetCC.bintools.bintools;
153153- # Same goes for strip.
154154- strip =
155155- # TODO(@sternenseemann): also use wrapper if linker == "bfd" or "gold"
156156- if stdenv.targetPlatform.isAarch64 && stdenv.targetPlatform.isDarwin
157157- then targetCC.bintools
158158- else targetCC.bintools.bintools;
159159- };
160160-161161- # Use gold either following the default, or to avoid the BFD linker due to some bugs / perf issues.
162162- # But we cannot avoid BFD when using musl libc due to https://sourceware.org/bugzilla/show_bug.cgi?id=23856
163163- # see #84670 and #49071 for more background.
164164- useLdGold = targetPlatform.linker == "gold" ||
165165- (targetPlatform.linker == "bfd" && (targetCC.bintools.bintools.hasGold or false) && !targetPlatform.isMusl);
166166-167167- # Makes debugging easier to see which variant is at play in `nix-store -q --tree`.
168168- variantSuffix = lib.concatStrings [
169169- (lib.optionalString stdenv.hostPlatform.isMusl "-musl")
170170- (lib.optionalString enableNativeBignum "-native-bignum")
171171- ];
172172-173173-in
174174-175175-# C compiler, bintools and LLVM are used at build time, but will also leak into
176176-# the resulting GHC's settings file and used at runtime. This means that we are
177177-# currently only able to build GHC if hostPlatform == buildPlatform.
178178-assert targetCC == pkgsHostTarget.targetPackages.stdenv.cc;
179179-assert buildTargetLlvmPackages.llvm == llvmPackages.llvm;
180180-assert stdenv.targetPlatform.isDarwin -> buildTargetLlvmPackages.clang == llvmPackages.clang;
181181-182182-stdenv.mkDerivation (rec {
183183- inherit version;
184184- inherit (src) rev;
185185- pname = "${targetPrefix}ghc${variantSuffix}";
186186-187187- src = fetchgit {
188188- url = "https://gitlab.haskell.org/ghc/ghc.git/";
189189- rev = "c44432db254d2fc960d7864e080cb50e65dfa7c6";
190190- sha256 = "0xagijcfcw3a19s6dmh6z7085lvkrakys3lcby4ncq1v0syh507h";
191191- };
192192-193193- enableParallelBuilding = true;
194194-195195- outputs = [ "out" "doc" ];
196196-197197- postPatch = "patchShebangs .";
198198-199199- # GHC is a bit confused on its cross terminology.
200200- # TODO(@sternenseemann): investigate coreutils dependencies and pass absolute paths
201201- preConfigure = ''
202202- for env in $(env | grep '^TARGET_' | sed -E 's|\+?=.*||'); do
203203- export "''${env#TARGET_}=''${!env}"
204204- done
205205- # GHC is a bit confused on its cross terminology, as these would normally be
206206- # the *host* tools.
207207- export CC="${targetCC}/bin/${targetCC.targetPrefix}cc"
208208- export CXX="${targetCC}/bin/${targetCC.targetPrefix}c++"
209209- # Use gold to work around https://sourceware.org/bugzilla/show_bug.cgi?id=16177
210210- # and more generally have a faster linker.
211211- export LD="${targetCC.bintools}/bin/${targetCC.bintools.targetPrefix}ld${lib.optionalString useLdGold ".gold"}"
212212- export AS="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}as"
213213- export AR="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ar"
214214- export NM="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}nm"
215215- export RANLIB="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}ranlib"
216216- export READELF="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}readelf"
217217- export STRIP="${bintoolsFor.strip}/bin/${bintoolsFor.strip.targetPrefix}strip"
218218- '' + lib.optionalString (stdenv.targetPlatform.linker == "cctools") ''
219219- export OTOOL="${targetCC.bintools.bintools}/bin/${targetCC.bintools.targetPrefix}otool"
220220- export INSTALL_NAME_TOOL="${bintoolsFor.install_name_tool}/bin/${bintoolsFor.install_name_tool.targetPrefix}install_name_tool"
221221- '' + lib.optionalString useLLVM ''
222222- export LLC="${lib.getBin buildTargetLlvmPackages.llvm}/bin/llc"
223223- export OPT="${lib.getBin buildTargetLlvmPackages.llvm}/bin/opt"
224224- '' + lib.optionalString (useLLVM && stdenv.targetPlatform.isDarwin) ''
225225- # LLVM backend on Darwin needs clang: https://downloads.haskell.org/~ghc/latest/docs/html/users_guide/codegens.html#llvm-code-generator-fllvm
226226- export CLANG="${buildTargetLlvmPackages.clang}/bin/${buildTargetLlvmPackages.clang.targetPrefix}clang"
227227- '' + ''
228228-229229- # otherwise haddock fails when generating the compiler docs
230230- export LANG=C.UTF-8
231231-232232- echo -n "${buildMK dontStrip}" > mk/build.mk
233233- echo ${version} > VERSION
234234- echo ${src.rev} > GIT_COMMIT_ID
235235- ./boot
236236- sed -i -e 's|-isysroot /Developer/SDKs/MacOSX10.5.sdk||' configure
237237- '' + lib.optionalString (!stdenv.isDarwin) ''
238238- export NIX_LDFLAGS+=" -rpath $out/lib/ghc-${version}"
239239- '' + lib.optionalString stdenv.isDarwin ''
240240- export NIX_LDFLAGS+=" -no_dtrace_dof"
241241-242242- # GHC tries the host xattr /usr/bin/xattr by default which fails since it expects python to be 2.7
243243- export XATTR=${lib.getBin xattr}/bin/xattr
244244- '' + lib.optionalString targetPlatform.useAndroidPrebuilt ''
245245- 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
246246- '' + lib.optionalString targetPlatform.isMusl ''
247247- echo "patching llvm-targets for musl targets..."
248248- echo "Cloning these existing '*-linux-gnu*' targets:"
249249- grep linux-gnu llvm-targets | sed 's/^/ /'
250250- echo "(go go gadget sed)"
251251- sed -i 's,\(^.*linux-\)gnu\(.*\)$,\0\n\1musl\2,' llvm-targets
252252- echo "llvm-targets now contains these '*-linux-musl*' targets:"
253253- grep linux-musl llvm-targets | sed 's/^/ /'
254254-255255- echo "And now patching to preserve '-musleabi' as done with '-gnueabi'"
256256- # (aclocal.m4 is actual source, but patch configure as well since we don't re-gen)
257257- for x in configure aclocal.m4; do
258258- substituteInPlace $x \
259259- --replace '*-android*|*-gnueabi*)' \
260260- '*-android*|*-gnueabi*|*-musleabi*)'
261261- done
262262- '';
263263-264264- # TODO(@Ericson2314): Always pass "--target" and always prefix.
265265- configurePlatforms = [ "build" "host" ]
266266- ++ lib.optional (targetPlatform != hostPlatform) "target";
267267-268268- # `--with` flags for libraries needed for RTS linker
269269- configureFlags = [
270270- "--datadir=$doc/share/doc/ghc"
271271- "--with-curses-libraries=${ncurses.out}/lib"
272272- ] ++ lib.optionals (libffi != null) [
273273- "--with-system-libffi"
274274- "--with-ffi-includes=${targetPackages.libffi.dev}/include"
275275- "--with-ffi-libraries=${targetPackages.libffi.out}/lib"
276276- ] ++ lib.optionals (targetPlatform == hostPlatform && !enableNativeBignum) [
277277- "--with-gmp-includes=${targetPackages.gmp.dev}/include"
278278- "--with-gmp-libraries=${targetPackages.gmp.out}/lib"
279279- ] ++ lib.optionals (targetPlatform == hostPlatform && hostPlatform.libc != "glibc" && !targetPlatform.isWindows) [
280280- "--with-iconv-includes=${libiconv}/include"
281281- "--with-iconv-libraries=${libiconv}/lib"
282282- ] ++ lib.optionals (targetPlatform != hostPlatform) [
283283- "--enable-bootstrap-with-devel-snapshot"
284284- ] ++ lib.optionals useLdGold [
285285- "CFLAGS=-fuse-ld=gold"
286286- "CONF_GCC_LINKER_OPTS_STAGE1=-fuse-ld=gold"
287287- "CONF_GCC_LINKER_OPTS_STAGE2=-fuse-ld=gold"
288288- ] ++ lib.optional disableLargeAddressSpace "--disable-large-address-space"
289289- ++ lib.optionals enableDwarf [
290290- "--enable-dwarf-unwind"
291291- "--with-libdw-includes=${lib.getDev elfutils}/include"
292292- "--with-libdw-libraries=${lib.getLib elfutils}/lib"
293293- ];
294294-295295- # Make sure we never relax`$PATH` and hooks support for compatibility.
296296- strictDeps = true;
297297-298298- # Don’t add -liconv to LDFLAGS automatically so that GHC will add it itself.
299299- dontAddExtraLibs = true;
300300-301301- nativeBuildInputs = [
302302- perl autoconf autoreconfHook automake m4 python3
303303- ghc bootPkgs.alex bootPkgs.happy bootPkgs.hscolour
304304- ] ++ lib.optionals (stdenv.isDarwin && stdenv.isAarch64) [
305305- autoSignDarwinBinariesHook
306306- ] ++ lib.optionals enableDocs [
307307- sphinx
308308- ];
309309-310310- # For building runtime libs
311311- depsBuildTarget = toolsForTarget;
312312-313313- buildInputs = [ perl bash ] ++ (libDeps hostPlatform);
314314-315315- depsTargetTarget = map lib.getDev (libDeps targetPlatform);
316316- depsTargetTargetPropagated = map (lib.getOutput "out") (libDeps targetPlatform);
317317-318318- # required, because otherwise all symbols from HSffi.o are stripped, and
319319- # that in turn causes GHCi to abort
320320- stripDebugFlags = [ "-S" ] ++ lib.optional (!targetPlatform.isDarwin) "--keep-file-symbols";
321321-322322- checkTarget = "test";
323323-324324- hardeningDisable =
325325- [ "format" ]
326326- # In nixpkgs, musl based builds currently enable `pie` hardening by default
327327- # (see `defaultHardeningFlags` in `make-derivation.nix`).
328328- # But GHC cannot currently produce outputs that are ready for `-pie` linking.
329329- # Thus, disable `pie` hardening, otherwise `recompile with -fPIE` errors appear.
330330- # See:
331331- # * https://github.com/NixOS/nixpkgs/issues/129247
332332- # * https://gitlab.haskell.org/ghc/ghc/-/issues/19580
333333- ++ lib.optional stdenv.targetPlatform.isMusl "pie";
334334-335335- # big-parallel allows us to build with more than 2 cores on
336336- # Hydra which already warrants a significant speedup
337337- requiredSystemFeatures = [ "big-parallel" ];
338338-339339- postInstall = ''
340340- # Install the bash completion file.
341341- install -D -m 444 utils/completion/ghc.bash $out/share/bash-completion/completions/${targetPrefix}ghc
342342- '';
343343-344344- passthru = {
345345- inherit bootPkgs targetPrefix;
346346-347347- inherit llvmPackages;
348348- inherit enableShared;
349349-350350- # This is used by the haskell builder to query
351351- # the presence of the haddock program.
352352- hasHaddock = enableHaddockProgram;
353353-354354- # Our Cabal compiler name
355355- haskellCompilerName = "ghc-${version}";
356356- };
357357-358358- meta = {
359359- homepage = "http://haskell.org/ghc";
360360- description = "The Glasgow Haskell Compiler";
361361- maintainers = with lib.maintainers; [
362362- guibou
363363- ] ++ lib.teams.haskell.members;
364364- timeout = 24 * 3600;
365365- inherit (ghc.meta) license platforms;
366366- # ghcHEAD times out on aarch64-linux on Hydra.
367367- hydraPlatforms = builtins.filter (p: p != "aarch64-linux") ghc.meta.platforms;
368368- };
369369-370370- dontStrip = (targetPlatform.useAndroidPrebuilt || targetPlatform.isWasm);
371371-372372-} // lib.optionalAttrs targetPlatform.useAndroidPrebuilt{
373373- dontPatchELF = true;
374374- noAuditTmpdir = true;
375375-})
11+import ./common-hadrian.nix {
22+ version = "9.5.20220921";
33+ rev = "2463df2fe21b5b37ecada3df8c6726c534d24590";
44+ sha256 = "1k2h4myqbs31fdzw5n4iw0qn44mp7d33kjwrr15ix4r54r8yskzs";
55+}