🐛 Replace musl-cross with zig cc wrappers for arm64 cross-compile 🐛

musl-cross does not exist in any Alpine package repo (main, community,
or edge) — both attempts to install it failed at build time.
Zig ships with Alpine (`apk add zig`) and bundles its own musl headers
and stdlib for every target triple, making it a drop-in replacement for
a musl cross-toolchain with zero external dependencies.
Three wrapper scripts are created at install time:
/usr/local/bin/aarch64-linux-musl-gcc → zig cc -target aarch64-linux-musl
/usr/local/bin/aarch64-linux-musl-g++ → zig c++ -target aarch64-linux-musl
/usr/local/bin/aarch64-linux-musl-ar → zig ar
The CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER and CC_*/CXX_*/AR_*
env vars are unchanged — they still point to aarch64-linux-musl-gcc,
which now resolves to the zig wrapper.
- Dockerfile: replace musl-cross apk install with zig + wrapper scripts

Dockerfile
This commit is contained in:
2026-06-21 18:17:10 -04:00
parent a10a527f46
commit 0a06ccafa1
+14 -4
View File
@@ -40,10 +40,20 @@ FROM tianon/gosu:latest AS gosu
FROM --platform=$BUILDPLATFORM rust:alpine AS rust-tools FROM --platform=$BUILDPLATFORM rust:alpine AS rust-tools
ARG TARGETARCH ARG TARGETARCH
# musl-cross provides aarch64-linux-musl-gcc for arm64 cross-compilation; # zig acts as a universal C/C++ cross-compiler — ships with bundled musl headers
# it lives in the Alpine community repo which rust:alpine does not enable by default # and stdlib for all targets, so no separate musl-cross toolchain is needed.
RUN apk add --no-cache curl jq \ # Wrapper scripts named aarch64-linux-musl-{gcc,g++,ar} let the CARGO_TARGET_*
&& apk add --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/community musl-cross # env vars below work without any changes.
RUN apk add --no-cache curl jq zig \
&& printf '#!/bin/sh\nexec zig cc -target aarch64-linux-musl "$@"\n' \
> /usr/local/bin/aarch64-linux-musl-gcc \
&& printf '#!/bin/sh\nexec zig c++ -target aarch64-linux-musl "$@"\n' \
> /usr/local/bin/aarch64-linux-musl-g++ \
&& printf '#!/bin/sh\nexec zig ar "$@"\n' \
> /usr/local/bin/aarch64-linux-musl-ar \
&& chmod +x /usr/local/bin/aarch64-linux-musl-gcc \
/usr/local/bin/aarch64-linux-musl-g++ \
/usr/local/bin/aarch64-linux-musl-ar
# Resolve Docker TARGETARCH → Rust target triple # Resolve Docker TARGETARCH → Rust target triple
RUN case "${TARGETARCH}" in \ RUN case "${TARGETARCH}" in \