62.6. ghc-9.12.4
The Glasgow Haskell Compiler, its libraries and GHCi
| Version | 9.12.4, release 1 |
| Shelf | lang — Language implementations, plus the modules of any language that has no module shelf of its own |
| Phase | 31_compilers (Compilers), 20 of 22 in build order |
| Licence | BSD-3-Clause |
| Homepage | https://www.haskell.org/ghc/ |
| Build time | 44.9 SBU |
| Installed size | 952.9 MiB in 4755 files |
| Recipe | ports/core/lang/ghc/kpkgbuild |
About
This port is the Glasgow Haskell Compiler, GHC, with GHCi, its boot libraries and the tools it ships (ghc-pkg, haddock, hsc2hs, hpc, runghc). The ports built with it are cabal-install and the two Haskell programs built with both: pandoc, which renders this book and which openjdk and ripgrep-all depend on, and shellcheck.
GHC is written in Haskell, so the build starts from a bootstrap seed: upstream’s statically linked GHC for Alpine, the second source = line. The seed is installed into a scratch prefix under $SRC_ROOT/seed, compiles Hadrian (GHC’s build system) and GHC’s first stage, and is then left behind; the first stage compiles the second, which is what ships. Hadrian’s own Hackage dependencies come from the vendor bundle, the third sha256 = line, so nothing is downloaded during the build (see The Haskell bundle).
Hadrian does not install. Its binary-dist-dir target lays out a binary distribution under _build/bindist, and that distribution’s own configure and make install put it into $PKG, which is how upstream’s release tarballs are installed too.
Sources
ghc-9.12.4.tar.xz(32.1 MiB)
sha25602d1ee5080acf00e135b93b238f09015b06ff27254cde59669cf57c42c2bee43
upstream: https://downloads.haskell.org/~ghc/9.12.4/ghc-9.12.4-src.tar.xz
archive copy: sources-3/lang--ghc-9.12.4.tar.xzghc-9.10.3-x86_64-alpine3_12-linux-static.tar.xz(239.1 MiB)
sha2569928e01d2f49b7b75b2a4f1c37cf5de31cdcf68cd063cc3b3a010aa4d99f3962
upstream: https://downloads.haskell.org/~ghc/9.10.3/ghc-9.10.3-x86_64-alpine3_12-linux-static.tar.xz
archive copy: sources-3/lang--ghc-9.10.3-x86_64-alpine3_12-linux-static.tar.xzghc-vendor-9.12.4.tar.xz(2.4 MiB)
sha2561108bc8401e74b49f71d7dd237c8b1fbfdd5d55cbcdd11ec9a9e6a6eb87d9d1f
a vendor bundle, made byports/hackage-vendor, not an upstream file
archive copy: sources-3/lang--ghc-vendor-9.12.4.tar.xz
Dependencies
Depends on: gcc, gmp, libffi, ncurses, python3, python3-sphinx, autoconf, automake.
Required by (3): cabal-install, pandoc, shellcheck.
Optional, off in KDOS
These switches in build.sh turn off a feature whose library is a port here. The recipe may turn each off on purpose, or because the library was not yet a port when the recipe was written; this list cannot tell which.
--disable-numa, line 41: numactl (explained with the switches below)
Installation
From the repository root, inside the build container, this is the line kdosbuild runs for the port:
script/chroot/exec.sh bash -c 'source script/phases/31_compilers/phase.env && kpkg install ghc'
What kpkg does
kpkg runs these steps, in this order, as root inside the chroot. The port directory is /ports/core/lang/ghc.
1. Verify every declared source. Each file a sha256 = line names, found in the port directory or in /var/cache/kpkg/sources, must hash to its line; a mismatch stops the build before anything is unpacked.
cd /ports/core/lang/ghc
echo '02d1ee5080acf00e135b93b238f09015b06ff27254cde59669cf57c42c2bee43 ghc-9.12.4.tar.xz' | sha256sum -c -
echo '9928e01d2f49b7b75b2a4f1c37cf5de31cdcf68cd063cc3b3a010aa4d99f3962 ghc-9.10.3-x86_64-alpine3_12-linux-static.tar.xz' | sha256sum -c -
echo '1108bc8401e74b49f71d7dd237c8b1fbfdd5d55cbcdd11ec9a9e6a6eb87d9d1f ghc-vendor-9.12.4.tar.xz' | sha256sum -c -
2. Unpack. The work directory is emptied and the first source is unpacked into $SRC with its top directory stripped; any later tarball lands unstripped beside it in $SRC_ROOT, and a file that is not a tarball is copied into $SRC.
SRC_ROOT=/var/cache/kpkg/work/ghc
SRC=$SRC_ROOT/ghc-9.12.4
PKG=$SRC_ROOT/pkg
rm -rf "$SRC_ROOT"
mkdir -p "$SRC" "$PKG"
tar --no-same-permissions --warning=no-unknown-keyword -xf ghc-9.12.4.tar.xz -C "$SRC" --strip-components=1
tar --no-same-permissions --warning=no-unknown-keyword -xf ghc-9.10.3-x86_64-alpine3_12-linux-static.tar.xz -C "$SRC_ROOT"
Every config.guess and config.sub older than automake’s is then replaced with automake’s, so a configure script recognises the musl target.
3. Build. build.sh is sourced in a subshell under set -e, from $SRC, with name, version, release and the recipe’s helpers _seed, _seedarch, hsplan, vendordir and the five paths PKGNAME, PORT_SRC, SRC_ROOT, SRC and PKG set as shell variables. Its body, verbatim:
_seedghc="$SRC_ROOT/seed/bin/ghc"
(
cd "$SRC_ROOT/ghc-$_seed-x86_64-unknown-linux"
./configure --prefix="$SRC_ROOT/seed"
make install
)
tar xf "$PORT_SRC/$name-vendor-$version.tar.xz" -C "$SRC_ROOT"
mkdir -p hadrian/bootstrap/_build/tarballs
for f in "$SRC_ROOT"/vendor/*.tar.gz; do
cp "$f" hadrian/bootstrap/_build/tarballs/
done
for f in "$SRC_ROOT"/vendor/*.cabal; do
b=${f##*/}
cp "$f" "hadrian/bootstrap/_build/tarballs/${b%-*}.cabal"
done
(
cd hadrian/bootstrap
python3 bootstrap.py -w "$_seedghc" -d "$hsplan" --no-archive
)
_hadrian="$SRC/hadrian/bootstrap/_build/bin/hadrian"
./configure \
--prefix=/usr \
--build=x86_64-unknown-linux \
--host=x86_64-unknown-linux \
--target=x86_64-unknown-linux \
--with-system-libffi \
--disable-ld-override \
--disable-numa \
CONF_GCC_LINKER_OPTS_STAGE2="-Wl,-z,now" \
GHC="$_seedghc"
"$_hadrian" -j"$KDOS_JOBS" \
--flavour=release+no_profiled_libs \
--docs=no-haddocks \
--docs=no-sphinx-pdfs \
--docs=no-sphinx-html \
binary-dist-dir
cd _build/bindist/ghc-$version-x86_64-unknown-linux
./configure --prefix=/usr --with-system-libffi --disable-ld-override \
CONF_GCC_LINKER_OPTS_STAGE2="-Wl,-z,now"
make install DESTDIR="$PKG"
rmdir "$PKG/usr/share/doc/ghc-$version"
The switches, and why each is set:
--prefix="$SRC_ROOT/seed"— Installs the seed into a directory under the work tree, never into the system; nothing under it reaches$PKG.-w— Tells Hadrian’sbootstrap.pywhich GHC to compile Hadrian with: the seed.-d— The bootstrap planbootstrap.pyfollows,hadrian/bootstrap/plan-bootstrap-<seed>.jsonfrom the GHC source, where<seed>is the recipe’s_seedwith its dots turned to underscores; thehsplanhelper spells the name. The plan names every package Hadrian needs, with its version and hashes, solved for the seed’s version of GHC.--no-archive— Builds Hadrian in place without packing it into a distribution archive; the build runs it straight fromhadrian/bootstrap/_build/bin.--build=x86_64-unknown-linux— The platform triple GHC is configured for, given for build, host and target alike (also--hostand--target). It is the triple in the binary distribution’s directory name,_build/bindist/ghc-<version>-x86_64-unknown-linux, which thecdfurther down spells out, so the two change together.--with-system-libffi— Builds the runtime system against the libffi port instead of the copy in GHC’s source. The choice is made when the runtime is compiled; the binary distribution’sconfigurehas no libffi switch, and autoconf passes the repeated option over with a warning about an unrecognised option.--disable-ld-override— Keeps gcc’s default linker, binutils’ld, the linker the rest of the tree links with. With the override on, GHC’sconfiguretriesld.lld, thenld.gold, thenld, and tells gcc to use the first that works; lld is installed earlier in this phase, so GHC would link everything with lld. Bothconfigureruns carry it, because the binary distribution’s makes the same search and records the result in the installedsettings.--disable-numa— Builds the runtime system without libnuma. The default,auto, links numactl’slibnumawhenever it is installed, and numactl is a port of41_system, so a rebuild on a tree past that phase would makeghcneed a library its recipe does not declare, which theundeclaredgate in70_imagefails.CONF_GCC_LINKER_OPTS_STAGE2="-Wl,-z,now"— The link flags of the target toolchain. The first configure writes them into Hadrian’sdefault.target, which the first-stage compiler links with, so the second-stageghcthat ships and its libraries bind every symbol at load time like the rest of the tree. They are also recorded in the installed compiler’ssettingsfile as the C compiler link flags, so every Haskell program GHC builds,pandocandshellcheckamong them, is linked with-z,now. It is passed to bothconfigureruns, because the binary distribution’sconfigurewrites thesettingsfile that is installed. GHC links its programs without PIE; why, and what that leaves out, is in The release flags.GHC="$_seedghc"— The compiler GHC’sconfigurebuilds the first stage with: the seed.--flavour=release+no_profiled_libs—releaseis Hadrian’s flavour for a distributed compiler:perf, which compiles the compiler and the libraries with-O2and splits sections so a static link can drop unused code, with Haddock documentation (turned off by the next switch) and late cost centres for profiling added.no_profiled_libsbuilds no profiling variant of any library, so a program on this system cannot be compiled for profiling: the boot libraries have no profiled objects forcabal --enable-profilingto link against.--docs=no-haddocks— Builds no Haddock HTML for the libraries, so the system carries no local API reference for GHC’s boot libraries, and no locally built Haddock page links into them.--docs=no-sphinx-pdfs— Builds no PDF of the User’s Guide.--docs=no-sphinx-html— Builds no HTML User’s Guide. Of GHC’s documentation, only the manual pageghc(1)is built and installed, which is why python3-sphinx is independs.
The common switches of each build system are explained in the Flag glossary.
4. Package. kpkg removes libtool archives, the info directory index, mimeinfo.cache and every fonts.dir from $PKG, copies the source’s licence files into /usr/share/licenses/ghc, prunes what the image does not ship, lints the tree and rolls it reproducibly:
tar --sort=name --format=gnu --numeric-owner --owner=0 --group=0 \
--mtime=@$SOURCE_DATE_EPOCH \
--use-compress-program='xz -9 -T0 --block-size=32MiB --no-adjust' \
-cf ghc-9.12.4-1.tar.xz -C "$PKG" .
5. Adopt. kpkgadd installs the package’s files over the root, refusing a path another package owns, records the file list in /var/lib/kpkg/db/ghc, and runs the triggers its paths call for.
Contents
Installed programs: ghc, ghc-9.12.4, ghc-pkg, ghc-pkg-9.12.4, ghci, ghci-9.12.4, haddock, haddock-ghc-9.12.4, hp2ps, hp2ps-ghc-9.12.4, hpc, hpc-ghc-9.12.4, hsc2hs, hsc2hs-ghc-9.12.4, runghc, runghc-9.12.4, runhaskell, runhaskell-9.12.4.
Installed directories: /usr/lib/ghc-9.12.4, /usr/share/doc/x86_64-linux-ghc-9.12.4-inplace, /usr/share/licenses/ghc, /usr/share/x86_64-linux-ghc-9.12.4-inplace.
Short descriptions
ghc |
the Glasgow Haskell Compiler |
Notes
rmdir, not rm -r, removes /usr/share/doc/ghc-<version>, the directory the binary distribution creates for the documentation that is not built. It fails, and fails the build, if anything was installed into it, so a change that brings documentation back shows up here.
The plan named by hsplan is solved for the seed’s GHC version: bootstrap.py takes each package the plan marks as coming with GHC from the seed’s own package database, at exactly the version the plan names, and stops when the seed has another. A new seed therefore needs a plan for it in the GHC source, and the vendor bundle is generated again from that plan by ports/fetch.
The seed’s archive unpacks as ghc-<seed>-x86_64-unknown-linux, not under the name of the file it came in, and its configure and make install run inside that directory.