lang/ghc94: Fix broken "make bootstrap"

Bootstrapping the compiler without "cabal-install" is something GHC devs
rarely do, and it keeps bitrotting. This time I could make it work again,
but at some point we might end up having to distribute binaries of
cabal-install for each platform.
This commit is contained in:
pho 2023-10-11 03:07:31 +00:00
parent 8f3322e12a
commit c670e21494
3 changed files with 57 additions and 5 deletions

View file

@ -1,4 +1,4 @@
# $NetBSD: bootstrap.mk,v 1.6 2023/06/06 12:41:44 riastradh Exp $
# $NetBSD: bootstrap.mk,v 1.7 2023/10/11 03:07:31 pho Exp $
# -----------------------------------------------------------------------------
# Select a bindist of bootstrapping compiler on a per-platform basis. See
# ./files/BOOTSTRAP.md for details.
@ -290,6 +290,26 @@ ${WRKDIR}/stamp-build-boot: ${WRKDIR}/stamp-configure-boot
@${PHASE_MSG} "Building Hadrian for ${BOOT_GHC_VERSION}"
${CP} -f ${FILESDIR}/UserSettings.hs ${WRKSRC}/hadrian/
# ${HADRIAN_BOOT_SOURCE} often contains libraries older than what we have
# in pkgsrc. When that happens bootstrap.py tries to build Hadrian with
# pkgsrc-installed libraries and fails because they aren't buildlinked. So
# we must temporarily disable wrappers while building it.
saved_IFS="$$IFS"; \
IFS=":"; \
set -- $$PATH; \
IFS="$$saved_IFS"; \
pruned_path=; \
while ${TEST} "$$#" -gt 0; do \
if ${TEST} "$$1" != "${WRAPPER_BINDIR}"; then \
if ${TEST} "$$pruned_path" = ""; then \
pruned_path="$$1"; \
else \
pruned_path="$$pruned_path:$$1"; \
fi; \
fi; \
shift; \
done; \
PATH="$$pruned_path"; \
cd ${WRKSRC}/hadrian/bootstrap && \
python bootstrap.py -s ${DISTDIR}/${DIST_SUBDIR}/${HADRIAN_BOOT_SOURCE}

View file

@ -1,4 +1,4 @@
<!-- $NetBSD: BOOTSTRAP.md,v 1.1 2023/01/21 04:49:25 pho Exp $ -->
<!-- $NetBSD: BOOTSTRAP.md,v 1.2 2023/10/11 03:07:31 pho Exp $ -->
# We need GHC to build GHC
@ -60,11 +60,14 @@ skip this step. If not, install `misc/cabal-install` and do:
```
% cd ${WRKSRC}/hadrian
% cabal configure
% ../../../files/extract-vanilla-package-db ./packages.conf
(The next command fails with an error but you can safely ignore it.)
% cabal build --package-db=clear --package-db=./packages.conf --only-configure
% cp dist-newstyle/cache/plan.json bootstrap/plan-${BOOT_VERSION}.json
% cd ./bootstrap
% cabal build --allow-newer
% cp ../dist-newstyle/cache/plan.json plan-${BOOT_VERSION}.json
% cabal run -v0 -- plan-${BOOT_VERSION}.json | \
% cabal run -v0 --allow-newer hadrian-bootstrap-gen \
-- plan-${BOOT_VERSION}.json | \
tee plan-bootstrap-${BOOT_VERSION}.json
```

View file

@ -0,0 +1,29 @@
#!/bin/sh
set -eu
# This script extracts the package DB originally came from GHC you are
# using. Only needed when you create a hadrian bootstrap archive.
if [ "$#" -lt 1 ]; then
echo >&2 "Usage: $0 PKG_DB_DIR"
exit
fi
PKG_DB_DIR="$1"
mkdir -p "$PKG_DB_DIR"
pkg_info -qL ghc | {
conf_dir_path=
while read path; do
conf_dir_removed="${path#*/package.conf.d/}"
if [ "$conf_dir_removed" != "$path" ]; then
echo "Copying ${path}..."
if [ "$conf_dir_path" = "" ]; then
conf_dir_path="${path%/${conf_dir_removed}}"
fi
sed -e "s|\\\${pkgroot}|${conf_dir_path}/..|g" \
< "${path}" \
> "${PKG_DB_DIR}/${conf_dir_removed}"
fi
done
}
ghc-pkg --package-db="$PKG_DB_DIR" recache