-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathMakefile
More file actions
86 lines (71 loc) · 2.77 KB
/
Makefile
File metadata and controls
86 lines (71 loc) · 2.77 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
# Variables
PINNED_TOOLCHAIN := $(shell cat rust-toolchain)
WASM_TARGET_DIR := ./target/wasm32-unknown-unknown/release
WASM_OUTPUT_DIR := tests/wasm
RUSTFLAGS := -C target-cpu=mvp
CARGO_BUILD_FLAGS := -Z build-std=std,panic_abort
# List of session and contract crates
SESSION_CRATES := balance_of_session get_approved_session is_approved_for_all_session \
mint_session owner_of_session transfer_session updated_receipts
CONTRACT_CRATES := mangle_named_keys minting_contract transfer_filter_contract
ALL_CRATES := cep78 $(SESSION_CRATES) $(CONTRACT_CRATES)
VERSIONS :=
# Helper macros
define build_and_strip
RUSTFLAGS="$(RUSTFLAGS)" cargo +$(PINNED_TOOLCHAIN) build --release --target wasm32-unknown-unknown $(CARGO_BUILD_FLAGS) -p $1 ;
wasm-strip $(WASM_TARGET_DIR)/$1.wasm ;
endef
# Targets
prepare:
rustup install $(PINNED_TOOLCHAIN)
rustup target add wasm32-unknown-unknown
rustup component add clippy --toolchain $(PINNED_TOOLCHAIN)
rustup component add rustfmt --toolchain $(PINNED_TOOLCHAIN)
rustup component add rust-src --toolchain $(PINNED_TOOLCHAIN)
.PHONY: build-contract
build-contract:
$(call build_and_strip,cep78)
.PHONY: build-all-contracts
build-all-contracts: build-contract
$(foreach crate, $(SESSION_CRATES), $(call build_and_strip,$(crate)))
$(foreach crate, $(CONTRACT_CRATES), $(call build_and_strip,$(crate)))
.PHONY: setup-test
setup-test: build-all-contracts
mkdir -p $(WASM_OUTPUT_DIR)
$(foreach version,$(VERSIONS), \
if [ ! -d "tests/wasm/$(version)" ]; then \
mkdir -p tests/wasm/$(version); \
curl -L https://github.com/casper-ecosystem/cep-78-enhanced-nft/releases/download/v$(subst _,.,$(version))/cep-78-wasm.tar.gz | tar zxv -C tests/wasm/$(version)/; \
fi; \
)
cp $(WASM_TARGET_DIR)/*.wasm $(WASM_OUTPUT_DIR)
.PHONY: test
test: setup-test
cargo test -p tests --lib
.PHONY: clippy
clippy:
cargo +$(PINNED_TOOLCHAIN) clippy --release -p cep78 --lib --target wasm32-unknown-unknown $(CARGO_BUILD_FLAGS) -- -D warnings
$(foreach crate, $(ALL_CRATES), \
cargo +$(PINNED_TOOLCHAIN) clippy --release -p $(crate) --bins --target wasm32-unknown-unknown $(CARGO_BUILD_FLAGS) -- -D warnings; \
)
cargo +stable clippy -p tests --all-targets -- -D warnings
.PHONY: check-lint
check-lint: clippy
$(foreach crate, $(ALL_CRATES), cargo +$(PINNED_TOOLCHAIN) fmt -p $(crate) -- --check;)
cargo +stable fmt -p tests -- --check
.PHONY: lint
lint: clippy format
.PHONY: format
format:
$(foreach crate, $(ALL_CRATES), cargo +$(PINNED_TOOLCHAIN) fmt -p $(crate);)
cargo +stable fmt -p tests
.PHONY: clean
clean:
$(foreach crate, $(ALL_CRATES), cargo clean -p $(crate);)
cargo clean -p tests
rm -rf $(WASM_OUTPUT_DIR)
rm -rf ./Cargo.lock
.PHONY: cargo-update
cargo-update:
$(foreach crate, $(ALL_CRATES), cargo update -p $(crate);)
cargo update -p tests