# crate-kit: common targets for the crates of a multi-crate Rust project. # # This directory (.crate-kit/) is a COPY of the kit/ folder of the crate-kit repository: do not # modify it here, fix it in crate-kit then run `make kit-update`. # # Usage, in the crate's Makefile: # RELEASE_PROJECT_DESC = acmexxx (short description) # optional # include .crate-kit/crate.mk # # Adjustable variables (before the include or on the command line): # CARGO, CARGO_TOML, FEATURES, API_DIR, RELEASE_NOTES_DIR, REGISTRY, KIT_SRC # KIT_LANG language of LLM-generated documents (default en; any language name or ISO code) # RELEASE=x.y.z forces the version of bump-version / jjrelease # DRY_RUN=1 publish: checks the package without sending it # # Crate kind: CRATE_KIND (default "crate"). kinds/.mk sets, before the targets, the generic variables # that the kit reads: BUILD_TARGET (--target of the builds), EXTRA_TARGETS (targets that check and clippy # go through in addition to the host), PUBLISH, API_TRACKED, WIKI (yes|no: publication to the registry, # API snapshot and version verdict, wiki), AFTER_RELEASE (command run after the tag). A kind # can also add its own targets. Kinds specific to an organization come from its overlay (org.mk # sets REGISTRY and REGISTRY_INDEX); see tools/kit-assemble.sh. KIT_DIR := $(patsubst %/,%,$(dir $(lastword $(MAKEFILE_LIST)))) KIT_SRC ?= ../crate-kit CARGO ?= cargo CARGO_TOML ?= Cargo.toml FEATURES ?= API_DIR ?= api RELEASE_NOTES_DIR ?= ReleaseNotes CRATE_KIND ?= crate BUILD_TARGET ?= PUBLISH ?= yes API_TRACKED ?= yes WIKI ?= yes AFTER_RELEASE ?= # Additional targets that check and clippy go through (e.g. EXTRA_TARGETS = wasm32-unknown-unknown). EXTRA_TARGETS ?= RELEASE_PROJECT_DESC ?= $(shell sed -n 's/^name = "\(.*\)"/\1/p' $(CARGO_TOML) | head -n 1) GREEN = \033[0;32m YELLOW = \033[1;33m BLUE = \033[1;34m NC = \033[0m include $(KIT_DIR)/dev-patch.mk include $(KIT_DIR)/jj.mk # Language of the documents an LLM generates (release notes). Default English; an extension kit # overrides it in its org.mk (KIT_LANG ?= fr), included above, or the user on the command line. KIT_LANG ?= en # Language of the commit messages written by `jj auto-doc` (pmojj reads PMOJJ_LANG). export PMOJJ_LANG = $(KIT_LANG) ifeq ($(wildcard $(KIT_DIR)/kinds/$(CRATE_KIND).mk),) $(error unknown crate kind: CRATE_KIND = $(CRATE_KIND) (kinds: $(patsubst $(KIT_DIR)/kinds/%.mk,%,$(wildcard $(KIT_DIR)/kinds/*.mk)))) endif include $(KIT_DIR)/kinds/$(CRATE_KIND).mk export KIT_LANG CARGO CARGO_TOML API_DIR RELEASE_NOTES_DIR REGISTRY RELEASE_PROJECT_DESC KIT_SRC CRATE_KIND PUBLISH API_TRACKED WIKI .DEFAULT_GOAL := build .PHONY: help build release debug test test-doc doc doc-build clean check fmt fmt-check clippy \ watch ci deps update bench coverage bump-version api-level api-snapshot publish wiki \ jjnew jjpush jjfetch jjrelease bookmark-check kit-check needs-commit kit-update kit-version help: @echo "$(GREEN)Available commands:$(NC)" @sed -n "s/^## *\([^:]*\): */\1$$(printf '\t')/p" $(MAKEFILE_LIST) | column -t -s "$$(printf '\t')" | sed -e 's/^/ /' ## build: Release build (alias of release) build: release ## release: Release build (the kind's BUILD_TARGET, if it sets one) release: @echo "$(YELLOW)→ Building (release)...$(NC)" $(CARGO) build --release $(if $(BUILD_TARGET),--target $(BUILD_TARGET)) $(FEATURES) @echo "$(GREEN)✓ Build finished$(NC)" ## debug: Debug build (the kind's BUILD_TARGET, if it sets one) debug: @echo "$(YELLOW)→ Building (debug)...$(NC)" $(CARGO) build $(if $(BUILD_TARGET),--target $(BUILD_TARGET)) $(FEATURES) @echo "$(GREEN)✓ Build finished$(NC)" ## test: All tests test: @echo "$(YELLOW)→ Running the tests...$(NC)" $(CARGO) test --all --all-features @echo "$(GREEN)✓ Tests finished$(NC)" ## test-doc: Documentation example tests test-doc: @echo "$(YELLOW)→ Testing the documentation examples...$(NC)" $(CARGO) test --doc --all-features @echo "$(GREEN)✓ Documentation tests finished$(NC)" ## doc: Generates the documentation and opens it doc: @echo "$(YELLOW)→ Generating the documentation...$(NC)" $(CARGO) doc --no-deps --document-private-items --all-features --open ## doc-build: Generates the documentation without opening it doc-build: @echo "$(YELLOW)→ Generating the documentation...$(NC)" $(CARGO) doc --no-deps --document-private-items --all-features ## clean: Cleanup clean: @echo "$(YELLOW)→ Cleaning...$(NC)" $(CARGO) clean ## check: Code check (host, then EXTRA_TARGETS) check: @$(KIT_DIR)/scripts/publish-guard.sh @echo "$(YELLOW)→ Checking the code...$(NC)" $(CARGO) check --all @for t in $(EXTRA_TARGETS); do $(CARGO) check --all --target $$t || exit 1; done @echo "$(GREEN)✓ Code valid$(NC)" ## fmt: Code formatting fmt: $(CARGO) fmt --all ## fmt-check: Formatting check fmt-check: $(CARGO) fmt --all -- --check ## clippy: Static analysis on the host then EXTRA_TARGETS (warnings = errors) clippy: @echo "$(YELLOW)→ Analysing with clippy...$(NC)" $(CARGO) clippy --all-targets --all-features -- -D warnings @for t in $(EXTRA_TARGETS); do $(CARGO) clippy --lib --all-features --target $$t -- -D warnings || exit 1; done @echo "$(GREEN)✓ Clippy analysis finished$(NC)" ## watch: Continuous check watch: $(CARGO) watch -x check ## ci: Verification pipeline (deps-check fmt-check clippy test doc-build) ci: deps-check fmt-check clippy test doc-build @echo "$(GREEN)✓ All CI checks passed$(NC)" ## deps: Outdated dependencies deps: $(CARGO) outdated ## update: Updates the dependencies update: $(CARGO) update ## bench: Benchmarks bench: $(CARGO) bench ## coverage: Coverage report (cargo-llvm-cov) coverage: @echo "$(YELLOW)→ Generating the coverage report...$(NC)" @mkdir -p target/coverage $(CARGO) llvm-cov --json --output-path target/coverage/llvm-cov-report.json $(CARGO) llvm-cov report @echo "$(GREEN)✓ Report: target/coverage/llvm-cov-report.json$(NC)" ## api-level: Compares the public API to the last snapshot (initial, unchanged, additive or breaking) api-level: @$(KIT_DIR)/scripts/api-level.sh ## api-snapshot: Records the public API of the current version (api/.txt and .json.gz) api-snapshot: @$(KIT_DIR)/scripts/api-snapshot.sh ## bump-version: Next version according to the API (breaking: x.y+1.0 in 0.x), or fixed RELEASE=x.y.z bump-version: @$(KIT_DIR)/scripts/bump-version.sh ## publish: Publishes to the $(REGISTRY) registry (done by the CI after the tag; manual troubleshooting, DRY_RUN=1: without sending) publish: @$(KIT_DIR)/scripts/publish.sh ## wiki: Publishes the API doc to the wiki (done by the CI after the tag; manual troubleshooting, DRY_RUN=1: without push) wiki: @$(KIT_DIR)/scripts/wiki.sh ## jjpush: Version bump, API snapshot, documentation, then main advances to the commit and is pushed jjpush: bookmark-check deps-check bump-version api-snapshot @echo "$(YELLOW)→ Pushing the commit to main...$(NC)" @jj auto-doc @$(KIT_DIR)/scripts/push-main.sh @$(KIT_DIR)/scripts/new-commit.sh @echo "$(GREEN)✓ main pushed; new working commit created on top of it$(NC)" ## jjrelease: Release (ci, version according to the API, snapshot, notes, push of main, tag; the CI then publishes) jjrelease: bookmark-check kit-check ci bump-version api-snapshot @echo "$(BLUE)→ Documenting the undocumented commits...$(NC)" @jj auto-doc @echo "$(BLUE)→ Synchronizing the tags with the remote repository...$(NC)" @jj git fetch @$(KIT_DIR)/scripts/release-notes.sh @echo "$(BLUE)→ Documenting the current commit...$(NC)" @jj auto-doc @echo "$(BLUE)→ Pushing main...$(NC)" @$(KIT_DIR)/scripts/push-main.sh @$(KIT_DIR)/scripts/tag.sh @$(KIT_DIR)/scripts/new-commit.sh @echo "$(GREEN)✓ Tag pushed: the CI (Release workflow) publishes the crate, updates the wiki and creates the release$(NC)" ifneq ($(strip $(AFTER_RELEASE)),) @echo "$(BLUE)→ After the release: $(AFTER_RELEASE)$(NC)" @$(AFTER_RELEASE) endif @name=$$(sed -n 's/^name = "\(.*\)"/\1/p' $(CARGO_TOML) | head -n 1); \ v=$$(sed -n 's/^version = "\(.*\)"/\1/p' $(CARGO_TOML) | head -n 1); \ case "$$v" in 0.*) req=$$(echo "$$v" | cut -d. -f1,2);; *) req=$$(echo "$$v" | cut -d. -f1);; esac; \ echo "$(YELLOW)⚠ Dependent projects: the requirement must accept $$v. If it does not, the local [patch] is ignored: raise it in their Cargo.toml $$name = { version = \"$$req\", registry = \"$(REGISTRY)\" } then cargo update -p $$name$(NC)" ## bookmark-check: Does main track main@origin? Otherwise the push of main would fail at the end of the release (read-only) bookmark-check: @$(KIT_DIR)/scripts/bookmark-check.sh ## kit-check: Is this crate's kit and release workflow identical to crate-kit's? (read-only) kit-check: @$(KIT_DIR)/scripts/kit-check.sh ## needs-commit: Are there changes other than the kit's to commit? (read-only, code 1 if not) needs-commit: @$(KIT_DIR)/scripts/needs-commit.sh ## kit-update: Updates .crate-kit/ from the extension kit (KIT_SRC) kit-update: @test -x "$(KIT_SRC)/tools/kit-copy.sh" || { echo "crate-kit not found: $(KIT_SRC) (set KIT_SRC=...)"; exit 1; } @"$(KIT_SRC)/tools/kit-copy.sh" $(KIT_DIR) @echo "$(GREEN)✓ .crate-kit/ up to date: crate-kit $$(cat $(KIT_DIR)/VERSION)$(NC)" ## print-%: Value of a make variable (e.g. make print-PUBLISH); for the tools print-%: @echo '$($*)' ## kit-version: Kit version installed in this crate kit-version: @cat $(KIT_DIR)/VERSION