Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default build target for native builds #10

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,26 @@ 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}

# 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
# 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"