-
Notifications
You must be signed in to change notification settings - Fork 22
feat:cargo check features #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
1c3f812
1d4a95b
44a050f
5511d95
a12ef5d
fcc452c
4fc64d1
5638b48
0a02ec5
9fc3ee1
b11ae64
6e13692
7a98695
426de9f
4e9530e
cab4e5b
80741fa
3e88230
f2d96ff
26c2810
81487e9
e23f5f8
e5100e0
bba177b
1255ed7
a0ab7d4
65049c1
7836430
ca04e05
f4379ec
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,97 @@ DEFUSE_OUT_DIR ?= $(ROOT_DIR)res | |
| MAKE_OUT_DIR_PREFIX ?= $(ROOT_DIR)target/makenear | ||
| MAKE_OUT_DIR = $(eval MAKE_OUT_DIR := $(shell mkdir -p $(MAKE_OUT_DIR_PREFIX) $(DEFUSE_OUT_DIR) && mktemp -d -p $(MAKE_OUT_DIR_PREFIX)))$(MAKE_OUT_DIR) | ||
|
|
||
| .PHONY: help | ||
| help: | ||
| @echo "Usage: make [target] [REPRODUCIBLE=1]" | ||
| @echo "" | ||
| @echo "Build targets (use REPRODUCIBLE=1 for reproducible builds):" | ||
| @$(foreach t,$(ALL_TARGETS),echo " $(t)";) | ||
| @echo "" | ||
| @echo "Other targets:" | ||
| @echo " all Build all contracts (default)" | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we're touching this already and we're going to have outlayer contracts and services, maybe it makes sense to introduce |
||
| @echo " clean Remove build artifacts and cargo clean" | ||
| @echo " test Run all workspace tests" | ||
| @echo " check Run clippy on codebase (codebase + per-contract wasm)" | ||
| @echo " check-all Run all checks" | ||
| @echo " fmt Format Rust files and Cargo.toml manifests" | ||
| @echo " help Show this help" | ||
|
|
||
| .PHONY: clean-out-dir | ||
| clean-out-dir: | ||
| rm -rf $(DEFUSE_OUT_DIR) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. side note: what if |
||
|
|
||
| .PHONY: clean | ||
| clean: clean-out-dir | ||
| cargo clean | ||
|
|
||
| .PHONY: test | ||
| test: | ||
| cargo test --workspace --all-targets | ||
|
|
||
| .PHONY: check | ||
| check: check-contracts | ||
| cargo clippy --workspace --all-targets --no-deps | ||
|
|
||
| .PHONY: check-contracts | ||
|
|
||
| .PHONY: check-fmt | ||
| check-fmt: | ||
| cargo fmt --all --check | ||
| RUST_LOG=warn taplo format --check | ||
|
|
||
| .PHONY: check-unused-deps | ||
| check-unused-deps: | ||
| cargo machete 2>/dev/null | ||
|
|
||
| .PHONY: check-examples | ||
| check-examples: | ||
| RUSTFLAGS='$(RUSTFLAGS_CHECK)' cargo clippy --workspace --examples | ||
|
|
||
| .PHONY: check-all | ||
| check-all: check-fmt check-unused-deps check check-examples check-all-features | ||
|
|
||
| .PHONY: fmt | ||
| fmt: | ||
| cargo fmt --all | ||
| taplo format | ||
|
|
||
| RUSTFLAGS_CHECK = -D warnings | ||
| # --cfg clippy: cargo clippy only sets cfg(clippy) for workspace crates, not dependencies. | ||
| # near-sdk compile_error!s on host unless one of its allowed cfgs is set, so we must set it via RUSTFLAGS. | ||
| # --include-features near-sdk/non-contract-usage would be cleaner, but cargo-hack's | ||
| # --ignore-unknown-features is not implemented for --include-features, so it fails | ||
| # on crates that don't depend on near-sdk. | ||
| CARGO_CHECK_HOST = RUSTFLAGS='$(RUSTFLAGS_CHECK) --cfg clippy' cargo hack clippy --exclude-features contract | ||
| CARGO_CHECK_WASM = RUSTFLAGS='$(RUSTFLAGS_CHECK)' cargo hack clippy --target wasm32-unknown-unknown --exclude-features abi --exclude-features near-api-types --exclude-features near-api --no-dev-deps | ||
|
|
||
| # Crates where every enum variant is feature-gated, requiring at least one | ||
| # variant feature. These need --feature-powerset + --at-least-one-of instead | ||
| # of --each-feature (which tests features in isolation). | ||
| # Format: crate=feature1,feature2,... | ||
| CRATES_AT_LEAST_ONE_VARIANT := \ | ||
| defuse-token-id=nep141,nep171,nep245,imt \ | ||
| defuse-ton-connect=text,binary,cell \ | ||
| defuse-escrow-swap=nep141,nep245 | ||
|
|
||
| # Testing crates that cannot compile for wasm32-unknown-unknown. | ||
| # defuse-randomness uses rand/getrandom which lacks wasm32 support; | ||
| # it only reaches the defuse contract via dev-dependencies, never in the WASM binary. | ||
| # defuse-wallet-sdk uses getrandom (via rand) without a wasm backend feature. | ||
| CRATES_HOST_ONLY := \ | ||
| defuse-test-utils \ | ||
| defuse-sandbox \ | ||
| defuse-randomness \ | ||
| defuse-tests \ | ||
| defuse-wallet-relayer \ | ||
| defuse-wallet-sdk | ||
|
|
||
| # Crates excluded from check-all-features-host (still covered by `make check`). | ||
| # defuse-wallet-relayer: aws-lc-sys build script breaks with --cfg clippy in RUSTFLAGS. | ||
| CRATES_SKIP_HOST_FEATURES := \ | ||
| defuse-wallet-relayer | ||
|
|
||
|
|
||
| .DEFAULT_GOAL := all | ||
| CONTRACT_CRATES := \ | ||
| defuse \ | ||
|
|
@@ -16,6 +107,9 @@ CONTRACT_CRATES := \ | |
|
|
||
| ALL_TARGETS := | ||
|
|
||
| crate_name = $(firstword $(subst =, ,$1)) | ||
| crate_features = $(lastword $(subst =, ,$1)) | ||
|
|
||
| # Generate all build targets from cargo metadata, filtered to CONTRACT_CRATES | ||
| $(eval $(shell cargo metadata --format-version=1 | jq -rn \ | ||
| --arg outdir '$(DEFUSE_OUT_DIR)' --arg reproducible '$(REPRODUCIBLE)' --arg makedir '$$$$(MAKE_OUT_DIR)' \ | ||
|
|
@@ -36,6 +130,10 @@ $(eval $(shell cargo metadata --format-version=1 | jq -rn \ | |
| ($$vval.container_build_command | join(" ")) as $$non_reproducible_cmd | \ | ||
| (if $$reproducible != "" then $$reproducible_cmd else $$non_reproducible_cmd end) as $$cmd | \ | ||
| (if $$vkey == "" then "" else ".\($$vkey)" end) as $$suffix | \ | ||
| ($$vval.container_build_command | map(select(startswith("--features="))) | if length > 0 then " " + first else "" end) as $$features_flag | \ | ||
| "$$(eval .PHONY: check-contract/\($$tname))", \ | ||
| "$$(eval check-contracts:: check-contract/\($$tname))", \ | ||
| "$$(eval check-contract/\($$tname):; cargo clippy -p \($$name) --no-deps --target wasm32-unknown-unknown\($$features_flag))", \ | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also add |
||
| "$$(eval .PHONY: \($$tname))", \ | ||
| "$$(eval ALL_TARGETS += \($$tname))", \ | ||
| "$$(eval \($$name)/all:: \($$tname))", \ | ||
|
|
@@ -47,51 +145,25 @@ $(eval $(shell cargo metadata --format-version=1 | jq -rn \ | |
| .PHONY: all | ||
| all: $(ALL_TARGETS) | ||
|
|
||
| .PHONY: help | ||
| help: | ||
| @echo "Usage: make [target] [REPRODUCIBLE=1]" | ||
| @echo "" | ||
| @echo "Build targets (use REPRODUCIBLE=1 for reproducible builds):" | ||
| @$(foreach t,$(ALL_TARGETS),echo " $(t)";) | ||
| @echo "" | ||
| @echo "Other targets:" | ||
| @echo " all Build all contracts (default)" | ||
| @echo " clean Remove build artifacts and cargo clean" | ||
| @echo " clean-out-dir Remove output directory only" | ||
| @echo " test Run all workspace tests" | ||
| @echo " clippy Run clippy lints" | ||
| @echo " fmt Format Rust files and Cargo.toml manifests" | ||
| @echo " help Show this help" | ||
| .PHONY: check-all-features-host | ||
| check-all-features-host:: | ||
| $(CARGO_CHECK_HOST) --workspace --each-feature --exclude-no-default-features \ | ||
| $(foreach c,$(CRATES_AT_LEAST_ONE_VARIANT),--exclude $(call crate_name,$c)) \ | ||
| $(addprefix --exclude ,$(CRATES_SKIP_HOST_FEATURES)) | ||
|
|
||
| .PHONY: clean-out-dir | ||
| clean-out-dir: | ||
| rm -rf $(DEFUSE_OUT_DIR) | ||
| $(foreach c,$(CRATES_AT_LEAST_ONE_VARIANT),\ | ||
| $(eval check-all-features-host::; \ | ||
| $(CARGO_CHECK_HOST) -p $(call crate_name,$c) --feature-powerset --at-least-one-of $(call crate_features,$c))) | ||
|
|
||
| .PHONY: clean | ||
| clean: clean-out-dir | ||
| cargo clean | ||
| .PHONY: check-all-features-wasm | ||
| check-all-features-wasm:: | ||
| $(CARGO_CHECK_WASM) --workspace --each-feature --exclude-no-default-features \ | ||
| $(foreach c,$(CRATES_AT_LEAST_ONE_VARIANT),--exclude $(call crate_name,$c)) \ | ||
| $(addprefix --exclude ,$(CRATES_HOST_ONLY)) | ||
|
|
||
| .PHONY: test | ||
| test: | ||
| cargo test --workspace --all-targets | ||
|
|
||
| .PHONY: check | ||
| check: | ||
| cargo clippy --workspace --all-targets --no-deps | ||
|
|
||
| .PHONY: check-fmt | ||
| check-fmt: | ||
| cargo fmt --all --check | ||
| RUST_LOG=warn taplo format --check | ||
| $(foreach c,$(CRATES_AT_LEAST_ONE_VARIANT),\ | ||
| $(eval check-all-features-wasm::; \ | ||
| $(CARGO_CHECK_WASM) -p $(call crate_name,$c) --feature-powerset --at-least-one-of $(call crate_features,$c))) | ||
|
|
||
|
Comment on lines
+158
to
167
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In general, this PR tries to check every crate we have for WASM target with all supported feature combinations. The reason for me worrying about this is that we will have to maintain these What do you think if we only keep |
||
| .PHONY: check-unused-deps | ||
| check-unused-deps: | ||
| cargo machete 2>/dev/null | ||
|
|
||
| .PHONY: check-all | ||
| check-all: check-fmt check check-unused-deps | ||
|
|
||
| .PHONY: fmt | ||
| fmt: | ||
| cargo fmt --all | ||
| taplo format | ||
| .PHONY: check-all-features | ||
| check-all-features: check-all-features-host check-all-features-wasm | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -45,6 +45,6 @@ impl State { | |
| self.close_unchecked(reason); | ||
| } | ||
|
|
||
| self.lost_found(params) | ||
| Ok(self.lost_found(params)) | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please move all the crappy stuff to the end of the file, while keeping minimalistic and understandable targets on top?