Skip to content

Commit

Permalink
Use partial-static linking for all bins
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-bcw committed Aug 19, 2024
1 parent f8fc743 commit d1577f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .cargo/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
# https://github.com/rust-lang/rust/pull/124129
# https://github.com/dtolnay/linkme/pull/88
rustflags = ["-Z", "linker-features=-lld"]

[target.x86_64-unknown-linux-gnu]
linker = "clang-16"
16 changes: 7 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,18 @@ RUN apt-get update && apt-get install -y \
# for openssl
libssl-dev \
pkg-config \
# for static linking
clang-16 \
# clean the image
&& rm -rf /var/lib/apt/lists/*

ARG PROFILE=release
# forward the docker argument so that the script below can read it
ENV PROFILE=${PROFILE}

# statically link the C runtime (but not openssl)
ENV COMMON_RUSTFLAGS='-C target-cpu=native -Zlinker-features=-lld -C target-feature=+crt-static'

# Build the application.
RUN \
# mount the repository so we don't have to COPY it in
Expand All @@ -46,17 +51,10 @@ set -eux
# .cargo/config.toml
cd /src

# don't statically build the leader or coordinator
ENV COMMON_RUSTFLAGS='-C target-cpu=native -Zlinker-features=-lld'

# use the cache mount
# (we will not be able to to write to e.g `/src/target` because it is bind-mounted)
RUN RUSTFLAGS="${COMMON_RUSTFLAGS}" \
CARGO_TARGET_DIR=/artifacts cargo build --locked "--profile=${PROFILE}" --target=x86_64-unknown-linux-gnu --bin coordinator --bin leader

# statically build the worker
RUN RUSTFLAGS="${COMMON_RUSTFLAGS} -C target-feature=+crt-static" \
CARGO_TARGET_DIR=/artifacts cargo build --locked "--profile=${PROFILE}" --target=x86_64-unknown-linux-gnu --bin worker
CC=clang-16 RUSTFLAGS="${COMMON_RUSTFLAGS}" \
CARGO_TARGET_DIR=/artifacts cargo build --locked "--profile=${PROFILE}" --target=x86_64-unknown-linux-gnu --bin worker --bin coordinator --bin leader --bin rpc --bin verifier


# narrow the find call to SUBDIR because if we just copy out all executables
Expand Down

0 comments on commit d1577f9

Please sign in to comment.