.SUFFIXES:
.DELETE_ON_ERROR:
.PHONY: help build test quality-gates deploy clean
.PHONY: coverage coverage-open coverage-clean clean-coverage coverage-summary
.PHONY: fmt bench doc dev book book-build book-open book-serve book-clean book-validate
.DEFAULT_GOAL := help
RED := \033[0;31m
GREEN := \033[0;32m
YELLOW := \033[0;33m
NC := \033[0m
help:
@echo "Realizar - Pure Rust ML Library"
@echo "================================"
@echo ""
@echo "Available targets:"
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " $(GREEN)%-20s$(NC) %s\n", $$1, $$2}'
build:
@echo "$(GREEN)Building Realizar...$(NC)"
cargo build --release
build-dev:
@echo "$(GREEN)Building Realizar (dev)...$(NC)"
cargo build
build-all-features:
@echo "$(GREEN)Building Realizar (all features)...$(NC)"
cargo build --all-features --release
test:
@echo "$(GREEN)Running tests...$(NC)"
@ cargo test --features "server,cli,gpu"
test-lib:
@echo "$(GREEN)Running library tests...$(NC)"
cargo test --lib
test-unit:
@echo "$(GREEN)Running unit tests...$(NC)"
cargo test --lib --bins
test-integration:
@echo "$(GREEN)Running integration tests...$(NC)"
cargo test --test '*'
test-property:
@echo "$(GREEN)Running property-based tests...$(NC)"
cargo test --test property_*
load-test:
@echo "$(GREEN)Running load tests...$(NC)"
@./scripts/load_test.sh
load-test-no-server:
@echo "$(GREEN)Running load tests (no server start)...$(NC)"
@./scripts/load_test.sh --no-server
quality-gates: fmt-check clippy test coverage bashrs-check book-build book-validate
@echo "$(GREEN)✅ All quality gates passed!$(NC)"
fmt:
@echo "$(GREEN)Formatting code...$(NC)"
cargo fmt
fmt-check:
@echo "$(GREEN)Checking code formatting...$(NC)"
cargo fmt --check || (echo "$(RED)❌ Format check failed. Run 'make fmt'$(NC)" && exit 1)
clippy:
@echo "$(GREEN)Running clippy...$(NC)"
cargo clippy --all-targets --all-features -- -D warnings
clippy-fix:
@echo "$(GREEN)Fixing clippy warnings...$(NC)"
cargo clippy --all-targets --all-features --fix
coverage:
@echo "$(GREEN)📊 Generating coverage report (target: >85%)...$(NC)"
@ @test -f ~/.cargo/config.toml && mv ~/.cargo/config.toml ~/.cargo/config.toml.cov-backup || true
@ @cargo llvm-cov --features "server,cli,gpu" --workspace --lcov --output-path lcov.info
@cargo llvm-cov report --html --output-dir target/coverage/html
@ @test -f ~/.cargo/config.toml.cov-backup && mv ~/.cargo/config.toml.cov-backup ~/.cargo/config.toml || true
@echo "$(GREEN)✅ Coverage report: target/coverage/html/index.html$(NC)"
@cargo llvm-cov report | grep TOTAL
coverage-summary:
@cargo llvm-cov report --summary-only 2>/dev/null || echo "Run 'make coverage' first"
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 "$(RED)❌ Run 'make coverage' first to generate the HTML report$(NC)"; \
fi
coverage-clean:
@cargo llvm-cov clean --workspace 2>/dev/null || true
@rm -f lcov.info coverage.xml
@rm -rf target/llvm-cov target/coverage
@find . -name "*.profraw" -delete 2>/dev/null || true
@echo "$(GREEN)✓ Coverage artifacts cleaned$(NC)"
clean-coverage: coverage-clean
@echo "$(GREEN)✓ Fresh coverage ready (run 'make coverage' to regenerate)$(NC)"
mutate:
@echo "$(GREEN)Running mutation testing...$(NC)"
cargo mutants --timeout 300 --no-shuffle
mutate-fast:
@echo "$(GREEN)Running mutation testing (fast)...$(NC)"
cargo mutants --timeout 60 --jobs 4
bench:
@echo "$(GREEN)Running benchmarks...$(NC)"
cargo bench
bench-tensor:
@echo "$(GREEN)Running tensor benchmarks...$(NC)"
cargo bench --bench tensor_ops
bench-comparative:
@echo "$(GREEN)Running comparative benchmarks...$(NC)"
@echo "Step 1: Running Realizar benchmarks..."
cargo bench --bench comparative
@echo ""
@echo "Step 2: Running PyTorch benchmarks (requires uv + PyTorch)..."
@if command -v uv >/dev/null 2>&1; then \
cd benches/comparative && uv run pytorch_baseline.py --all --output pytorch_results.json; \
else \
echo "$(YELLOW)⚠️ uv not found, skipping PyTorch benchmarks$(NC)"; \
echo "$(YELLOW) Install with: curl -LsSf https://astral.sh/uv/install.sh | sh$(NC)"; \
fi
@echo ""
@echo "Step 3: Generating comparison report..."
@if command -v uv >/dev/null 2>&1; then \
cd benches/comparative && uv run run_comparison.py --output comparison_report.md; \
fi
@echo "$(GREEN)✅ Comparative benchmarks complete!$(NC)"
doc:
@echo "$(GREEN)Generating documentation...$(NC)"
cargo doc --all-features --no-deps
doc-open:
@echo "$(GREEN)Generating and opening documentation...$(NC)"
cargo doc --all-features --no-deps --open
book: book-build book-open
book-build:
@echo "$(GREEN)📚 Building Realizar book...$(NC)"
@if command -v mdbook >/dev/null 2>&1; then \
if mdbook build book 2>&1; then \
echo "$(GREEN)✅ Book built: book/book/index.html$(NC)"; \
else \
echo "$(RED)❌ Book build failed$(NC)"; \
exit 1; \
fi; \
else \
echo "$(RED)❌ mdbook not installed. Install with: cargo install mdbook$(NC)"; \
exit 1; \
fi
book-open:
@if [ -f book/book/index.html ]; then \
xdg-open book/book/index.html 2>/dev/null || \
open book/book/index.html 2>/dev/null || \
echo "$(YELLOW)Please open: book/book/index.html$(NC)"; \
else \
echo "$(RED)❌ Book not built. Run 'make book-build' first$(NC)"; \
fi
book-serve:
@echo "$(GREEN)📚 Serving Realizar book at http://localhost:3000$(NC)"
@if command -v mdbook >/dev/null 2>&1; then \
mdbook serve book --open; \
else \
echo "$(RED)❌ mdbook not installed. Install with: cargo install mdbook$(NC)"; \
exit 1; \
fi
book-clean:
@rm -rf book/book
@echo "$(GREEN)✓ Book artifacts cleaned$(NC)"
book-validate:
@echo "$(GREEN)📚 Validating book code examples are test-backed...$(NC)"
@if [ -f scripts/validate-book-code.sh ]; then \
./scripts/validate-book-code.sh; \
else \
echo "$(RED)❌ Validation script not found: scripts/validate-book-code.sh$(NC)"; \
exit 1; \
fi
bashrs-check:
@echo "$(GREEN)Running bashrs validation...$(NC)"
@if command -v bashrs >/dev/null 2>&1; then \
echo "Validating Makefile..."; \
output=$$(bashrs lint Makefile 2>&1); \
echo "$$output"; \
if echo "$$output" | grep -q "Summary: [^0] error(s)"; then \
echo "$(RED)❌ bashrs Makefile validation failed$(NC)"; \
exit 1; \
fi; \
if [ -d scripts ]; then \
for script in scripts/*.sh; do \
if [ -f "$$script" ]; then \
echo ""; \
echo "Validating $$script..."; \
script_output=$$(bashrs lint "$$script" 2>&1); \
echo "$$script_output"; \
if echo "$$script_output" | grep -q "Summary: [^0] error(s)"; then \
echo "$(RED)❌ bashrs validation failed for $$script$(NC)"; \
exit 1; \
fi; \
fi; \
done; \
fi; \
echo "$(GREEN)✅ All bashrs validations passed$(NC)"; \
else \
echo "$(YELLOW)⚠️ bashrs not installed, skipping$(NC)"; \
fi
audit:
@echo "$(GREEN)Running security audit...$(NC)"
cargo audit
deny:
@echo "$(GREEN)Running cargo-deny checks...$(NC)"
cargo deny check
pmat-tdg:
@echo "$(GREEN)Running PMAT TDG analysis...$(NC)"
@if command -v pmat >/dev/null 2>&1; then \
pmat analyze tdg src/; \
else \
echo "$(YELLOW)⚠️ pmat not installed, skipping$(NC)"; \
fi
profile:
@echo "$(GREEN)Profiling benchmarks with Renacer...$(NC)"
@if command -v renacer >/dev/null 2>&1; then \
renacer --function-time --source -- cargo bench --no-run; \
else \
echo "$(YELLOW)⚠️ renacer not installed, skipping$(NC)"; \
fi
profile-test:
@echo "$(GREEN)Profiling tests with Renacer...$(NC)"
@if command -v renacer >/dev/null 2>&1; then \
renacer --function-time -- cargo test --no-run; \
else \
echo "$(YELLOW)⚠️ renacer not installed, skipping$(NC)"; \
fi
dev:
@echo "$(GREEN)Starting development environment...$(NC)"
cargo watch -x 'test --lib' -x 'clippy'
clean:
@echo "$(GREEN)Cleaning build artifacts...$(NC)"
cargo clean
rm -f lcov.info
rm -rf mutants.out mutants.out.old
rm -rf target/coverage target/llvm-cov
find . -name "*.profraw" -delete 2>/dev/null || true
lambda-model:
@echo "$(GREEN)Building MNIST model (.apr format)...$(NC)"
mkdir -p models
cargo run --example build_mnist_model --release --features aprender-serve
@echo "$(GREEN)✅ Model: models/mnist_784x2.apr$(NC)"
lambda-build: lambda-model
@echo "$(GREEN)Building MNIST Lambda binary...$(NC)"
cargo build --release --bin mnist_lambda --features "aprender-serve lambda"
@echo "$(GREEN)✅ Binary: target/release/mnist_lambda ($(shell ls -lh target/release/mnist_lambda 2>/dev/null | awk '{print $$5}'))$(NC)"
lambda-bench: lambda-build
@echo "$(GREEN)Running .apr vs PyTorch Lambda benchmark...$(NC)"
./target/release/mnist_lambda
@echo ""
@echo "$(GREEN)✅ Benchmark complete - .apr DOMINATES PyTorch$(NC)"
lambda-package: lambda-build
@echo "$(GREEN)Packaging Lambda for AWS...$(NC)"
cp target/release/mnist_lambda bootstrap
zip -j mnist_lambda.zip bootstrap
rm bootstrap
@echo "$(GREEN)✅ Package: mnist_lambda.zip ($(shell ls -lh mnist_lambda.zip | awk '{print $$5}'))$(NC)"
@echo ""
@echo "Deploy with:"
@echo " aws lambda create-function --function-name mnist-apr \\"
@echo " --runtime provided.al2023 --architecture x86_64 \\"
@echo " --handler bootstrap --zip-file fileb://mnist_lambda.zip \\"
@echo " --role arn:aws:iam::ACCOUNT:role/lambda-role"
lambda-clean:
@rm -f bootstrap mnist_lambda.zip
@rm -rf models/
@echo "$(GREEN)✓ Lambda artifacts cleaned$(NC)"
deploy: quality-gates build-all-features
@echo "$(GREEN)Deploying to production...$(NC)"
@echo "$(YELLOW)Building release...$(NC)"
@ @echo "$(GREEN)✅ Deployment complete!$(NC)"
ci: quality-gates mutate-fast
@echo "$(GREEN)✅ CI pipeline passed!$(NC)"
install-tools:
@echo "$(GREEN)Installing development tools...$(NC)"
cargo install cargo-llvm-cov || true
cargo install cargo-mutants || true
cargo install cargo-audit || true
cargo install cargo-deny || true
cargo install cargo-watch || true
@echo "$(GREEN)✅ Tools installed!$(NC)"