mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 02:49:55 +00:00
chore: Add Makefile from reth and features used by Makefile
This commit is contained in:
209
Makefile
Normal file
209
Makefile
Normal file
@ -0,0 +1,209 @@
|
||||
# Modifed from reth Makefile
|
||||
.DEFAULT_GOAL := help
|
||||
|
||||
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 ?=
|
||||
|
||||
##@ Help
|
||||
|
||||
.PHONY: help
|
||||
help: ## Display this help.
|
||||
@awk 'BEGIN {FS = ":.*##"; printf "Usage:\n make \033[36m<target>\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
|
||||
Reference in New Issue
Block a user