-
Notifications
You must be signed in to change notification settings - Fork 134
/
Copy pathMakefile
149 lines (122 loc) · 5.21 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# Heavily inspired by Lighthouse: https://github.com/sigp/lighthouse/blob/693886b94176faa4cb450f024696cb69cda2fe58/Makefile
.DEFAULT_GOAL := help
GIT_TAG ?= $(shell git describe --tags --abbrev=0)
BIN_DIR = "dist/bin"
BUILD_PATH = "target"
# List of features to use when building. Can be override via the environment.
FEATURES ?=
# Cargo profile for builds. Default is for local builds, CI uses an override.
PROFILE ?= release
# Extra flags for Cargo
CARGO_INSTALL_EXTRA_FLAGS ?=
.PHONY: lint
lint: ## Run clippy and rustfmt
cargo +nightly fmt --all
cargo clippy --all --all-targets --all-features --no-deps -- --deny warnings
.PHONY: lint-unstable
lint-unstable: ## run clippy, rustfmt and rustc lints with unstable features. expect errors, which cannot be resolved, so the user must step through and evaluate each one manually.
cargo +nightly fmt --all
cargo clippy --all --all-targets --all-features --no-deps -- -Wclippy::cargo
RUSTFLAGS="-W unused_crate_dependencies" cargo build
#@ 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 trin binary under `~/.cargo/bin`.
cargo install --path bin/trin --bin trin --force --locked \
--features "$(FEATURES)" \
--profile "$(PROFILE)" \
$(CARGO_INSTALL_EXTRA_FLAGS)
# Builds the trin binary natively.
build-native-%:
cargo build --bin trin --target $* --features "$(FEATURES)" --profile "$(PROFILE)"
# The following commands use `cross` to build a cross-compile.
#
# These commands require that:
#
# - `cross` is installed (`cargo install cross`).
# - Docker is running.
# - The current user is in the `docker` group.
#
# The resulting binaries will be created in the `target/` directory.
# No jemalloc on Windows
build-x86_64-pc-windows-gnu: FEATURES := $(filter-out jemalloc jemalloc-prof,$(FEATURES))
# Note: The additional rustc compiler flags are for intrinsics needed by MDBX.
# See: https://github.com/cross-rs/cross/wiki/FAQ#undefined-reference-with-build-std
build-%:
RUSTFLAGS="" \
cross build --bin trin --target $* --features "$(FEATURES)" --profile "$(PROFILE)"
# Unfortunately we can't easily use cross to build for Darwin because of licensing issues.
# If we wanted to, we would need to build a custom Docker image with the SDK available.
#
# Note: You must set `SDKROOT` and `MACOSX_DEPLOYMENT_TARGET`. These can be found using `xcrun`.
#
# `SDKROOT=$(xcrun -sdk macosx --show-sdk-path) MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx --show-sdk-platform-version)`
build-x86_64-apple-darwin:
$(MAKE) build-native-x86_64-apple-darwin
build-aarch64-apple-darwin:
$(MAKE) build-native-aarch64-apple-darwin
# Create a `.tar.gz` containing a binary for a specific target.
define tarball_release_binary
cp $(BUILD_PATH)/$(1)/$(PROFILE)/$(2) $(BIN_DIR)/$(2)
cd $(BIN_DIR) && \
tar -czf trin-$(GIT_TAG)-$(1)$(3).tar.gz $(2) && \
rm $(2)
endef
# The current git tag will be used as the version in the output file names. You
# will likely need to use `git tag` and create a semver tag (e.g., `v0.2.3`).
#
# Note: This excludes macOS tarballs because of SDK licensing issues.
.PHONY: build-release-tarballs
build-release-tarballs: ## Create a series of `.tar.gz` files in the BIN_DIR directory, each containing a `trin` binary for a different target.
[ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR)
$(MAKE) build-x86_64-unknown-linux-gnu
$(call tarball_release_binary,"x86_64-unknown-linux-gnu","trin","")
$(MAKE) build-aarch64-unknown-linux-gnu
$(call tarball_release_binary,"aarch64-unknown-linux-gnu","trin","")
$(MAKE) build-x86_64-pc-windows-gnu
$(call tarball_release_binary,"x86_64-pc-windows-gnu","trin.exe","")
##@ Tests
EF_TESTS_TARGET = mainnet.tar.gz
EF_TESTS_DIR = ./testing/ef-tests/mainnet
LATEST_RELEASE_URL = https://api.github.com/repos/ethereum/consensus-spec-tests/releases/latest
download_test_data:
@if [ -d $(EF_TESTS_DIR) ]; then \
echo "$(EF_TESTS_DIR) already downloaded. Skipping download."; \
else \
echo "Fetching the latest release URL for $(EF_TESTS_TARGET)..."; \
curl -s $(LATEST_RELEASE_URL) \
| grep "browser_download_url.*$(EF_TESTS_TARGET)" \
| cut -d : -f 2,3 \
| tr -d \" \
| wget -qi -; \
echo "$(EF_TESTS_TARGET) downloaded successfully."; \
fi
extract_test_data: download_test_data
@if [ -d $(EF_TESTS_DIR) ]; then \
echo "$(EF_TESTS_DIR) already exists. Skipping extraction."; \
else \
echo "Extracting $(EF_TESTS_TARGET) into $(EF_TESTS_DIR)..."; \
mkdir -p $(EF_TESTS_DIR); \
tar -xzf $(EF_TESTS_TARGET) -C $(EF_TESTS_DIR); \
rm -f $(EF_TESTS_TARGET); \
echo "Extraction complete."; \
fi
.PHONY: ef-tests
ef-tests: extract_test_data ## Runs Ethereum Foundation tests.
@echo "Running tests..."
@cargo test -p ef-tests --features ef-tests
@echo "Tests complete."
.PHONY: test
test: ## Runs workspace tests.
cargo test --workspace -- --nocapture
.PHONY: test-full
test-full: test ef-tests ## Runs all tests.
##@ Other
.PHONY: clean
clean: ## Perform a `cargo` clean and remove the binary and test vectors directories.
cargo clean
rm -rf $(BIN_DIR)
rm -rf $(EF_TESTS_DIR)