.DEFAULT_GOAL := help
CARGO := cargo
WASM_PACK := wasm-pack
PYTHON := python3
RUSTFLAGS_WASM := --cfg getrandom_backend="js"
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[0;33m
BLUE := \033[0;34m
NC := \033[0m
.PHONY: help
help:
@echo "$(BLUE)Trek Build System$(NC)"
@echo "=================="
@echo ""
@echo "Available targets:"
@echo ""
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-15s$(NC) %s\n", $$1, $$2}'
.PHONY: check
check:
@echo "$(YELLOW)Checking code...$(NC)"
$(CARGO) check
.PHONY: build
build:
@echo "$(YELLOW)Building project...$(NC)"
$(CARGO) build
.PHONY: build-release
build-release:
@echo "$(YELLOW)Building release...$(NC)"
$(CARGO) build --release
.PHONY: test
test:
@echo "$(YELLOW)Running tests...$(NC)"
$(CARGO) test
.PHONY: test-verbose
test-verbose:
@echo "$(YELLOW)Running tests (verbose)...$(NC)"
$(CARGO) test -- --nocapture
.PHONY: fmt
fmt:
@echo "$(YELLOW)Formatting code...$(NC)"
$(CARGO) fmt
.PHONY: fmt-check
fmt-check:
@echo "$(YELLOW)Checking formatting...$(NC)"
$(CARGO) fmt -- --check
.PHONY: clippy
clippy:
@echo "$(YELLOW)Running clippy...$(NC)"
$(CARGO) clippy -- -D warnings
.PHONY: clippy-fix
clippy-fix:
@echo "$(YELLOW)Running clippy with fixes...$(NC)"
$(CARGO) clippy --fix --allow-dirty --allow-staged
.PHONY: clean
clean:
@echo "$(YELLOW)Cleaning build artifacts...$(NC)"
$(CARGO) clean
rm -rf pkg/
rm -rf target/
.PHONY: doc
doc:
@echo "$(YELLOW)Generating documentation...$(NC)"
$(CARGO) doc --open
.PHONY: wasm-check-deps
wasm-check-deps:
@echo "$(YELLOW)Checking WASM dependencies...$(NC)"
@command -v wasm-pack >/dev/null 2>&1 || { echo "$(RED)wasm-pack not found. Install with: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh$(NC)" >&2; exit 1; }
.PHONY: wasm-build
wasm-build: wasm-check-deps
@echo "$(YELLOW)Building WASM module...$(NC)"
RUSTFLAGS='$(RUSTFLAGS_WASM)' $(WASM_PACK) build --target web --out-dir pkg --release --no-opt
@node scripts/fix-package-json.js
.PHONY: wasm-build-debug
wasm-build-debug: wasm-check-deps
@echo "$(YELLOW)Building WASM module (debug)...$(NC)"
RUSTFLAGS='$(RUSTFLAGS_WASM)' $(WASM_PACK) build --target web --out-dir pkg --dev
@node scripts/fix-package-json.js
.PHONY: wasm-test
wasm-test:
@echo "$(YELLOW)Running WASM tests...$(NC)"
wasm-pack test --headless --chrome
.PHONY: serve
serve:
@echo "$(YELLOW)Starting test server...$(NC)"
@echo "$(GREEN)Open http://localhost:8000/test-wasm.html in your browser$(NC)"
$(PYTHON) serve.py
.PHONY: playground
playground: wasm-build
@echo "$(YELLOW)Building WASM and starting playground server...$(NC)"
@echo "$(GREEN)Open http://localhost:8000/playground/ in your browser$(NC)"
$(PYTHON) serve.py
.PHONY: bench
bench:
@echo "$(YELLOW)Running benchmarks...$(NC)"
$(CARGO) bench
.PHONY: outdated
outdated:
@echo "$(YELLOW)Checking for outdated dependencies...$(NC)"
$(CARGO) outdated
.PHONY: update
update:
@echo "$(YELLOW)Updating dependencies...$(NC)"
$(CARGO) update
.PHONY: audit
audit:
@echo "$(YELLOW)Running security audit...$(NC)"
$(CARGO) audit
.PHONY: coverage
coverage:
@echo "$(YELLOW)Generating coverage report...$(NC)"
$(CARGO) tarpaulin --out Html
.PHONY: all
all: fmt check clippy test build
.PHONY: ci
ci: fmt-check check clippy test
.PHONY: release
release: clean fmt check clippy test build-release wasm-build
.PHONY: changelog
changelog:
@echo "$(YELLOW)Generating changelog...$(NC)"
@command -v git-cliff >/dev/null 2>&1 || { echo "$(RED)git-cliff not found. Install with: cargo install git-cliff$(NC)" >&2; exit 1; }
git-cliff -o CHANGELOG.md
.PHONY: changelog-unreleased
changelog-unreleased:
@echo "$(YELLOW)Showing unreleased changes...$(NC)"
@command -v git-cliff >/dev/null 2>&1 || { echo "$(RED)git-cliff not found. Install with: cargo install git-cliff$(NC)" >&2; exit 1; }
git-cliff --unreleased
.PHONY: changelog-tag
changelog-tag:
@echo "$(YELLOW)Generating changelog for tag $(TAG)...$(NC)"
@command -v git-cliff >/dev/null 2>&1 || { echo "$(RED)git-cliff not found. Install with: cargo install git-cliff$(NC)" >&2; exit 1; }
@test -n "$(TAG)" || { echo "$(RED)Please specify TAG=v0.x.x$(NC)" >&2; exit 1; }
git-cliff --tag $(TAG) -o CHANGELOG.md
.PHONY: version-bump
version-bump:
@echo "$(YELLOW)Analyzing commits for version bump...$(NC)"
@command -v git-cliff >/dev/null 2>&1 || { echo "$(RED)git-cliff not found. Install with: cargo install git-cliff$(NC)" >&2; exit 1; }
@echo "Current version: $$(grep '^version' Cargo.toml | head -1 | cut -d'"' -f2)"
@echo "Suggested next version based on commits:"
@git-cliff --bumped-version
.PHONY: install-dev-deps
install-dev-deps:
@echo "$(YELLOW)Installing development dependencies...$(NC)"
$(CARGO) install cargo-outdated
$(CARGO) install cargo-audit
$(CARGO) install cargo-tarpaulin
$(CARGO) install git-cliff
$(CARGO) install wasm-pack
@echo "$(GREEN)Development dependencies installed!$(NC)"
.PHONY: setup-git
setup-git:
@echo "$(YELLOW)Configuring git for conventional commits...$(NC)"
git config --local commit.template .gitmessage
@echo "$(GREEN)Git configured to use .gitmessage template!$(NC)"
@echo "$(BLUE)Tip: Use 'git commit' (without -m) to use the template$(NC)"
.PHONY: pre-commit
pre-commit: fmt check clippy test
@echo "$(GREEN)All pre-commit checks passed!$(NC)"
.PHONY: npm-publish
npm-publish: wasm-build
@echo "$(YELLOW)Publishing to npm...$(NC)"
@cd pkg && npm publish --access public
@echo "$(GREEN)Published to npm!$(NC)"
.PHONY: npm-publish-dry
npm-publish-dry: wasm-build
@echo "$(YELLOW)Running npm publish dry run...$(NC)"
@cd pkg && npm publish --dry-run --access public
.PHONY: crates-publish
crates-publish: test
@echo "$(YELLOW)Publishing to crates.io...$(NC)"
cargo publish
@echo "$(GREEN)Published to crates.io!$(NC)"
.PHONY: crates-publish-dry
crates-publish-dry: test
@echo "$(YELLOW)Running crates.io publish dry run...$(NC)"
cargo publish --dry-run
.PHONY: stats
stats:
@echo "$(YELLOW)Code statistics:$(NC)"
@echo ""
@echo "Lines of Rust code:"
@find src -name "*.rs" | xargs wc -l | tail -1
@echo ""
@echo "Number of files:"
@find src -name "*.rs" | wc -l
.PHONY: vscode-setup
vscode-setup:
@mkdir -p .vscode
@echo '{\n "version": "2.0.0",\n "tasks": [\n {\n "label": "cargo check",\n "type": "shell",\n "command": "make check"\n },\n {\n "label": "cargo test",\n "type": "shell",\n "command": "make test"\n },\n {\n "label": "cargo fmt",\n "type": "shell",\n "command": "make fmt"\n }\n ]\n}' > .vscode/tasks.json
@echo "$(GREEN)VS Code tasks created!$(NC)"