# Modifed from reth Makefile .DEFAULT_GOAL := help GIT_SHA ?= $(shell git rev-parse HEAD) GIT_TAG ?= $(shell git describe --tags --abbrev=0 2>/dev/null) BIN_DIR = "dist/bin" # List of features to use when building. Can be overridden via the environment. # No jemalloc on Windows ifeq ($(OS),Windows_NT) FEATURES ?= asm-keccak min-debug-logs else FEATURES ?= jemalloc asm-keccak min-debug-logs endif # Cargo profile for builds. Default is for local builds, CI uses an override. PROFILE ?= release # Extra flags for Cargo CARGO_INSTALL_EXTRA_FLAGS ?= # The docker image name DOCKER_IMAGE_NAME ?= ghcr.io/hl-archive-node/nanoreth ##@ Help .PHONY: help help: ## Display this help. @awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST) ##@ Build .PHONY: install install: ## Build and install the reth binary under `~/.cargo/bin`. cargo install --path . --bin reth-hl --force --locked \ --features "$(FEATURES)" \ --profile "$(PROFILE)" \ $(CARGO_INSTALL_EXTRA_FLAGS) .PHONY: build build: ## Build the reth binary into `target` directory. cargo build --bin reth-hl --features "$(FEATURES)" --profile "$(PROFILE)" # Environment variables for reproducible builds # Initialize RUSTFLAGS RUST_BUILD_FLAGS = # Enable static linking to ensure reproducibility across builds RUST_BUILD_FLAGS += --C target-feature=+crt-static # Set the linker to use static libgcc to ensure reproducibility across builds RUST_BUILD_FLAGS += -C link-arg=-static-libgcc # Remove build ID from the binary to ensure reproducibility across builds RUST_BUILD_FLAGS += -C link-arg=-Wl,--build-id=none # Remove metadata hash from symbol names to ensure reproducible builds RUST_BUILD_FLAGS += -C metadata='' # Set timestamp from last git commit for reproducible builds SOURCE_DATE ?= $(shell git log -1 --pretty=%ct) # Disable incremental compilation to avoid non-deterministic artifacts CARGO_INCREMENTAL_VAL = 0 # Set C locale for consistent string handling and sorting LOCALE_VAL = C # Set UTC timezone for consistent time handling across builds TZ_VAL = UTC .PHONY: build-reproducible build-reproducible: ## Build the reth binary into `target` directory with reproducible builds. Only works for x86_64-unknown-linux-gnu currently SOURCE_DATE_EPOCH=$(SOURCE_DATE) \ RUSTFLAGS="${RUST_BUILD_FLAGS} --remap-path-prefix $$(pwd)=." \ CARGO_INCREMENTAL=${CARGO_INCREMENTAL_VAL} \ LC_ALL=${LOCALE_VAL} \ TZ=${TZ_VAL} \ cargo build --bin reth-hl --features "$(FEATURES)" --profile "release" --locked --target x86_64-unknown-linux-gnu .PHONY: build-debug build-debug: ## Build the reth binary into `target/debug` directory. cargo build --bin reth-hl --features "$(FEATURES)" # Builds the reth binary natively. build-native-%: cargo build --bin reth-hl --target $* --features "$(FEATURES)" --profile "$(PROFILE)" ##@ Test UNIT_TEST_ARGS := --locked --workspace --features 'jemalloc-prof' -E 'kind(lib)' -E 'kind(bin)' -E 'kind(proc-macro)' COV_FILE := lcov.info .PHONY: test-unit test-unit: ## Run unit tests. cargo install cargo-nextest --locked cargo nextest run $(UNIT_TEST_ARGS) .PHONY: cov-unit cov-unit: ## Run unit tests with coverage. rm -f $(COV_FILE) cargo llvm-cov nextest --lcov --output-path $(COV_FILE) $(UNIT_TEST_ARGS) .PHONY: cov-report-html cov-report-html: cov-unit ## Generate a HTML coverage report and open it in the browser. cargo llvm-cov report --html open target/llvm-cov/html/index.html ##@ Other .PHONY: clean clean: ## Perform a `cargo` clean and remove the binary and test vectors directories. cargo clean rm -rf $(BIN_DIR) .PHONY: profiling profiling: ## Builds `reth` with optimisations, but also symbols. RUSTFLAGS="-C target-cpu=native" cargo build --profile profiling --features jemalloc,asm-keccak .PHONY: maxperf maxperf: ## Builds `reth` with the most aggressive optimisations. RUSTFLAGS="-C target-cpu=native" cargo build --profile maxperf --features jemalloc,asm-keccak .PHONY: maxperf-no-asm maxperf-no-asm: ## Builds `reth` with the most aggressive optimisations, minus the "asm-keccak" feature. RUSTFLAGS="-C target-cpu=native" cargo build --profile maxperf --features jemalloc fmt: cargo +nightly fmt clippy: cargo +nightly clippy \ --workspace \ --lib \ --examples \ --tests \ --benches \ --all-features \ -- -D warnings lint-codespell: ensure-codespell codespell --skip "*.json" ensure-codespell: @if ! command -v codespell &> /dev/null; then \ echo "codespell not found. Please install it by running the command `pip install codespell` or refer to the following link for more information: https://github.com/codespell-project/codespell" \ exit 1; \ fi # Lint and format all TOML files in the project using dprint. # This target ensures that TOML files follow consistent formatting rules, # such as using spaces instead of tabs, and enforces other style guidelines # defined in the dprint configuration file (e.g., dprint.json). # # Usage: # make lint-toml # # Dependencies: # - ensure-dprint: Ensures that dprint is installed and available in the system. lint-toml: ensure-dprint dprint fmt ensure-dprint: @if ! command -v dprint &> /dev/null; then \ echo "dprint not found. Please install it by running the command `cargo install --locked dprint` or refer to the following link for more information: https://github.com/dprint/dprint" \ exit 1; \ fi lint: make fmt && \ make clippy && \ make lint-codespell && \ make lint-toml clippy-fix: cargo +nightly clippy \ --workspace \ --lib \ --examples \ --tests \ --benches \ --all-features \ --fix \ --allow-staged \ --allow-dirty \ -- -D warnings fix-lint: make clippy-fix && \ make fmt .PHONY: rustdocs rustdocs: ## Runs `cargo docs` to generate the Rust documents in the `target/doc` directory RUSTDOCFLAGS="\ --cfg docsrs \ --show-type-layout \ --generate-link-to-definition \ --enable-index-page -Zunstable-options -D warnings" \ cargo +nightly docs \ --document-private-items test-doc: cargo test --doc --workspace --all-features test: make cargo-test && \ make test-doc pr: make lint && \ make update-book-cli && \ cargo docs --document-private-items && \ make test check-features: cargo hack check \ --package reth-codecs \ --package reth-primitives-traits \ --package reth-primitives \ --feature-powerset ##@ Docker # Note: This requires a buildx builder with emulation support. For example: # # `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64` # `docker buildx create --use --driver docker-container --name cross-builder` .PHONY: docker-build-push docker-build-push: ## Build and push a cross-arch Docker image tagged with the latest git tag. $(call docker_build_push,$(GIT_TAG),$(GIT_TAG)) # Note: This requires a buildx builder with emulation support. For example: # # `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64` # `docker buildx create --use --driver docker-container --name cross-builder` .PHONY: docker-build-push-git-sha docker-build-push-git-sha: ## Build and push a cross-arch Docker image tagged with the latest git sha. $(call docker_build_push,$(GIT_SHA),$(GIT_SHA)) # Note: This requires a buildx builder with emulation support. For example: # # `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64` # `docker buildx create --use --driver docker-container --name cross-builder` .PHONY: docker-build-push-latest docker-build-push-latest: ## Build and push a cross-arch Docker image tagged with the latest git tag and `latest`. $(call docker_build_push,$(GIT_TAG),latest) # Note: This requires a buildx builder with emulation support. For example: # # `docker run --privileged --rm tonistiigi/binfmt --install amd64,arm64` # `docker buildx create --use --name cross-builder` .PHONY: docker-build-push-nightly docker-build-push-nightly: ## Build and push cross-arch Docker image tagged with the latest git tag with a `-nightly` suffix, and `latest-nightly`. $(call docker_build_push,nightly,nightly) # Create a Docker image using the main Dockerfile define docker_build_push docker buildx build --file ./Dockerfile . \ --platform linux/amd64 \ --tag $(DOCKER_IMAGE_NAME):$(1) \ --tag $(DOCKER_IMAGE_NAME):$(2) \ --build-arg BUILD_PROFILE="$(PROFILE)" \ --build-arg FEATURES="jemalloc,asm-keccak" \ --provenance=false \ --push endef