Skip to content
Merged
Changes from 4 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
27 changes: 22 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
FROM rust:alpine AS chef
RUN apk add --no-cache musl-dev
COPY rust-toolchain.toml .
RUN rustup show && cargo install cargo-chef
# rust-src feeds -Zbuild-std in the builder stage.
RUN rustup show && rustup component add rust-src && cargo install cargo-chef --locked
WORKDIR /app

FROM chef AS planner
Expand All @@ -25,15 +26,31 @@ RUN cargo chef prepare --recipe-path recipe.json
# --- Builder: cook deps (cached layer), then compile source ---
FROM chef AS builder

ENV RUSTFLAGS="-C target-cpu=native"
# -Zshare-generics reuses upstream monomorphizations instead of re-codegening
# them per crate, deduplicating most cross-crate generic/coroutine copies
# (measured: -666 KiB, -5.6% .text). Nightly-only, which this image already
# pins via rust-toolchain.toml; with fat LTO the historical inlining downside
# does not apply since LTO sees all bitcode anyway.
ENV RUSTFLAGS="-C target-cpu=native -Zshare-generics=y"
Comment thread
jlucaso1 marked this conversation as resolved.
Comment thread
jlucaso1 marked this conversation as resolved.

# build-std recompiles std with the release profile so it participates in fat
# LTO and dead-code elimination instead of linking the prebuilt rustup std
# (measured: another -303 KiB). The env form reaches both the chef cook and
# the final build, keeping the dependency cache layer valid; build-std
# requires an explicit --target, hence the musl triple on both invocations.
ENV CARGO_UNSTABLE_BUILD_STD="std,panic_abort"

# The dependency cook runs before the source COPY, so make the nightly
# override explicit in /app instead of relying on rustup walking up to the
# chef stage's copy at /; the nightly-only RUSTFLAGS above depends on it.
COPY rust-toolchain.toml .
COPY --from=planner /app/recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
RUN cargo chef cook --release --recipe-path recipe.json --target x86_64-unknown-linux-musl
COPY . .
RUN cargo build --release
RUN cargo build --release --target x86_64-unknown-linux-musl
Comment thread
jlucaso1 marked this conversation as resolved.
Outdated

# --- Runtime: static binary on empty image ---
FROM scratch
COPY --from=builder /app/target/release/whatsapp-rust /whatsapp-rust
COPY --from=builder /app/target/x86_64-unknown-linux-musl/release/whatsapp-rust /whatsapp-rust
WORKDIR /data
ENTRYPOINT ["/whatsapp-rust"]
Loading