1
1
# syntax=docker/dockerfile:1
2
2
FROM ubuntu:noble
3
3
LABEL maintainer="Eirik Albrigtsen <sszynrae@gmail.com>"
4
+ LABEL org.opencontainers.image.create="$(date --utc --iso-8601=seconds)"
5
+ LABEL org.opencontainers.image.documentation="https://github.com/clux/muslrust"
6
+ LABEL org.opencontainers.image.licenses="MIT"
7
+ LABEL org.opencontainers.image.url="https://github.com/clux/muslrust"
8
+ LABEL org.opencontainers.image.description="Docker environment for building musl based static rust binaries"
4
9
5
10
# Required packages:
6
11
# - musl-dev, musl-tools - the musl toolchain
@@ -30,17 +35,19 @@ RUN apt-get update && apt-get install -y \
30
35
--no-install-recommends && \
31
36
rm -rf /var/lib/apt/lists/*
32
37
38
+ # Common arg for arch used in urls and triples
39
+ ARG AARCH
33
40
# Install rust using rustup
34
41
ARG CHANNEL
35
42
ENV RUSTUP_VER="1.27.1" \
36
- RUST_ARCH="aarch64 -unknown-linux-gnu" \
43
+ RUST_ARCH="${AARCH} -unknown-linux-gnu" \
37
44
CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
38
45
39
46
RUN curl "https://static.rust-lang.org/rustup/archive/${RUSTUP_VER}/${RUST_ARCH}/rustup-init" -o rustup-init && \
40
47
chmod +x rustup-init && \
41
48
./rustup-init -y --default-toolchain ${CHANNEL} --profile minimal --no-modify-path && \
42
49
rm rustup-init && \
43
- ~/.cargo/bin/rustup target add aarch64 -unknown-linux-musl
50
+ ~/.cargo/bin/rustup target add ${AARCH} -unknown-linux-musl
44
51
45
52
# Allow non-root access to cargo
46
53
RUN chmod a+X /root
@@ -49,7 +56,7 @@ RUN chmod a+X /root
49
56
# This helps continuing manually if anything breaks.
50
57
ENV ZLIB_VER="1.3.1" \
51
58
SQLITE_VER="3490100" \
52
- PROTOBUF_VER="29.2 " \
59
+ PROTOBUF_VER="31.0 " \
53
60
SCCACHE_VER="0.9.1" \
54
61
CC=musl-gcc \
55
62
PREFIX=/musl \
@@ -59,18 +66,18 @@ ENV ZLIB_VER="1.3.1" \
59
66
60
67
# Install a more recent release of protoc (protobuf-compiler in jammy is 4 years old and misses some features)
61
68
RUN cd /tmp && \
62
- curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VER}/protoc-${PROTOBUF_VER}-linux-aarch_64.zip -o protoc.zip && \
69
+ curl -sSL https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOBUF_VER}/protoc-${PROTOBUF_VER}-linux-$([ "$AARCH" = "aarch64" ] && echo " aarch_64" || echo "$AARCH" ) .zip -o protoc.zip && \
63
70
unzip protoc.zip && \
64
71
cp bin/protoc /usr/bin/protoc && \
65
72
rm -rf *
66
73
67
74
# Install prebuilt sccache based on platform
68
- RUN curl -sSL https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VER}/sccache-v${SCCACHE_VER}-aarch64 -unknown-linux-musl.tar.gz | tar xz && \
75
+ RUN curl -sSL https://github.com/mozilla/sccache/releases/download/v${SCCACHE_VER}/sccache-v${SCCACHE_VER}-${AARCH} -unknown-linux-musl.tar.gz | tar xz && \
69
76
mv sccache-v${SCCACHE_VER}-*-unknown-linux-musl/sccache /usr/local/bin/ && \
70
77
chmod +x /usr/local/bin/sccache && \
71
78
rm -rf sccache-v${SCCACHE_VER}-*-unknown-linux-musl
72
79
73
- # Build zlib (used in pq)
80
+ # Build zlib
74
81
RUN curl -sSL https://zlib.net/zlib-$ZLIB_VER.tar.gz | tar xz && \
75
82
cd zlib-$ZLIB_VER && \
76
83
CC="musl-gcc -fPIC -pie" LDFLAGS="-L$PREFIX/lib" CFLAGS="-I$PREFIX/include" ./configure --static --prefix=$PREFIX && \
@@ -88,13 +95,16 @@ RUN curl -sSL https://www.sqlite.org/2025/sqlite-autoconf-$SQLITE_VER.tar.gz | t
88
95
89
96
ENV PATH=/root/.cargo/bin:$PREFIX/bin:$PATH \
90
97
RUSTUP_HOME=/root/.rustup \
91
- CARGO_BUILD_TARGET=aarch64 -unknown-linux-musl \
98
+ CARGO_BUILD_TARGET=${AARCH} -unknown-linux-musl \
92
99
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld -Ctarget-feature=+crt-static" \
93
100
PKG_CONFIG_ALLOW_CROSS=true \
94
101
PKG_CONFIG_ALL_STATIC=true \
95
102
PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig \
103
+ PG_CONFIG_X86_64_UNKNOWN_LINUX_GNU=/usr/bin/pg_config \
96
104
PG_CONFIG_AARCH64_UNKNOWN_LINUX_GNU=/usr/bin/pg_config \
105
+ # Rust libz-sys support
97
106
LIBZ_SYS_STATIC=1 \
107
+ ZLIB_STATIC=1 \
98
108
DEBIAN_FRONTEND=noninteractive \
99
109
TZ=Etc/UTC
100
110
0 commit comments