Skip to content

Commit

Permalink
Build worker with static linking, leader and coordinator with dynamic…
Browse files Browse the repository at this point in the history
… linking
  • Loading branch information
julianbraha committed Aug 19, 2024
1 parent 512527a commit f8fc743
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ ARG PROFILE=release
# forward the docker argument so that the script below can read it
ENV PROFILE=${PROFILE}

ENV RUSTFLAGS='-C target-cpu=native -Zlinker-features=-lld'

# Build the application.
RUN \
# mount the repository so we don't have to COPY it in
Expand All @@ -48,9 +46,19 @@ 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)
CARGO_TARGET_DIR=/artifacts cargo build --locked "--profile=${PROFILE}" --all
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


# narrow the find call to SUBDIR because if we just copy out all executables
# we will break the cache invariant
if [ "$PROFILE" = "dev" ]; then
Expand All @@ -62,8 +70,9 @@ fi
# maxdepth because binaries are in the root
# - other folders contain build scripts etc.
mkdir /output
find "/artifacts/$SUBDIR" \
-maxdepth 1 \
find "/artifacts"
find "/artifacts/x86_64-unknown-linux-gnu" \
-maxdepth 2 \
-type f \
-executable \
-not -name '*.so' \
Expand Down

0 comments on commit f8fc743

Please sign in to comment.