Skip to content

Commit

Permalink
Use static linking for worker
Browse files Browse the repository at this point in the history
  • Loading branch information
julian-bcw authored and patrick-bcw committed Aug 15, 2024
1 parent a965cb1 commit 255716a
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions optimized-worker.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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
Expand Down Expand Up @@ -104,4 +104,4 @@ COPY --from=build ["/output/worker", "/usr/local/bin/"]
# --uid "${UID}" \
# user
# USER user
CMD ["worker"]
CMD ["worker"]
4 changes: 3 additions & 1 deletion pgo-worker.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,7 +42,7 @@ RUN \
<<EOF
set -eux

cargo pgo build -- --locked --bin worker
cargo pgo build -- --locked --bin worker --target=x86_64-unknown-linux-gnu

EOF

Expand Down
39 changes: 39 additions & 0 deletions worker.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
FROM rustlang/rust:nightly-bullseye-slim as builder

RUN apt-get update && apt-get install -y libjemalloc2 libjemalloc-dev make libssl-dev pkg-config

RUN mkdir -p zero_bin
COPY Cargo.toml .
# Cleanup all workspace members and add selected crates again
RUN sed -i '/members =/{:a;N;/]/!ba};//d' Cargo.toml
RUN sed -i 's#\[workspace\]#\[workspace\]\nmembers = \["zero_bin\/worker", "zero_bin\/common", "zero_bin\/ops"\, "evm_arithmetization", "mpt_trie", "proc_macro"\]#' Cargo.toml
COPY Cargo.lock .
COPY ./rust-toolchain.toml ./

COPY proof_gen proof_gen
COPY mpt_trie mpt_trie
COPY evm_arithmetization evm_arithmetization
COPY proc_macro proc_macro
COPY zero_bin/common zero_bin/common
COPY zero_bin/ops zero_bin/ops
COPY zero_bin/worker zero_bin/worker

RUN \
touch zero_bin/common/src/lib.rs && \
touch zero_bin/ops/src/lib.rs && \
touch zero_bin/worker/src/main.rs && \
touch evm_arithmetization/src/lib.rs && \
touch mpt_trie/src/lib.rs && \
touch proc_macro/src/lib.rs

# Disable the lld linker for now, as it's causing issues with the linkme package.
# https://github.com/rust-lang/rust/pull/124129
# https://github.com/dtolnay/linkme/pull/88
ENV RUSTFLAGS='-C target-feature=+crt-static -C target-cpu=native -Zlinker-features=-lld'

RUN cargo build --release --bin worker --target=x86_64-unknown-linux-gnu

FROM debian:bullseye-slim
RUN apt-get update && apt-get install -y ca-certificates libjemalloc2
COPY --from=builder ./target/release/worker /usr/local/bin/worker
ENTRYPOINT ["/usr/local/bin/worker"]
13 changes: 13 additions & 0 deletions zero_bin/worker/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,19 @@ tracing-subscriber = { workspace = true }
clap = { workspace = true }
tokio = { workspace = true }
log = "0.4.21"
alloy = { git = "https://github.com/alloy-rs/alloy", tag = 'v0.1.1', default-features = false, features = [
"consensus",
"json-rpc",
"rlp",
"rpc",
"rpc-client",
"rpc-types-eth",
"rpc-types-trace",
"providers",
"transports",
"transport-http",
"rpc-types-debug",
] }

# Local dependencies
ops = { workspace = true }
Expand Down

0 comments on commit 255716a

Please sign in to comment.