Skip to content

Commit

Permalink
remove cargo-chef and link to libgcc on aarch64.
Browse files Browse the repository at this point in the history
  • Loading branch information
Erk- committed Mar 13, 2024
1 parent 93d22c6 commit 490a201
Showing 1 changed file with 5 additions and 21 deletions.
26 changes: 5 additions & 21 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# Rust syntax target, either x86_64-unknown-linux-musl, aarch64-unknown-linux-musl etc.
ARG RUST_TARGET="aarch64-unknown-linux-musl"
ARG RUST_TARGET="x86_64-unknown-linux-musl"
# The crate features to build this with
ARG FEATURES=""

FROM --platform=$BUILDPLATFORM rustlang/rust:nightly AS chef
FROM --platform=$BUILDPLATFORM rustlang/rust:nightly AS builder
ARG RUST_TARGET
ARG FEATURES

RUN <<EOT
set -ex
apt-get update
apt-get upgrade
apt-get install --assume-yes musl-dev clang lld
apt-get install --assume-yes musl-dev clang lld libgcc-12-dev-arm64-cross
EOT

RUN <<-EOT bash
Expand All @@ -20,8 +20,6 @@ RUN <<-EOT bash
rustup component add rust-src --toolchain "nightly"
EOT

RUN cargo install cargo-chef --locked

COPY <<EOF /app/.cargo/config.toml
[env]
CC_aarch64-unknown-linux-musl = "clang -target aarch64-unknown-linux-musl -fuse-ld=lld"
Expand All @@ -34,6 +32,8 @@ linker = "clang"
rustflags = [
"-C", "link-args=-target aarch64-unknown-linux-musl -fuse-ld=lld",
"-C", "strip=symbols",
# aarch64 has to link libgcc
"-C", "link-arg=-lgcc",
]

[target.x86_64-unknown-linux-musl]
Expand All @@ -49,21 +49,6 @@ EOF

WORKDIR /app

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /app/recipe.json recipe.json
RUN <<-EOF bash
set -ex
if test "$FEATURES" = ""; then
cargo chef cook --target "$RUST_TARGET" --release --recipe-path recipe.json
else
cargo chef cook --target "$RUST_TARGET" --features="$FEATURES" --release --recipe-path recipe.json
fi
EOF

COPY . .

RUN <<-EOF bash
Expand All @@ -76,7 +61,6 @@ RUN <<-EOF bash
cp target/$RUST_TARGET/release/twilight-http-proxy /twilight-http-proxy
EOF


FROM scratch

COPY --from=builder /twilight-http-proxy /twilight-http-proxy
Expand Down

0 comments on commit 490a201

Please sign in to comment.