-
Notifications
You must be signed in to change notification settings - Fork 225
/
Makefile
238 lines (182 loc) · 8.1 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
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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# This supports environments where $HOME/.cargo/env has not been sourced (CI, CLion Makefile runner)
CARGO = $(or $(shell which cargo), $(HOME)/.cargo/bin/cargo)
RUSTUP = $(or $(shell which rustup), $(HOME)/.cargo/bin/rustup)
NPM = $(or $(shell which npm), /usr/bin/npm)
PINNED_NIGHTLY := $(shell cat smart_contracts/rust-toolchain)
PINNED_STABLE := $(shell sed -nr 's/channel *= *\"(.*)\"/\1/p' rust-toolchain.toml)
WASM_STRIP_VERSION := $(shell wasm-strip --version)
CARGO_OPTS := --locked
CARGO_PINNED_NIGHTLY := $(CARGO) +$(PINNED_NIGHTLY) $(CARGO_OPTS)
CARGO := $(CARGO) $(CARGO_OPTS)
DISABLE_LOGGING = RUST_LOG=MatchesNothing
# Rust Contracts
ALL_CONTRACTS = $(shell find ./smart_contracts/contracts/[!.]* -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
CLIENT_CONTRACTS = $(shell find ./smart_contracts/contracts/client -mindepth 1 -maxdepth 1 -type d -exec basename {} \;)
CARGO_HOME_REMAP = $(if $(CARGO_HOME),$(CARGO_HOME),$(HOME)/.cargo)
RUSTC_FLAGS = "--remap-path-prefix=$(CARGO_HOME_REMAP)=/home/cargo --remap-path-prefix=$$PWD=/dir"
# AssemblyScript Contracts
CLIENT_CONTRACTS_AS = $(shell find ./smart_contracts/contracts_as/client -mindepth 1 -maxdepth 1 -type d)
TEST_CONTRACTS_AS = $(shell find ./smart_contracts/contracts_as/test -mindepth 1 -maxdepth 1 -type d)
EXAMPLE_CONTRACTS_AS = $(shell find ./smart_contracts/contracts_as/example -mindepth 1 -maxdepth 1 -type d)
CLIENT_CONTRACTS_AS := $(patsubst %, build-contract-as/%, $(CLIENT_CONTRACTS_AS))
TEST_CONTRACTS_AS := $(patsubst %, build-contract-as/%, $(TEST_CONTRACTS_AS))
EXAMPLE_CONTRACTS_AS := $(patsubst %, build-contract-as/%, $(EXAMPLE_CONTRACTS_AS))
CONTRACT_TARGET_DIR = target/wasm32-unknown-unknown/release
CONTRACT_TARGET_DIR_AS = target_as
build-contract-rs/%:
cd smart_contracts/contracts && RUSTFLAGS=$(RUSTC_FLAGS) $(CARGO) build --verbose --release $(filter-out --release, $(CARGO_FLAGS)) --package $*
.PHONY: build-all-contracts-rs
build-all-contracts-rs: $(patsubst %, build-contract-rs/%, $(ALL_CONTRACTS))
.PHONY: build-client-contracts-rs
build-client-contracts-rs: $(patsubst %, build-contract-rs/%, $(CLIENT_CONTRACTS))
strip-contract/%:
wasm-strip $(CONTRACT_TARGET_DIR)/$(subst -,_,$*).wasm 2>/dev/null | true
.PHONY: strip-all-contracts
strip-all-contracts: $(info Using 'wasm-strip' version $(WASM_STRIP_VERSION)) $(patsubst %, strip-contract/%, $(ALL_CONTRACTS))
.PHONY: strip-client-contracts
strip-client-contracts: $(patsubst %, strip-contract/%, $(CLIENT_CONTRACTS))
.PHONY: build-contracts-rs
build-contracts-rs: build-all-contracts-rs strip-all-contracts
.PHONY: build-client-contracts
build-client-contracts: build-client-contracts-rs strip-client-contracts
build-contract-as/%:
cd $* && $(NPM) run asbuild
.PHONY: build-contracts-as
build-contracts-as: \
$(CLIENT_CONTRACTS_AS) \
$(TEST_CONTRACTS_AS) \
$(EXAMPLE_CONTRACTS_AS)
.PHONY: build-contracts
build-contracts: build-contracts-rs build-contracts-as
resources/local/chainspec.toml: generate-chainspec.sh resources/local/chainspec.toml.in
@./$<
.PHONY: test-rs
test-rs: resources/local/chainspec.toml build-contracts-rs
$(LEGACY) $(DISABLE_LOGGING) $(CARGO) test --all-features --no-fail-fast $(CARGO_FLAGS) -- --nocapture
.PHONY: resources/local/chainspec.toml
test-rs-no-default-features:
cd smart_contracts/contract && $(DISABLE_LOGGING) $(CARGO) test $(CARGO_FLAGS) --no-default-features --features=version-sync
.PHONY: test-as
test-as: setup-as
cd smart_contracts/contract_as && npm run asbuild && npm run test
.PHONY: test
test: test-rs-no-default-features test-rs test-as
.PHONY: test-contracts-rs
test-contracts-rs: build-contracts-rs
$(DISABLE_LOGGING) $(CARGO) test $(CARGO_FLAGS) -p casper-engine-tests -- --ignored --skip repeated_ffi_call_should_gas_out_quickly
.PHONY: test-contracts-timings
test-contracts-timings: build-contracts-rs
$(DISABLE_LOGGING) $(CARGO) test --release $(filter-out --release, $(CARGO_FLAGS)) -p casper-engine-tests -- --ignored --test-threads=1 repeated_ffi_call_should_gas_out_quickly
.PHONY: test-contracts-as
test-contracts-as: build-contracts-rs build-contracts-as
@# see https://github.com/rust-lang/cargo/issues/5015#issuecomment-515544290
$(DISABLE_LOGGING) $(CARGO) test $(CARGO_FLAGS) --manifest-path "execution_engine_testing/tests/Cargo.toml" --features "use-as-wasm" -- --ignored
.PHONY: test-contracts
test-contracts: test-contracts-rs
.PHONY: check-no-default-features
check-no-default-features:
cd types && $(CARGO) check --all-targets --no-default-features
.PHONY: check-std-features
check-std-features:
cd types && $(CARGO) check --all-targets --no-default-features --features=std
cd types && $(CARGO) check --all-targets --features=std
cd smart_contracts/contract && $(CARGO) check --all-targets --no-default-features --features=std
cd smart_contracts/contract && $(CARGO) check --all-targets --features=std
check-std-fs-io-features:
cd types && $(CARGO) check --all-targets --features=std-fs-io
cd types && $(CARGO) check --lib --features=std-fs-io
check-testing-features:
cd types && $(CARGO) check --all-targets --no-default-features --features=testing
cd types && $(CARGO) check --all-targets --features=testing
.PHONY: check-format
check-format:
$(CARGO_PINNED_NIGHTLY) fmt --all -- --check
.PHONY: format
format:
$(CARGO_PINNED_NIGHTLY) fmt --all
lint-contracts-rs:
cd smart_contracts/contracts && $(CARGO) clippy $(patsubst %, -p %, $(ALL_CONTRACTS)) -- -D warnings -A renamed_and_removed_lints
.PHONY: lint
lint: lint-contracts-rs lint-default-features lint-all-features lint-smart-contracts lint-no-default-features
.PHONY: lint-default-features
lint-default-features:
$(CARGO) clippy --all-targets -- -D warnings
.PHONY: lint-no-default-features
lint-no-default-features:
$(CARGO) clippy --all-targets --no-default-features -- -D warnings
.PHONY: lint-all-features
lint-all-features:
$(CARGO) clippy --all-targets --all-features -- -D warnings
.PHONY: lint-smart-contracts
lint-smart-contracts:
cd smart_contracts/contract && $(CARGO) clippy --all-targets -- -D warnings -A renamed_and_removed_lints
.PHONY: audit-rs
audit-rs:
$(CARGO) audit --ignore RUSTSEC-2024-0344 --ignore RUSTSEC-2024-0367 --ignore RUSTSEC-2024-0371
.PHONY: audit-as
audit-as:
@# Runs a vulnerability scan that fails if there are prod vulnerabilities with a moderate level or above.
cd smart_contracts/contract_as && $(NPM) audit --production --audit-level=moderate
.PHONY: audit
audit: audit-rs
.PHONY: doc
doc:
RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--cfg docsrs" $(CARGO_PINNED_NIGHTLY) doc --all-features $(CARGO_FLAGS) --no-deps
cd smart_contracts/contract && RUSTFLAGS="-D warnings" RUSTDOCFLAGS="--cfg docsrs" $(CARGO_PINNED_NIGHTLY) doc --all-features $(CARGO_FLAGS) --no-deps
.PHONY: check-rs
check-rs: \
check-format \
doc \
lint \
audit \
check-no-default-features \
check-std-features \
check-std-fs-io-features \
check-testing-features \
test-rs \
test-rs-no-default-features \
test-contracts-rs
.PHONY: check
check: \
check-rs \
test-as
.PHONY: clean
clean:
rm -rf resources/local/chainspec.toml
rm -rf $(CONTRACT_TARGET_DIR_AS)
$(CARGO) clean
.PHONY: build-for-packaging
build-for-packaging: build-client-contracts
$(LEGACY) $(CARGO) build --release
.PHONY: package
package:
cd contract && $(CARGO) package
.PHONY: publish
publish:
./publish.sh
.PHONY: bench
bench: build-contracts-rs
$(CARGO) bench
.PHONY: setup-cargo-packagers
setup-cargo-packagers:
$(CARGO) install cargo-rpm || exit 0
$(CARGO) install cargo-deb || exit 0
.PHONY: setup-audit
setup-audit:
cargo install cargo-audit
.PHONY: setup-rs
setup-rs: smart_contracts/rust-toolchain
$(RUSTUP) update
$(RUSTUP) toolchain install $(PINNED_STABLE) $(PINNED_NIGHTLY) $(NIGHTLY_FOR_DOC)
$(RUSTUP) target add --toolchain $(PINNED_STABLE) wasm32-unknown-unknown
$(RUSTUP) target add --toolchain $(PINNED_NIGHTLY) wasm32-unknown-unknown
.PHONY: setup-nightly-rs
setup-nightly-rs:
$(RUSTUP) update
$(RUSTUP) toolchain install nightly
$(RUSTUP) target add --toolchain nightly wasm32-unknown-unknown
.PHONY: setup-as
setup-as: smart_contracts/contract_as/package.json
cd smart_contracts/contract_as && $(NPM) ci
.PHONY: setup
setup: setup-rs