Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add reproducible build profile #10459

Merged
merged 12 commits into from
Oct 22, 2024
Merged
7 changes: 7 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,13 @@ codegen-units = 1
inherits = "release"
lto = "fat"

[profile.reproducible]
inherits = "release"
debug = false
panic = "abort"
codegen-units = 1
overflow-checks = true

[workspace.dependencies]
# reth
op-reth = { path = "crates/optimism/bin" }
Expand Down
37 changes: 37 additions & 0 deletions Dockerfile.reproducible
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Use the Rust 1.80 image based on Debian Bullseye
FROM rust:1.80-bullseye@sha256:c1490599f028ae06740706279a81c09687dde26c2d00f7160b85f63e9f6d8607 as builder
Rjected marked this conversation as resolved.
Show resolved Hide resolved

# Install specific version of libclang-dev
RUN apt-get update && apt-get install -y libclang-dev=1:11.0-51+nmu5

# Clone the repository at the specific branch
RUN git clone https://github.com/paradigmxyz/reth /app
WORKDIR /app

# Checkout the reproducible-build branch
RUN git checkout reproducible-build

# Get the latest commit timestamp and set SOURCE_DATE_EPOCH
RUN SOURCE_DATE_EPOCH=$(git log -1 --pretty=%ct) && \
echo "SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH" >> /etc/environment

# Set environment variables for reproducibility
ARG RUSTFLAGS="-C link-arg=-Wl,--build-id=none -Clink-arg=-static-libgcc -C metadata='' --remap-path-prefix $$(pwd)=."
ENV SOURCE_DATE_EPOCH=$SOURCE_DATE_EPOCH \
CARGO_INCREMENTAL=0 \
LC_ALL=C \
TZ=UTC \
RUSTFLAGS="${RUSTFLAGS}"

# Set the default features if not provided
ARG FEATURES="jemalloc asm-keccak"

# Build the project with the reproducible settings
RUN . /etc/environment && \
cargo build --bin reth --features "${FEATURES}" --profile "reproducible" --locked

# Create a minimal final image with just the binary
FROM scratch as binaries

# Copy the compiled binary from the builder stage
COPY --from=builder /app/target/reproducible/reth /reth
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ install-op: ## Build and install the op-reth binary under `~/.cargo/bin`.
build: ## Build the reth binary into `target` directory.
cargo build --bin reth --features "$(FEATURES)" --profile "$(PROFILE)"

SOURCE_DATE_EPOCH := $(shell git log -1 --pretty=%ct)
.PHONY: build-reproducible
build-reproducible: ## Build the reth binary into `target` directory with reproducible builds.
SOURCE_DATE_EPOCH=$(SOURCE_DATE_EPOCH) \
CARGO_INCREMENTAL=0 \
LC_ALL=C \
TZ=UTC \
RUSTFLAGS="-C link-arg=-Wl,--build-id=none -Clink-arg=-static-libgcc -C metadata='' --remap-path-prefix $$(pwd)=." \
cargo build --bin reth --features "$(FEATURES)" --profile "reproducible" --locked

.PHONY: build-debug
build-debug: ## Build the reth binary into `target/debug` directory.
cargo build --bin reth --features "$(FEATURES)"
Expand Down
Loading