Makefile 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. RUST_TOOLCHAIN_NIGHTLY = nightly-2025-02-16
  2. SOLANA_CLI_VERSION = 3.0.0
  3. nightly = +${RUST_TOOLCHAIN_NIGHTLY}
  4. # This is a bit tricky -- findstring returns the found string, so we're looking
  5. # for "directory-", returning that, and replacing "-" with "/" to change the
  6. # first "-" to a "/". But if it isn't found, we replace "" with "", which works
  7. # in the case where there is no subdirectory.
  8. pattern-dir = $(firstword $(subst -, ,$1))
  9. find-pattern-dir = $(findstring $(call pattern-dir,$1)-,$1)
  10. make-path = $(subst $(call find-pattern-dir,$1),$(subst -,/,$(call find-pattern-dir,$1)),$1)
  11. rust-toolchain-nightly:
  12. @echo ${RUST_TOOLCHAIN_NIGHTLY}
  13. solana-cli-version:
  14. @echo ${SOLANA_CLI_VERSION}
  15. cargo-nightly:
  16. cargo $(nightly) $(ARGS)
  17. generate-clients:
  18. @echo "No JavaScript clients to generate"
  19. audit:
  20. cargo audit \
  21. --ignore RUSTSEC-2022-0093 \
  22. --ignore RUSTSEC-2024-0344 \
  23. --ignore RUSTSEC-2024-0376 $(ARGS)
  24. spellcheck:
  25. cargo spellcheck --code 1 $(ARGS)
  26. clippy-%:
  27. cargo $(nightly) clippy --manifest-path $(call make-path,$*)/Cargo.toml \
  28. --all-targets \
  29. --all-features \
  30. -- \
  31. --deny=warnings \
  32. --deny=clippy::default_trait_access \
  33. --deny=clippy::arithmetic_side_effects \
  34. --deny=clippy::manual_let_else \
  35. --deny=clippy::used_underscore_binding $(ARGS)
  36. format-check-%:
  37. cargo $(nightly) fmt --check --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)
  38. powerset-%:
  39. cargo $(nightly) hack check --feature-powerset --all-targets --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)
  40. semver-check-%:
  41. cargo semver-checks --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)
  42. shellcheck:
  43. git ls-files -- '*.sh' | xargs shellcheck --color=always --external-sources --shell=bash $(ARGS)
  44. sort-check:
  45. cargo $(nightly) sort --workspace --check $(ARGS)
  46. bench-%:
  47. cargo $(nightly) bench --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)
  48. regression-%:
  49. mollusk run-test --proto mollusk --ignore-compute-units $(call make-path,$*)/fuzz/program-mb.so ./target/deploy/$(subst -,_,$(shell toml get $(call make-path,$*)/Cargo.toml package.name)).so $(call make-path,$*)/fuzz/blob $(shell toml get $(call make-path,$*)/Cargo.toml package.metadata.solana.program-id)
  50. format-rust:
  51. cargo $(nightly) fmt --all $(ARGS)
  52. build-sbf-%:
  53. cargo build-sbf --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)
  54. build-wasm-%:
  55. cargo build --target wasm32-unknown-unknown --manifest-path $(call make-path,$*)/Cargo.toml --all-features $(ARGS)
  56. build-doc-%:
  57. RUSTDOCFLAGS="--cfg docsrs -D warnings" cargo $(nightly) doc --all-features --no-deps --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)
  58. test-doc-%:
  59. cargo $(nightly) test --doc --all-features --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)
  60. test-%:
  61. SBF_OUT_DIR=$(PWD)/target/deploy cargo $(nightly) test --manifest-path $(call make-path,$*)/Cargo.toml $(ARGS)
  62. # Helpers for publishing
  63. tag-name = $(lastword $(subst /, ,$(call make-path,$1)))
  64. preid-arg = $(subst pre,--preid $2,$(findstring pre,$1))
  65. package-version = $(subst ",,$(shell jq -r '.version' $(call make-path,$1)/package.json))
  66. crate-version = $(subst ",,$(shell toml get $(call make-path,$1)/Cargo.toml package.version))
  67. git-tag-rust-%:
  68. @echo "$(call tag-name,$*)@v$(call crate-version,$*)"
  69. publish-rust-%:
  70. cd "$(call make-path,$*)" && cargo release $(LEVEL) --tag-name "$(call tag-name,$*)@v{{version}}" --execute --no-confirm --dependent-version fix
  71. publish-rust-dry-run-%:
  72. cd "$(call make-path,$*)" && cargo release $(LEVEL) --tag-name "$(call tag-name,$*)@v{{version}}"