|
1 | 1 | ARG RUST_VERSION=1.80.1
|
| 2 | +FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-alpine3.20 AS tools-host |
| 3 | +ARG BUILDPLATFORM |
| 4 | +ARG TARGETARCH |
| 5 | + |
| 6 | +ENV TARGETS="x86_64-unknown-linux-musl aarch64-unknown-linux-musl x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu riscv64gc-unknown-linux-gnu" |
| 7 | +RUN rustup target add ${TARGETS} |
| 8 | +RUN apk add musl-dev linux-headers make clang mold |
| 9 | + |
| 10 | +FROM tools-host AS target-amd64 |
| 11 | +ENV CARGO_BUILD_TARGET="x86_64-unknown-linux-musl" |
| 12 | + |
| 13 | +FROM tools-host AS target-arm64 |
| 14 | +ENV CARGO_BUILD_TARGET="aarch64-unknown-linux-musl" |
| 15 | + |
| 16 | +FROM tools-host AS target-riscv64 |
| 17 | +ENV CARGO_BUILD_TARGET="riscv64gc-unknown-linux-gnu" |
| 18 | + |
| 19 | +FROM target-$TARGETARCH AS tools |
| 20 | +RUN echo "Cargo target: $CARGO_BUILD_TARGET" |
| 21 | + |
| 22 | +ADD config.toml /usr/local/cargo/ |
| 23 | +# CARGO_BUILD_TARGET is respected by cargo install and other cargo commands |
| 24 | +RUN cargo install --root /cargo-cross [email protected] [email protected] |
| 25 | + |
| 26 | + |
2 | 27 | FROM rust:${RUST_VERSION}-alpine3.20
|
3 | 28 | ENV TARGETS="x86_64-unknown-linux-musl aarch64-unknown-linux-musl x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu riscv64gc-unknown-linux-gnu"
|
4 | 29 | RUN rustup target add ${TARGETS}
|
5 | 30 |
|
6 | 31 | # needed for cargo-chef and cargo-sbom, as well as many other compilations
|
7 |
| -RUN apk add musl-dev linux-headers make |
8 |
| - |
| 32 | +RUN apk add musl-dev linux-headers make clang mold |
| 33 | + |
| 34 | +# copy the cargo plugins from the tools stage |
| 35 | +COPY --from=tools /cargo-cross /usr/local/cargo |
| 36 | +# we define target specific rustc flags for cross-compilation |
| 37 | +ADD config.toml /usr/local/cargo/ |
0 commit comments