forked from ReamLabs/ream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
174 lines (137 loc) · 5.36 KB
/
Copy pathMakefile
File metadata and controls
174 lines (137 loc) · 5.36 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
# Heavily inspired by Reth: https://github.com/paradigmxyz/reth/blob/4c39b98b621c53524c6533a9c7b52fc42c25abd6/Makefile
.DEFAULT_GOAL := help
BIN_DIR = "dist/bin"
# Cargo features for builds.
FEATURES ?=
# Devnet feature selected for Shadow builds (devnet4/devnet5 are mutually
# exclusive, and `--no-default-features` drops the default `devnet4`).
SHADOW_DEVNET ?= devnet5
# Cargo profile for builds.
PROFILE ?= release
# Extra flags for Cargo.
CARGO_INSTALL_EXTRA_FLAGS ?=
CARGO_TARGET_DIR ?= target
IMAGE ?= ream-local
TAG ?= dev
##@ Help
.PHONY: help
help: # Display this help.
@awk 'BEGIN {FS = ":.*#"; printf "Usage:\n make \033[34m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?#/ { printf " \033[34m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) }' $(MAKEFILE_LIST)
##@ Build
.PHONY: build
build: # Build the Ream binary into `target` directory.
cargo build --bin ream --features "$(FEATURES)" --profile "$(PROFILE)"
.PHONY: build-debug
build-debug: # Build the Ream binary into `target/debug` directory
cargo build --bin ream --features "$(FEATURES)"
.PHONY: install
install: # Build and install the Ream binary under `~/.cargo/bin`.
cargo install --path bin/ream --force --locked \
--features "$(FEATURES)" \
--profile "$(PROFILE)" \
$(CARGO_INSTALL_EXTRA_FLAGS)
##@ Testing and Linting
.PHONY: test
test: test-devnet5
.PHONY: test-devnet5
test-devnet5:
cargo test --workspace --no-default-features --features "devnet5" -- --nocapture
.PHONY: test-ef
test-ef: # Download test vectors and run the EF spec tests.
$(MAKE) -C testing/ef-tests test
.PHONY: clean-ef
clean-ef: # Clean up downloaded EF test vectors.
$(MAKE) -C testing/ef-tests clean
.PHONY: fmt
fmt: # Run `rustfmt` on the entire workspace and enfore closure variables on `map_err` to be `err`
cargo +nightly fmt --all
@all_occurrences=$$(grep -RIn --exclude-dir=./target --include="*.rs" "\.map_err(|" . || true); \
violations=$$(echo "$$all_occurrences" | grep -Ev "\.map_err\(\|err\|" || true); \
if [ -n "$$violations" ]; then \
echo "Invalid .map_err closure naming found:"; \
echo "$$violations"; \
echo; \
echo "Only this form is allowed:"; \
echo " .map_err(|err| ... )"; \
exit 1; \
fi
@# ---- Err(err) naming check ----
@all_errs=$$(grep -RIn --exclude-dir=./target --include="*.rs" "Err(" . || true); \
violations_err=$$(echo "$$all_errs" | grep -E "Err\(\s*[a-z][a-zA-Z0-9_]*\s*\)" | grep -Ev "Err\(err\)" || true); \
if [ -n "$$violations_err" ]; then \
echo "Invalid Err variable naming found:"; \
echo "$$violations_err"; \
echo; \
echo "Only this form is allowed:"; \
echo " Err(err)"; \
exit 1; \
fi
.PHONY: clippy
clippy: # Run `clippy` on the entire workspace.
cargo clippy --all --all-targets --features "$(FEATURES)" --no-deps -- --deny warnings
cargo clippy --package ream-bls --all-targets --features "supranational" --no-deps -- --deny warnings
.PHONY: clippy-devnet5
clippy-devnet5:
cargo clippy --workspace --all-targets --no-default-features --features "devnet5" --no-deps -- --deny warnings
.PHONY: sort
sort: # Run `cargo sort` on the entire workspace.
cargo sort --grouped --workspace
.PHONY: lint
lint: fmt clippy sort # Run all linters.
##@ Others
.PHONY: check
check: # Run `cargo check`.
cargo check --workspace --features "$(FEATURES)"
.PHONY: clean
clean: # Run `cargo clean`.
cargo clean
.PHONY: update-book-cli
update-book-cli: build-debug # Update book cli documentation.
@echo "Updating book cli doc..."
@./book/cli/update.sh $(CARGO_TARGET_DIR)/debug/ream
.PHONY: clean-deps
clean-deps: # Run `cargo udeps` except `ef-tests` directory.
cargo +nightly udeps --workspace --tests --all-targets --release --exclude ef-tests
.PHONY: pr
pr: lint update-book-cli clean-deps test # Run all checks for a PR.
build-%:
cross build --bin ream --target $* --features "$(FEATURES)" --profile "$(PROFILE)" $(EXTRA_FLAGS)
##@ Shadow simulator
.PHONY: shadow-build
shadow-build: # Shadow-compatible binary (single-threaded, no jemalloc, quinn-udp patch).
./shadow/build.sh cargo build --profile "$(PROFILE)" \
--no-default-features --features "shadow-integration $(SHADOW_DEVNET)" --bin ream
.PHONY: shadow-docker-build
shadow-docker-build: # Build a Shadow-compatible Docker image, tagged ...:latest-shadow.
docker build --file ./Dockerfile . \
--build-arg SHADOW=1 \
--build-arg NO_DEFAULT_FEATURES=--no-default-features \
--build-arg FEATURES="shadow-integration $(SHADOW_DEVNET)" \
--build-arg LOCKED= \
--build-arg BUILD_PROFILE=$(PROFILE) \
--tag ghcr.io/reamlabs/ream:latest-shadow
.PHONY: docker-build-push
docker-build-push:
$(MAKE) build-x86_64-unknown-linux-gnu
mkdir -p $(BIN_DIR)/amd64
cp $(CARGO_TARGET_DIR)/x86_64-unknown-linux-gnu/$(PROFILE)/ream $(BIN_DIR)/amd64/ream
$(MAKE) build-aarch64-unknown-linux-gnu
mkdir -p $(BIN_DIR)/arm64
cp $(CARGO_TARGET_DIR)/aarch64-unknown-linux-gnu/$(PROFILE)/ream $(BIN_DIR)/arm64/ream
docker buildx build --file ./Dockerfile.cross . \
--platform linux/amd64,linux/arm64 \
--tag ghcr.io/reamlabs/ream:latest \
--tag ghcr.io/reamlabs/ream:latest-devnet5 \
--build-arg GIT_COMMIT=$(GIT_COMMIT) \
--build-arg GIT_BRANCH=$(GIT_BRANCH) \
--build-arg BUILD_DATE=$(BUILD_DATE) \
--provenance=false \
--push
.PHONY: docker-local
docker-local:
docker build \
-f Dockerfile \
--build-arg BUILD_PROFILE=release \
--build-arg FEATURES="$(FEATURES)" \
-t $(IMAGE):$(TAG) \
.