-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cross compile docker images instead of emulating
- Loading branch information
Showing
2 changed files
with
37 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
FROM rust:1-bullseye AS chef | ||
RUN cargo install cargo-chef | ||
WORKDIR /app | ||
FROM --platform=${BUILDPLATFORM:-linux/amd64} tonistiigi/xx AS xx | ||
|
||
FROM chef AS planner | ||
COPY . . | ||
RUN cargo chef prepare --recipe-path recipe.json | ||
FROM --platform=${BUILDPLATFORM:-linux/amd64} rust:1-bullseye as builder | ||
|
||
FROM chef AS builder | ||
WORKDIR /app | ||
|
||
RUN apt-get update && apt-get install -y build-essential cmake clang \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
COPY --from=xx / / | ||
|
||
COPY --from=planner /app/recipe.json recipe.json | ||
# install native dependencies first so we can cache them | ||
RUN apt-get update && \ | ||
apt-get install -y build-essential cmake clang llvm g++ | ||
|
||
# Build dependencies - this is the caching Docker layer! | ||
RUN cargo chef cook --release --recipe-path recipe.json | ||
ARG TARGETPLATFORM | ||
ENV TARGETPLATFORM=${TARGETPLATFORM:-linux/amd64} | ||
|
||
RUN xx-apt-get install -y xx-cxx-essentials g++ | ||
|
||
# Build application | ||
COPY . . | ||
RUN cargo build --release --bin aero2solver | ||
|
||
FROM debian:bullseye-slim | ||
RUN ./build.sh | ||
|
||
RUN apt-get update && apt-get install -y libgomp1 \ | ||
&& rm -rf /var/lib/apt/lists/* | ||
FROM debian:bullseye-slim AS runtime | ||
|
||
WORKDIR /app | ||
|
||
RUN apt-get update && \ | ||
apt-get install -y libgomp1 && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
COPY ./model/ ./model/ | ||
COPY --from=builder /app/target/release/aero2solver ./aero2solver | ||
COPY --from=builder /app/target/aero2solver ./aero2solver | ||
|
||
ENTRYPOINT [ "/app/aero2solver" ] | ||
ENTRYPOINT [ "/app/aero2solver" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
# set -x | ||
set -e | ||
|
||
# shellcheck disable=SC1091 | ||
. xx-cargo --setup-target-triple | ||
RUST_TARGET_TRIPLE="$(xx-cargo --print-target-triple)" | ||
|
||
if ! xx-info is-cross; then | ||
# remove these clang declarations to avoid linking errors | ||
unset "CARGO_TARGET_$(echo "$RUST_TARGET_TRIPLE" | tr '[:lower:]' '[:upper:]' | tr - _)_LINKER"; | ||
unset "CC_$(echo "$RUST_TARGET_TRIPLE" | tr - _)" | ||
fi | ||
|
||
cargo build --release --bin aero2solver --target="$RUST_TARGET_TRIPLE" | ||
xx-verify "./target/$RUST_TARGET_TRIPLE/release/aero2solver" | ||
cp "./target/$RUST_TARGET_TRIPLE/release/aero2solver" "./target/aero2solver" |