Skip to content

Commit bf254e8

Browse files
committed
Small updates
1 parent 2e9ea5a commit bf254e8

4 files changed

Lines changed: 179 additions & 11 deletions

File tree

Makefile

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
################################################################################
2+
# https://www.gnu.org/software/make/manual/html_node/Special-Variables.html
3+
# https://ftp.gnu.org/old-gnu/Manuals/make-3.80/html_node/make_17.html
4+
ALPINE_HASKELL_MKFILE_PATH := $(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST))
5+
ALPINE_HASKELL_ROOT_DIR := $(shell cd $(shell dirname $(ALPINE_HASKELL_MKFILE_PATH)); pwd)
6+
7+
# Common aliases lifted from other Makefiles
8+
package = alpine-haskell
9+
main_exe = demo
10+
11+
# Use GHC options informed by this blog post:
12+
# https://rybczak.net/2016/03/26/how-to-reduce-compilation-times-of-haskell-projects/
13+
ghc_opts = -j +RTS -A128m -RTS
14+
stack_yaml = STACK_YAML="stack.yaml"
15+
stack = $(stack_yaml) stack
16+
17+
# Stack commands that will be executed in the Docker container
18+
stack_docker = $(stack) --docker
19+
20+
# GHC version to build
21+
TARGET_GHC_VERSION ?= 8.6.5
22+
23+
################################################################################
24+
# Standard build (runs in the Docker container)
25+
.PHONY: build
26+
build:
27+
$(stack_docker) build $(package) \
28+
--ghc-options='$(ghc_opts)'
29+
30+
# Static build (runs in the Docker container)
31+
.PHONY: build-static
32+
build-static:
33+
$(stack_docker) build $(package) --flag $(package):static \
34+
--ghc-options='$(ghc_opts)'
35+
36+
# Fast build (-O0) (runs in the Docker container)
37+
.PHONY: build-fast
38+
build-fast:
39+
$(stack_docker) build $(package) \
40+
--ghc-options='$(ghc_opts)' \
41+
--fast
42+
43+
# Clean up all build artifacts
44+
clean:
45+
$(stack_docker) clean
46+
47+
# Run ghcid (runs in the Docker container)
48+
ghcid:
49+
$(stack) exec -- ghcid \
50+
--command "$(stack_docker) ghci \
51+
--ghci-options='-fobject-code $(ghc_opts)' \
52+
--main-is $(package):$(main_exe)"
53+
54+
################################################################################
55+
# Convenience targets for building GHC locally
56+
#
57+
# The intermediate layers of the multi-stage Docker build file are cached so
58+
# that changes to the Dockerfile don't force us to rebuild GHC when developing
59+
60+
# Build GHC with support for 'integer-gmp' and 'libgmp'
61+
.PHONY: docker-build-gmp
62+
docker-build-gmp: docker-base-gmp docker-ghc-gmp docker-tooling-gmp docker-image-gmp
63+
64+
.PHONY: docker-base-gmp
65+
docker-base-gmp:
66+
docker build \
67+
--build-arg GHC_BUILD_TYPE=gmp \
68+
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
69+
--target base \
70+
--tag alpine-haskell-gmp:base \
71+
--cache-from alpine-haskell-gmp:base \
72+
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
73+
$(ALPINE_HASKELL_ROOT_DIR)
74+
75+
.PHONY: docker-ghc-gmp
76+
docker-ghc-gmp:
77+
docker build \
78+
--build-arg GHC_BUILD_TYPE=gmp \
79+
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
80+
--target build-ghc \
81+
--tag alpine-haskell-gmp:build-ghc-$(TARGET_GHC_VERSION) \
82+
--cache-from alpine-haskell-gmp:build-ghc-$(TARGET_GHC_VERSION) \
83+
--cache-from alpine-haskell-gmp:base \
84+
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
85+
$(ALPINE_HASKELL_ROOT_DIR)
86+
87+
.PHONY: docker-tooling-gmp
88+
docker-tooling-gmp:
89+
docker build \
90+
--build-arg GHC_BUILD_TYPE=gmp \
91+
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
92+
--target build-tooling \
93+
--tag alpine-haskell-gmp:build-tooling \
94+
--cache-from alpine-haskell-gmp:build-tooling\
95+
--cache-from alpine-haskell-gmp:build-ghc-$(TARGET_GHC_VERSION) \
96+
--cache-from alpine-haskell-gmp:base \
97+
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
98+
$(ALPINE_HASKELL_ROOT_DIR)
99+
100+
.PHONY: docker-image-gmp
101+
docker-image-gmp:
102+
docker build \
103+
--build-arg GHC_BUILD_TYPE=gmp \
104+
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
105+
--tag alpine-haskell-gmp:$(TARGET_GHC_VERSION) \
106+
--cache-from alpine-haskell-gmp:$(TARGET_GHC_VERSION) \
107+
--cache-from alpine-haskell-gmp:build-tooling \
108+
--cache-from alpine-haskell-gmp:build-ghc-$(TARGET_GHC_VERSION) \
109+
--cache-from alpine-haskell-gmp:base \
110+
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
111+
$(ALPINE_HASKELL_ROOT_DIR)
112+
113+
# Build GHC with support for 'integer-simple'
114+
.PHONY: docker-build-simple
115+
docker-build-simple: docker-base-simple docker-ghc-simple docker-tooling-simple docker-image-simple
116+
117+
.PHONY: docker-base-simple
118+
docker-base-simple:
119+
docker build \
120+
--build-arg GHC_BUILD_TYPE=simple \
121+
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
122+
--target base \
123+
--tag alpine-haskell-simple:base \
124+
--cache-from alpine-haskell-simple:base \
125+
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
126+
$(ALPINE_HASKELL_ROOT_DIR)
127+
128+
.PHONY: docker-ghc-simple
129+
docker-ghc-simple:
130+
docker build \
131+
--build-arg GHC_BUILD_TYPE=simple \
132+
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
133+
--target build-ghc \
134+
--tag alpine-haskell-simple:build-ghc-$(TARGET_GHC_VERSION) \
135+
--cache-from alpine-haskell-simple:build-ghc-$(TARGET_GHC_VERSION) \
136+
--cache-from alpine-haskell-simple:base \
137+
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
138+
$(ALPINE_HASKELL_ROOT_DIR)
139+
140+
.PHONY: docker-tooling-simple
141+
docker-tooling-simple:
142+
docker build \
143+
--build-arg GHC_BUILD_TYPE=simple \
144+
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
145+
--target build-tooling \
146+
--tag alpine-haskell-simple:build-tooling \
147+
--cache-from alpine-haskell-simple:build-tooling\
148+
--cache-from alpine-haskell-simple:build-ghc-$(TARGET_GHC_VERSION) \
149+
--cache-from alpine-haskell-simple:base \
150+
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
151+
$(ALPINE_HASKELL_ROOT_DIR)
152+
153+
.PHONY: docker-image-simple
154+
docker-image-simple:
155+
docker build \
156+
--build-arg GHC_BUILD_TYPE=simple \
157+
--build-arg GHC_VERSION=$(TARGET_GHC_VERSION) \
158+
--tag alpine-haskell-simple:$(TARGET_GHC_VERSION) \
159+
--cache-from alpine-haskell-simple:$(TARGET_GHC_VERSION) \
160+
--cache-from alpine-haskell-simple:build-tooling \
161+
--cache-from alpine-haskell-simple:build-ghc-$(TARGET_GHC_VERSION) \
162+
--cache-from alpine-haskell-simple:base \
163+
--file $(ALPINE_HASKELL_ROOT_DIR)/Dockerfile \
164+
$(ALPINE_HASKELL_ROOT_DIR)

ghc/builder.sh

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ usage="USAGE: $0
3232
default: ${alpine_ver}
3333
-c CONTAINER override the default container name
3434
default: ${container}
35-
-g GHC_VER override the numeric library GHC is built against; either 'gmp' or 'simple'
35+
-g GHC_VER override the version of GHC to be compiled
3636
default: ${ghc_version}
3737
-i IMAGE override the default image base name
3838
default: ${image}
39-
-n NUMERIC override the numeric library GHC is built against; either 'gmp' or 'simple'
39+
-n NUMERIC override the numeric library GHC is built against; either 'gmp' or 'native'
4040
default: ${numeric}"
4141

4242
while getopts "a:c:g:i:n:h" opt; do
@@ -54,11 +54,11 @@ while getopts "a:c:g:i:n:h" opt; do
5454
image="${OPTARG}"
5555
};;
5656
n ) {
57-
if [ "${OPTARG}" = "gmp" ] || [ "${OPTARG}" = "simple" ]; then
57+
if [ "${OPTARG}" = "gmp" ] || [ "${OPTARG}" = "native" ]; then
5858
numeric="${OPTARG}"
5959
else
6060
echo "Invalid NUMERIC argument (i.e. '-n')." >&2
61-
echo "Expected either 'gmp' or 'simple', got '${OPTARG}'" >&2
61+
echo "Expected either 'gmp' or 'native', got '${OPTARG}'" >&2
6262
exit 1
6363
fi;
6464
};;
@@ -128,14 +128,16 @@ if [ "${numeric}" = "gmp" ]; then
128128
buildah copy --chmod 444 "${container}" \
129129
./ghc/build-gmp.mk \
130130
/tmp/build.mk
131-
elif [ "${numeric}" = "simple" ]; then
131+
elif [ "${numeric}" = "native" ]; then
132+
# TODO: Add a check for GHC version > 9.x; in that case we need to use a
133+
# `ghc-bignum` flag w/ `native` instead of the old flag for `simple`.
132134
buildah copy --chmod 444 "${container}" \
133135
./ghc/build-simple.mk \
134136
/tmp/build.mk
135137
else # Should be impossible...
136138
echo "This code path should be unreachable!" >&2
137139
echo "Invalid NUMERIC argument (i.e. '-n')" >&2
138-
echo "Expected either 'gmp' or 'simple', got '${numeric}'" >&2
140+
echo "Expected either 'gmp' or 'native', got '${numeric}'" >&2
139141
exit 1
140142
fi;
141143

policy.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
"transports": {
44
"docker": {
55
"docker.io/library/alpine": [{"type": "insecureAcceptAnything"}],
6-
"ghcr.io/jkachmar/ghcup": [{"type": "insecureAcceptAnything"}]
6+
"ghcr.io/jkachmar/ghcup": [{"type": "insecureAcceptAnything"}],
7+
"ghcr.io/jkachmar/ghc-gmp": [{"type": "insecureAcceptAnything"}],
8+
"ghcr.io/jkachmar/ghc-native": [{"type": "insecureAcceptAnything"}]
79
},
810
"dir": {
911
"": [{"type": "insecureAcceptAnything"}]

tooling/builder.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,11 @@ usage="USAGE: $0
3939
default: ${alpine_ver}
4040
-c CONTAINER override the default container name
4141
default: ${container}
42-
-g GHC_VER override the numeric library GHC is built against; either 'gmp' or 'simple'
42+
-g GHC_VER override the version of GHC to be compiled
4343
default: ${ghc_version}
4444
-i IMAGE override the default image base name
4545
default: ${image}
46-
-n NUMERIC override the numeric library GHC is built against; either 'gmp' or 'simple'
46+
-n NUMERIC override the numeric library GHC is built against; either 'gmp' or 'native'
4747
default: ${numeric}
4848
-C CABAL_VER override the default version of 'cabal-install' to build
4949
default: ${cabal_version}
@@ -67,11 +67,11 @@ while getopts "a:c:g:i:n:C:S:H:h" opt; do
6767
image="${OPTARG}"
6868
};;
6969
n ) {
70-
if [ "${OPTARG}" = "gmp" ] || [ "${OPTARG}" = "simple" ]; then
70+
if [ "${OPTARG}" = "gmp" ] || [ "${OPTARG}" = "native" ]; then
7171
numeric="${OPTARG}"
7272
else
7373
echo "Invalid NUMERIC argument (i.e. '-n')." >&2
74-
echo "Expected either 'gmp' or 'simple', got '${OPTARG}'" >&2
74+
echo "Expected either 'gmp' or 'native', got '${OPTARG}'" >&2
7575
exit 1
7676
fi;
7777
};;

0 commit comments

Comments
 (0)