From c01f727344123688960d50989ba69aeada9d74ce Mon Sep 17 00:00:00 2001 From: Mikhail Malyshev Date: Fri, 23 Aug 2024 12:20:39 +0200 Subject: [PATCH 1/2] Set default build target for native builds Signed-off-by: Mikhail Malyshev --- Dockerfile | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index db4ae35..cd2e329 100644 --- a/Dockerfile +++ b/Dockerfile @@ -24,7 +24,7 @@ ADD config.toml /usr/local/cargo/ RUN cargo install --root /cargo-cross cargo-chef@0.1.67 cargo-sbom@0.9.1 -FROM rust:${RUST_VERSION}-alpine3.20 +FROM rust:${RUST_VERSION}-alpine3.20 AS tools-target-base ENV 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} @@ -35,3 +35,15 @@ RUN apk add musl-dev linux-headers make clang mold COPY --from=tools /cargo-cross /usr/local/cargo # we define target specific rustc flags for cross-compilation ADD config.toml /usr/local/cargo/ + +FROM tools-target-base AS tools-target-amd64 +ENV CARGO_BUILD_TARGET="x86_64-unknown-linux-musl" + +FROM tools-target-base AS tools-target-arm64 +ENV CARGO_BUILD_TARGET="aarch64-unknown-linux-musl" + +FROM tools-target-base AS tools-target-riscv64 +ENV CARGO_BUILD_TARGET="riscv64gc-unknown-linux-gnu" + +FROM tools-target-$TARGETARCH AS tools-target +RUN echo "Cargo target: $CARGO_BUILD_TARGET" From 2b63002926c2453e5287644b123f1ef0015d9ef1 Mon Sep 17 00:00:00 2001 From: Mikhail Malyshev Date: Fri, 23 Aug 2024 13:28:43 +0200 Subject: [PATCH 2/2] Add python3 to the image as it is often required Signed-off-by: Mikhail Malyshev --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index cd2e329..25b9f7a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -29,7 +29,7 @@ ENV TARGETS="x86_64-unknown-linux-musl aarch64-unknown-linux-musl x86_64-unknown RUN rustup target add ${TARGETS} # needed for cargo-chef and cargo-sbom, as well as many other compilations -RUN apk add musl-dev linux-headers make clang mold +RUN apk add musl-dev linux-headers make clang mold python3 # copy the cargo plugins from the tools stage COPY --from=tools /cargo-cross /usr/local/cargo