Skip to content

Commit cb9b9c8

Browse files
committed
Add makefile command to create reproducible build
1 parent 784ad05 commit cb9b9c8

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Makefile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,26 @@ GIT_TAG ?= $(shell git describe --tags --abbrev=0)
77

88
FEATURES ?=
99

10+
# Environment variables for reproducible builds
11+
# Initialize RUSTFLAGS
12+
RUST_BUILD_FLAGS =
13+
# Enable static linking to ensure reproducibility across builds
14+
RUST_BUILD_FLAGS += --C target-feature=+crt-static
15+
# Set the linker to use static libgcc to ensure reproducibility across builds
16+
RUST_BUILD_FLAGS += -C link-arg=-static-libgcc
17+
# Remove build ID from the binary to ensure reproducibility across builds
18+
RUST_BUILD_FLAGS += -C link-arg=-Wl,--build-id=none
19+
# Remove metadata hash from symbol names to ensure reproducible builds
20+
RUST_BUILD_FLAGS += -C metadata=''
21+
# Set timestamp from last git commit for reproducible builds
22+
SOURCE_DATE ?= $(shell git log -1 --pretty=%ct)
23+
# Disable incremental compilation to avoid non-deterministic artifacts
24+
CARGO_INCREMENTAL_VAL = 0
25+
# Set C locale for consistent string handling and sorting
26+
LOCALE_VAL = C
27+
# Set UTC timezone for consistent time handling across builds
28+
TZ_VAL = UTC
29+
1030
##@ Help
1131

1232
.PHONY: help
@@ -31,6 +51,15 @@ build: ## Build (debug version)
3151
op-rbuilder: ## Build op-rbuilder (debug version)
3252
cargo build -p op-rbuilder --bin op-rbuilder --features "$(FEATURES)"
3353

54+
.PHONY: build-reproducible
55+
build-reproducible: ## Build the reth binary into `target` directory with reproducible builds. Only works for x86_64-unknown-linux-gnu currently
56+
SOURCE_DATE_EPOCH=$(SOURCE_DATE) \
57+
RUSTFLAGS="${RUST_BUILD_FLAGS} --remap-path-prefix $$(pwd)=." \
58+
CARGO_INCREMENTAL=${CARGO_INCREMENTAL_VAL} \
59+
LC_ALL=${LOCALE_VAL} \
60+
TZ=${TZ_VAL} \
61+
cargo build -p op-rbuilder --bin op-rbuilder --features "$(FEATURES)" --profile "release" --locked --target x86_64-unknown-linux-gnu --features "$(FEATURES)"
62+
3463
.PHONY: tdx-quote-provider
3564
tdx-quote-provider: ## Build tdx-quote-provider (debug version)
3665
cargo build -p tdx-quote-provider --bin tdx-quote-provider --features "$(FEATURES)"

0 commit comments

Comments
 (0)