From d5e238fb99f92ce32f7e2f3cdda212bd6c859542 Mon Sep 17 00:00:00 2001 From: julian-bcw Date: Wed, 14 Aug 2024 18:38:30 +0100 Subject: [PATCH] Use static linking for worker --- Cargo.lock | 1 + optimized-worker.Dockerfile | 6 +++--- pgo-worker.Dockerfile | 4 +++- zero_bin/worker/Cargo.toml | 13 +++++++++++++ 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a5bdbe46c..5ac9c50fe 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6362,6 +6362,7 @@ dependencies = [ name = "worker" version = "0.1.0" dependencies = [ + "alloy", "anyhow", "clap", "dotenvy", diff --git a/optimized-worker.Dockerfile b/optimized-worker.Dockerfile index d0c7a7080..33144a42d 100644 --- a/optimized-worker.Dockerfile +++ b/optimized-worker.Dockerfile @@ -34,7 +34,7 @@ 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' +ENV RUSTFLAGS='-C target-feature=+crt-static -C target-cpu=native -Zlinker-features=-lld' # Build the application. RUN \ @@ -56,7 +56,7 @@ cp -r pgo-profiles/* /artifacts/pgo-profiles # 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 pgo optimize build -- --bin worker --locked "--profile=${PROFILE}" +CARGO_TARGET_DIR=/artifacts cargo pgo optimize build -- --bin worker --locked "--profile=${PROFILE}" --target=x86_64-unknown-linux-gnu # narrow the find call to SUBDIR because if we just copy out all executables # we will break the cache invariant @@ -104,4 +104,4 @@ COPY --from=build ["/output/worker", "/usr/local/bin/"] # --uid "${UID}" \ # user # USER user -CMD ["worker"] \ No newline at end of file +CMD ["worker"] diff --git a/pgo-worker.Dockerfile b/pgo-worker.Dockerfile index 3206a4de4..cbc34ebf0 100644 --- a/pgo-worker.Dockerfile +++ b/pgo-worker.Dockerfile @@ -32,6 +32,8 @@ WORKDIR /src COPY . . +ENV RUSTFLAGS='-C target-feature=+crt-static -C target-cpu=native -Zlinker-features=-lld' + # Build the application. RUN \ # cache artifacts and the cargo registry to speed up subsequent builds @@ -40,7 +42,7 @@ RUN \ <