SHELL := /bin/bash
MAKEFLAGS += -j$(shell nproc)
.SUFFIXES:
.DELETE_ON_ERROR:
.ONESHELL:
.PHONY: help build build-release bench bench-check test test-fast test-verbose test-lib test-s3 test-s3-full lint lint-pedantic lint-fast fmt fmt-check check coverage coverage-open coverage-check coverage-clean quality-gate mutants mutation-report mutation-clean tdg clean doc doc-open watch watch-test ci pre-commit dev-deps stats pmat-tdg pmat-analyze pmat-score pmat-rust-score pmat-rust-score-fast pmat-quality-gate pmat-all wasm wasm-check book book-build book-serve book-test
COVERAGE_THRESHOLD := 85
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
build:
cargo build --all-features
build-release:
cargo build --release --all-features
bench:
cargo bench
bench-check:
cargo bench --no-run
test:
cargo test --all-features
test-fast:
@echo "โก Running fast tests (target: <2 min)..."
@if command -v cargo-nextest >/dev/null 2>&1; then \
cargo nextest run \
--workspace \
--all-features \
--status-level skip \
--failure-output immediate; \
else \
echo "๐ฆ cargo-nextest not found, using cargo test..."; \
cargo test --all-features --workspace; \
fi
test-verbose:
cargo test --all-features -- --nocapture
test-lib:
cargo test --lib --all-features
test-s3:
@echo "๐ชฃ Running S3 integration tests with MinIO..."
@echo " Ensure MinIO is running: docker compose up -d"
cargo test --features s3 s3_integration -- --ignored
test-s3-full:
@echo "๐ Starting MinIO via docker compose..."
docker compose up -d
@echo "โณ Waiting for MinIO to be ready..."
@sleep 5
@echo "๐ชฃ Running S3 integration tests..."
cargo test --features s3 s3_integration -- --ignored
@echo "๐งน Stopping MinIO..."
docker compose down
lint:
cargo clippy --all-targets --all-features -- -D warnings
lint-pedantic:
cargo clippy --all-targets --all-features -- -D warnings -D clippy::pedantic
lint-fast:
cargo clippy --lib --all-features -- -D warnings
fmt:
cargo fmt
fmt-check:
cargo fmt --check
check: fmt-check lint test
COVERAGE_FEATURES := local,tokio-runtime,cli,mmap,http,hf-hub,shuffle,format-encryption,format-signing,format-streaming,repl
coverage:
@echo "๐ Running coverage analysis (target: <5 min)..."
@echo " Note: S3 feature excluded (requires MinIO)"
@echo "๐ Checking for cargo-llvm-cov and cargo-nextest..."
@which cargo-llvm-cov > /dev/null 2>&1 || (echo "๐ฆ Installing cargo-llvm-cov..." && cargo install cargo-llvm-cov --locked)
@which cargo-nextest > /dev/null 2>&1 || (echo "๐ฆ Installing cargo-nextest..." && cargo install cargo-nextest --locked)
@echo "๐งน Cleaning old coverage data..."
@cargo llvm-cov clean --workspace
@mkdir -p target/coverage
@echo "โ๏ธ Temporarily disabling global cargo config (mold breaks coverage)..."
@test -f ~/.cargo/config.toml && mv ~/.cargo/config.toml ~/.cargo/config.toml.cov-backup 2>/dev/null || true
@echo "๐งช Phase 1: Running tests with instrumentation (no report)..."
@cargo llvm-cov --no-report nextest --no-tests=warn --features "$(COVERAGE_FEATURES)" --workspace
@echo "๐ Phase 2: Generating coverage reports..."
@cargo llvm-cov report --html --output-dir target/coverage/html
@cargo llvm-cov report --lcov --output-path target/coverage/lcov.info
@cp target/coverage/lcov.info lcov.info
@echo "โ๏ธ Restoring global cargo config..."
@test -f ~/.cargo/config.toml.cov-backup && mv ~/.cargo/config.toml.cov-backup ~/.cargo/config.toml 2>/dev/null || true
@echo ""
@echo "๐ Coverage Summary:"
@echo "=================="
@cargo llvm-cov report --summary-only
@echo ""
@echo "๐ก COVERAGE INSIGHTS:"
@echo "- HTML report: target/coverage/html/index.html"
@echo "- LCOV file: target/coverage/lcov.info"
@echo "- Open HTML: make coverage-open"
coverage-open:
@if [ -f target/coverage/html/index.html ]; then \
xdg-open target/coverage/html/index.html 2>/dev/null || \
open target/coverage/html/index.html 2>/dev/null || \
echo "Please open: target/coverage/html/index.html"; \
else \
echo "โ Run 'make coverage' first to generate the HTML report"; \
fi
coverage-check:
@echo "๐ Enforcing $(COVERAGE_THRESHOLD)% coverage threshold..."
@echo " Note: S3 feature excluded (requires MinIO)"
@which cargo-llvm-cov > /dev/null 2>&1 || (echo "๐ฆ Installing cargo-llvm-cov..." && cargo install cargo-llvm-cov --locked)
@which cargo-nextest > /dev/null 2>&1 || (echo "๐ฆ Installing cargo-nextest..." && cargo install cargo-nextest --locked)
@cargo llvm-cov clean --workspace
@test -f ~/.cargo/config.toml && mv ~/.cargo/config.toml ~/.cargo/config.toml.cov-backup 2>/dev/null || true
@cargo llvm-cov --no-report nextest --no-tests=warn --features "$(COVERAGE_FEATURES)" --workspace
@cargo llvm-cov report --fail-under-lines $(COVERAGE_THRESHOLD) || \
(echo "โ FAIL: Coverage below $(COVERAGE_THRESHOLD)% threshold"; \
test -f ~/.cargo/config.toml.cov-backup && mv ~/.cargo/config.toml.cov-backup ~/.cargo/config.toml 2>/dev/null; exit 1)
@test -f ~/.cargo/config.toml.cov-backup && mv ~/.cargo/config.toml.cov-backup ~/.cargo/config.toml 2>/dev/null || true
@echo "โ
Coverage threshold met (โฅ$(COVERAGE_THRESHOLD)%)"
coverage-clean:
@cargo llvm-cov clean --workspace
@rm -f lcov.info coverage.xml target/coverage/lcov.info
@rm -rf target/llvm-cov target/coverage
@find . -name "*.profraw" -delete
@echo "โ Coverage artifacts cleaned"
mutants:
@echo "๐งฌ Running mutation testing (this will take a while)..."
@echo "Target: >85% mutation score"
@if command -v cargo-mutants >/dev/null 2>&1; then \
cargo mutants --no-times --output mutants.out || true; \
echo "โ
Mutation testing complete. Results in mutants.out/"; \
else \
echo "๐ฅ Installing cargo-mutants..."; \
cargo install cargo-mutants && cargo mutants --no-times --output mutants.out || true; \
fi
mutation-report:
@echo "๐ Analyzing mutation test results..."
@if [ -d "mutants.out" ]; then \
cat mutants.out/mutants.out 2>/dev/null || echo "No mutation results yet"; \
else \
echo "No mutation results found. Run 'make mutants' first."; \
fi
mutation-clean:
@rm -rf mutants.out mutants.out.old
@echo "โ Mutation testing artifacts cleaned"
tdg:
@pmat analyze tdg 2>/dev/null || echo "โ ๏ธ PMAT not available"
quality-gate: lint test coverage-check
@echo "โ
All quality gates passed"
pmat-tdg:
@pmat analyze tdg
pmat-analyze:
@pmat analyze complexity --project-path . || true
@pmat analyze satd --path . || true
@pmat analyze dead-code --path . || true
@pmat analyze duplicates || true
@pmat analyze defects --path . || true
pmat-score:
@pmat repo-score || true
pmat-rust-score:
@mkdir -p target/pmat-reports
@pmat rust-project-score --path . || echo "โ ๏ธ Rust project score not available in this PMAT version"
pmat-rust-score-fast:
@pmat rust-project-score --path . || echo "โ ๏ธ Rust project score not available in this PMAT version"
pmat-quality-gate:
@echo "๐ Running PMAT quality gate..."
@pmat analyze tdg --min-grade B+ 2>/dev/null || echo " โ ๏ธ PMAT TDG not available"
@pmat repo-score . --min-score 90 2>/dev/null || echo " โ ๏ธ PMAT repo-score not available"
pmat-all: pmat-tdg pmat-analyze pmat-score pmat-rust-score
wasm:
cargo build --target wasm32-unknown-unknown --release --no-default-features --features wasm
wasm-check:
cargo check --target wasm32-unknown-unknown --no-default-features --features wasm
doc:
cargo doc --all-features --no-deps
doc-open:
cargo doc --all-features --no-deps --open
book: book-build
@if command -v xdg-open >/dev/null 2>&1; then \
xdg-open book/book/index.html; \
elif command -v open >/dev/null 2>&1; then \
open book/book/index.html; \
fi
book-build:
@echo "๐ Building alimentar user guide..."
@if command -v mdbook >/dev/null 2>&1; then \
mdbook build book; \
echo "โ
Book built: book/book/index.html"; \
else \
echo "โ mdbook not found. Install with: cargo install mdbook"; \
exit 1; \
fi
book-serve:
@echo "๐ Serving book at http://localhost:3000..."
@mdbook serve book --open
book-test:
@echo "๐ Testing book code examples..."
@mdbook test book 2>/dev/null || echo "โ ๏ธ Some examples may not be runnable (requires full project context)"
watch:
cargo watch -x "check --all-features"
watch-test:
cargo watch -x "test --all-features"
ci: lint test coverage doc
@echo "โ
CI pipeline passed"
pre-commit: fmt-check lint test
@echo "โ
Pre-commit checks passed"
clean:
cargo clean
rm -rf target/ coverage/ mutants.out/ lcov.info
dev-deps:
cargo install cargo-llvm-cov cargo-nextest cargo-tarpaulin cargo-mutants cargo-watch
stats:
@echo "๐ Project Statistics"
@echo "===================="
@echo ""
@echo "Lines of code:"
@find src -name "*.rs" | xargs wc -l | tail -1
@echo ""
@echo "Test count:"
@cargo test --all-features 2>&1 | grep -E "running [0-9]+ tests" | awk '{sum += $$2} END {print " " sum " tests"}'
@echo ""
@echo "Dependencies:"
@cargo tree --depth 1 2>/dev/null | wc -l | xargs -I {} echo " {} direct dependencies"