Skip to content

Commit

Permalink
cross-compile cargo plugins
Browse files Browse the repository at this point in the history
Signed-off-by: Avi Deitcher <[email protected]>
  • Loading branch information
deitch committed Aug 18, 2024
1 parent 52f71f6 commit 29e1b39
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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) [email protected] [email protected]

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 [email protected] [email protected]
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

0 comments on commit 29e1b39

Please sign in to comment.