@@ -17,26 +17,32 @@ cd "$( git rev-parse --show-toplevel )"
1717# cf. https://sookocheff.com/post/bash/parsing-bash-script-arguments-with-shopts/
1818# ###############################################################################
1919
20- container=" builder-ghc"
21- image=" builder-ghc"
20+ alpine_ver=" 3.14"
21+ container=" ghc"
22+ image=" ghc"
2223ghc_ver=" 8.10.7"
2324# NOTE: The logic associated with this will have to change for GHC 9.x and up to
2425# support the changes introduced with the switch to `ghc-bignum`.
2526numeric=" gmp"
2627
2728usage=" USAGE: $0
28- -h show this help text
29- -c CONTAINER override the default container name
30- default: ${container}
31- -g GHC_VER override the numeric library GHC is built against; either 'gmp' or 'simple'
32- default: ${ghc_ver}
33- -i IMAGE override the default image name
34- default: ${image}
35- -n NUMERIC override the numeric library GHC is built against; either 'gmp' or 'simple'
36- default: ${numeric} "
37-
38- while getopts " c:g:i:n:h" opt; do
29+ -h show this help text
30+ -a ALPINE_VER override the default Alpine version
31+ default: ${alpine_ver}
32+ -c CONTAINER override the default container name
33+ default: ${container}
34+ -g GHC_VER override the numeric library GHC is built against; either 'gmp' or 'simple'
35+ default: ${ghc_ver}
36+ -i IMAGE override the default image name
37+ default: ${image}
38+ -n NUMERIC override the numeric library GHC is built against; either 'gmp' or 'simple'
39+ default: ${numeric} "
40+
41+ while getopts " a:c:g:i:n:h" opt; do
3942 case ${opt} in
43+ a ) {
44+ alpine_ver=" ${OPTARG} "
45+ };;
4046 c ) {
4147 container=" ${OPTARG} "
4248 };;
@@ -76,7 +82,7 @@ container="${container}-${numeric}-${ghc_ver}"
7682image=" ${image} -${numeric} :${ghc_ver} "
7783
7884# ###############################################################################
79- # Container and dependencies .
85+ # Container.
8086# ###############################################################################
8187
8288# Create the container that will be used to compile GHC from source.
@@ -89,35 +95,49 @@ image="${image}-${numeric}:${ghc_ver}"
8995buildah \
9096 --signature-policy=./policy.json \
9197 --name " ${container} " \
92- from --pull " base-${numeric} " \
93- || true
98+ from --pull " docker.io/library/alpine:${alpine_ver} "
99+
100+ # ###############################################################################
101+ # Copy `ghcup` from another container.
102+ # ###############################################################################
103+
104+ # XXX: Maybe the `"ghcup"` image name should be fully qualified (i.e.
105+ # "localhost/ghcup" for an image built locally)...?
106+ buildah unshare ./ghc/copy_ghcup.sh " ghcup" " ${container} "
107+
108+ # ###############################################################################
109+ # Dependencies.
110+ # ###############################################################################
94111
95112buildah run " ${container} " \
96113 apk add --no-cache \
97114 autoconf \
98115 automake \
99116 binutils-gold \
100117 build-base \
118+ curl \
101119 coreutils \
102120 cpio \
103121 ghc \
122+ git \
104123 linux-headers \
105124 libffi-dev \
106125 musl-dev \
107126 ncurses-dev \
108127 perl \
109128 python3 \
110129 py3-sphinx \
111- zlib-dev
130+ zlib-dev \
131+ xz
112132
113133# Copy the appropriate build file, depending on the chosen numeric library.
114134if [ " ${numeric} " = " gmp" ]; then
115135 buildah copy --chmod 444 " ${container} " \
116- ./1_ghc /build-gmp.mk \
136+ ./ghc /build-gmp.mk \
117137 /tmp/build.mk
118138elif [ " ${numeric} " = " simple" ]; then
119139 buildah copy --chmod 444 " ${container} " \
120- ./1_ghc /build-simple.mk \
140+ ./ghc /build-simple.mk \
121141 /tmp/build.mk
122142else # Should be impossible...
123143 echo " This code path should be unreachable!" >&2
@@ -128,12 +148,12 @@ fi;
128148
129149# Copy all patches that will be applied to the GHC source tree.
130150buildah copy --chmod 444 " ${container} " \
131- ./1_ghc /patches \
151+ ./ghc /patches \
132152 /tmp/patches
133153
134154# Copy wrapper script that will invoke `ghcup` to compile GHC.
135155buildah copy --chmod 111 " ${container} " \
136- ./1_ghc /compile_ghc.sh \
156+ ./ghc /compile_ghc.sh \
137157 /tmp/compile_ghc.sh
138158
139159# ###############################################################################
@@ -156,16 +176,6 @@ buildah run "${container}" \
156176# Generate the final image.
157177# ###############################################################################
158178
159- # NOTE: Using images for all of these intermediate stages is sort of a
160- # carry-over from multi-stage Docker builds.
161- #
162- # It might be preferable to keep this container around for future build steps
163- # and just mount it to copy the files over manually.
164- #
165- # The tradeoff with this is that the image building process stops being
166- # "declarative", since it depends on the intermediate state of a particular
167- # container on the host builder's system.
168-
169179buildah \
170180 --signature-policy=./policy.json \
171- commit " ${container} " " ${image} "
181+ commit --rm " ${container} " " ${image} "
0 commit comments