From 374ae5b8f3af3fe5720822dbd393e4945e90e0eb Mon Sep 17 00:00:00 2001 From: Avi Deitcher Date: Sun, 18 Aug 2024 10:54:45 +0300 Subject: [PATCH] cross-compile cargo plugins Signed-off-by: Avi Deitcher --- Dockerfile | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index ed3b062..a5c165f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,8 +1,23 @@ ARG RUST_VERSION=1.80.1 -FROM rust:${RUST_VERSION}-alpine3.20 -ENV TARGETS="x86_64-unknown-linux-musl aarch64-unknown-linux-musl x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu riscv64gc-unknown-linux-gnu" + +FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx + +FROM --platform=$BUILDPLATFORM rust:${RUST_VERSION}-alpine3.20 AS builder +ARG TARGETARCH +ARG TARGETOS +COPY --from=xx / / +RUN echo $(xx-info march)-unknown-$(xx-info os)-musl > /etc/rustc_target + +RUN rustup target add $(cat /etc/rustc_target) +# needed for cargo-chef and cargo-sbom +RUN apk add musl-dev linux-headers make +RUN cargo install --target=$(cat /etc/rustc_target) cargo-chef@0.1.67 cargo-sbom@0.9.1 + +FROM rust:${RUST_VERSION}-alpine3.20 AS toolchain +ARG TARGETS="x86_64-unknown-linux-musl aarch64-unknown-linux-musl x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu riscv64gc-unknown-linux-gnu" RUN rustup target add ${TARGETS} -# needed for cargo-chef and cargo-sbom, as well as many other compilations +# needed for downstream compilations RUN apk add musl-dev linux-headers make -RUN cargo install cargo-chef@0.1.67 cargo-sbom@0.9.1 +COPY --from=builder /usr/local/cargo/bin/cargo-chef /usr/local/cargo/bin +COPY --from=builder /usr/local/cargo/bin/cargo-sbom /usr/local/cargo/bin