Skip to content

Commit

Permalink
Statically link on default target
Browse files Browse the repository at this point in the history
  • Loading branch information
diegomrsantos committed Oct 24, 2023
1 parent b6f763c commit a7ceded
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions hole-punching-tests/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
# syntax=docker/dockerfile:1.5-labs
FROM rust:1.72.0 as builder

ARG RUST_TARGET

RUN rustup target add $RUST_TARGET

RUN --mount=type=cache,target=/var/cache/apt apt-get update && apt-get install -y musl-dev musl-tools

# Run with access to the target cache to speed up builds
WORKDIR /workspace
ADD . .

# Build the relay as a statically-linked binary. Unfortunately, we must specify the `--target` explicitly. See https://msfjarvis.dev/posts/building-static-rust-binaries-for-linux/.
RUN --mount=type=cache,target=./target \
--mount=type=cache,target=/usr/local/cargo/registry \
cargo build --release --package hole-punching-tests --target $RUST_TARGET
RUSTFLAGS='-C target-feature=+crt-static' cargo build --release --package hole-punching-tests --target $(rustc -vV | grep host | awk '{print $2}')

RUN --mount=type=cache,target=./target \
mv ./target/$RUST_TARGET/release/hole-punching-tests /usr/local/bin/hole-punching-tests
mv ./target/$(rustc -vV | grep host | awk '{print $2}')/release/hole-punching-tests /usr/local/bin/hole-punching-tests

FROM alpine:3
COPY --from=builder /usr/local/bin/hole-punching-tests /usr/bin/hole-punch-client
Expand Down

0 comments on commit a7ceded

Please sign in to comment.