Skip to content

Commit f8d74d8

Browse files
committed
Get static builds working again by switching to musl.
1 parent 1f48c4f commit f8d74d8

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
2222
prevent garbling unicode characters.
2323
[#108](https://github.com/greglook/cljstyle/issues/108)
2424
[#110](https://github.com/greglook/cljstyle/issues/110)
25+
- Fix static builds by switching to musl.
2526

2627

2728
## [0.16.626] - 2024-01-06

Dockerfile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ RUN clojure -T:build fetch-deps
3030
COPY . .
3131
RUN ./bin/build graal-uberjar
3232

33-
# Build native-image
33+
# Setup musl compiler if building a static binary
3434
ARG GRAAL_STATIC="false"
35+
RUN if [ "$GRAAL_STATIC" = true ]; then ./bin/build setup-musl; fi
36+
37+
# Build native-image
3538
RUN ./bin/build native-image :graal-static $GRAAL_STATIC
3639

3740
# Install tool

bin/build

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ elif [[ $1 = hiera ]]; then
1212
shift
1313
exec clojure -X:hiera "$@"
1414

15+
elif [[ $1 = setup-musl ]]; then
16+
# This should only really run in the context of the Docker image builder for static binaries
17+
apt install -y musl-tools
18+
ZLIB_VERSION="1.2.13"
19+
curl -sLO --fail --show-error "https://zlib.net/fossils/zlib-${ZLIB_VERSION}.tar.gz"
20+
tar xf "zlib-${ZLIB_VERSION}.tar.gz"
21+
cd "zlib-${ZLIB_VERSION}"
22+
CC=musl-gcc ./configure --static --prefix=/usr/local
23+
make CC=musl-gcc
24+
make install
25+
cd ..
26+
install -Dm644 /usr/local/lib/libz.a /usr/lib/x86_64-linux-musl/libz.a
27+
1528
elif [[ $1 = native-image ]]; then
1629
shift
1730
GRAAL_ROOT="${GRAAL_ROOT:-$HOME/.local/share/graalvm}"

build.clj

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,10 @@
370370
"--verbose"])
371371
;; Static build flag
372372
(when (:graal-static opts)
373-
"--static")]
373+
["--libc=musl"
374+
;; see https://github.com/oracle/graal/issues/3398
375+
"-H:CCompilerOption=-Wl,-z,stack-size=2097152"
376+
"--static"])]
374377
result (b/process {:command-args (remove nil? (flatten args))})]
375378
(when-not (zero? (:exit result))
376379
(binding [*out* *err*]

0 commit comments

Comments
 (0)