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:
parent
f50492f132
commit
a873049e96
1 changed files with 10 additions and 3 deletions
|
|
@ -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\
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue