fix: install gcc and configure native x86_64 linker in build image

rust:slim-bookworm doesn't include gcc, and aes-gcm's build deps (via
cc-rs) need a C compiler. With --target x86_64-unknown-linux-gnu set
explicitly, cc-rs looks for the cross-compiler 'x86_64-linux-gnu-gcc'
instead of native 'gcc'.

Fix: install gcc in the build stage and add a [target.x86_64-*] linker
entry pointing to 'gcc' so cc-rs finds it on native x86_64 builds.

https://claude.ai/code/session_01FKCW3FDjNFj6jve4niMFXH
This commit is contained in:
Claude 2026-03-24 16:23:02 +00:00
parent f50492f132
commit a873049e96
No known key found for this signature in database

View file

@ -8,8 +8,10 @@ ARG TARGETPLATFORM
ARG TARGETARCH
ARG TARGETVARIANT
# Install cross-compilation toolchains only when actually cross-compiling.
RUN apt-get update && apt-get install -y pkg-config && \
# Install build tools. gcc is always needed: cc-rs (used by ring/aes-gcm deps)
# calls the native compiler even on native builds, and rust:slim doesn't
# include it. Cross-compilers are added only when actually cross-compiling.
RUN apt-get update && apt-get install -y gcc pkg-config && \
if [ "${BUILDPLATFORM}" != "${TARGETPLATFORM}" ]; then \
case "${TARGETARCH}:${TARGETVARIANT}" in \
"arm64:") apt-get install -y gcc-aarch64-linux-gnu ;; \
@ -29,8 +31,13 @@ RUN case "${TARGETARCH}:${TARGETVARIANT}" in \
esac > /rust_target && \
rustup target add "$(cat /rust_target)"
# Tell Cargo which cross-linker to use (ignored on native builds).
# Tell Cargo which linker to use for each target.
# x86_64 native: use plain gcc (cc-rs would otherwise look for
# "x86_64-linux-gnu-gcc" which is the *cross* toolchain, not installed here).
RUN mkdir -p /root/.cargo && printf '\
[target.x86_64-unknown-linux-gnu]\n\
linker = "gcc"\n\
\n\
[target.aarch64-unknown-linux-gnu]\n\
linker = "aarch64-linux-gnu-gcc"\n\
\n\