mirror of
https://github.com/dockersrc/rust
synced 2026-06-24 14:01:04 -04:00
🐛 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:
+14
-4
@@ -40,10 +40,20 @@ FROM tianon/gosu:latest AS gosu
|
||||
FROM --platform=$BUILDPLATFORM rust:alpine AS rust-tools
|
||||
ARG TARGETARCH
|
||||
|
||||
# musl-cross provides aarch64-linux-musl-gcc for arm64 cross-compilation;
|
||||
# it lives in the Alpine community repo which rust:alpine does not enable by default
|
||||
RUN apk add --no-cache curl jq \
|
||||
&& apk add --no-cache --repository https://dl-cdn.alpinelinux.org/alpine/edge/community musl-cross
|
||||
# zig acts as a universal C/C++ cross-compiler — ships with bundled musl headers
|
||||
# and stdlib for all targets, so no separate musl-cross toolchain is needed.
|
||||
# Wrapper scripts named aarch64-linux-musl-{gcc,g++,ar} let the CARGO_TARGET_*
|
||||
# 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
|
||||
RUN case "${TARGETARCH}" in \
|
||||
|
||||
Reference in New Issue
Block a user