|
| 1 | +# rclib Makefile |
| 2 | +# Thorough code checking and development automation |
| 3 | + |
| 4 | +CI := 1 |
| 5 | + |
| 6 | +# -------- Utility macros -------- |
| 7 | +define ensure_tool |
| 8 | + @command -v $(1) >/dev/null || (echo "Installing $(1)..." && cargo install $(1)) |
| 9 | +endef |
| 10 | + |
| 11 | +# Show the help message with list of commands (default target) |
| 12 | +help: |
| 13 | + @echo "rclib Development Commands" |
| 14 | + @echo "==========================" |
| 15 | + @echo "" |
| 16 | + @echo "Code Formatting:" |
| 17 | + @echo " make fmt - Check code formatting" |
| 18 | + @echo " make dev-fmt - Auto-fix code formatting" |
| 19 | + @echo "" |
| 20 | + @echo "Code Quality:" |
| 21 | + @echo " make clippy - Run clippy linter" |
| 22 | + @echo " make lint - Check for compile warnings" |
| 23 | + @echo " make dev-clippy - Auto-fix clippy warnings" |
| 24 | + @echo "" |
| 25 | + @echo "Code Safety:" |
| 26 | + @echo " make kani - Run Kani verifier for safety checks" |
| 27 | + @echo " make geiger - Run Geiger scanner for unsafe code" |
| 28 | + @echo " make safety - Run all code safety checks" |
| 29 | + @echo "" |
| 30 | + @echo "Security:" |
| 31 | + @echo " make deny - Check licenses and dependencies" |
| 32 | + @echo " make security - Run all security checks" |
| 33 | + @echo "" |
| 34 | + @echo "Tests:" |
| 35 | + @echo " make test - Run all tests" |
| 36 | + @echo " make test-lib - Run library tests only" |
| 37 | + @echo " make test-int - Run integration tests only" |
| 38 | + @echo "" |
| 39 | + @echo "Coverage:" |
| 40 | + @echo " make coverage - Generate code coverage report (HTML)" |
| 41 | + @echo " make coverage-text - Generate code coverage report (text)" |
| 42 | + @echo "" |
| 43 | + @echo "Development:" |
| 44 | + @echo " make dev - Auto-fix formatting and clippy, then test" |
| 45 | + @echo " make dev-test - Run tests in development mode" |
| 46 | + @echo "" |
| 47 | + @echo "Build:" |
| 48 | + @echo " make build - Make a release build" |
| 49 | + @echo " make run - Run the dummyjson-cli example" |
| 50 | + @echo "" |
| 51 | + @echo "Main Targets:" |
| 52 | + @echo " make check - Run all quality checks" |
| 53 | + @echo " make ci - Run CI pipeline" |
| 54 | + @echo " make all - Run all checks, tests, and build" |
| 55 | + |
| 56 | +# -------- Code formatting -------- |
| 57 | +.PHONY: fmt |
| 58 | + |
| 59 | +# Check code formatting |
| 60 | +fmt: |
| 61 | + cargo fmt --all -- --check |
| 62 | + |
| 63 | +# -------- Code quality -------- |
| 64 | +.PHONY: clippy lint |
| 65 | + |
| 66 | +# Run clippy linter |
| 67 | +clippy: |
| 68 | + cargo clippy --workspace --all-targets --all-features -- -D warnings -D clippy::perf |
| 69 | + |
| 70 | +# Check there are no compile time warnings |
| 71 | +lint: |
| 72 | + RUSTFLAGS="-D warnings" cargo check --workspace --all-targets --all-features |
| 73 | + |
| 74 | +# -------- Code safety checks -------- |
| 75 | +.PHONY: kani geiger safety |
| 76 | + |
| 77 | +# The Kani Rust Verifier for checking safety of the code |
| 78 | +kani: |
| 79 | + @command -v kani >/dev/null || \ |
| 80 | + (echo "Installing Kani verifier..." && \ |
| 81 | + cargo install --locked kani-verifier) |
| 82 | + cargo kani --workspace --all-features |
| 83 | + |
| 84 | +# Run Geiger scanner for unsafe code in dependencies |
| 85 | +geiger: |
| 86 | + $(call ensure_tool,cargo-geiger) |
| 87 | + cargo geiger --all-features |
| 88 | + |
| 89 | +# Run all code safety checks |
| 90 | +safety: clippy lint |
| 91 | + @echo "OK. Rust Safety Pipeline complete" |
| 92 | + |
| 93 | +# -------- Code security checks -------- |
| 94 | +.PHONY: deny security |
| 95 | + |
| 96 | +# Check licenses and dependencies |
| 97 | +deny: |
| 98 | + $(call ensure_tool,cargo-deny) |
| 99 | + cargo deny check |
| 100 | + |
| 101 | +# Run all security checks |
| 102 | +security: deny |
| 103 | + @echo "OK. Rust Security Pipeline complete" |
| 104 | + |
| 105 | +# -------- Development and auto fix -------- |
| 106 | +.PHONY: dev dev-fmt dev-clippy dev-test |
| 107 | + |
| 108 | +# Run tests in development mode |
| 109 | +dev-test: |
| 110 | + cargo test --workspace |
| 111 | + |
| 112 | +# Auto-fix code formatting |
| 113 | +dev-fmt: |
| 114 | + cargo fmt --all |
| 115 | + |
| 116 | +# Auto-fix clippy warnings |
| 117 | +dev-clippy: |
| 118 | + cargo clippy --workspace --all-targets --fix --allow-dirty |
| 119 | + |
| 120 | +# Auto-fix formatting and clippy warnings |
| 121 | +dev: dev-fmt dev-clippy dev-test |
| 122 | + |
| 123 | +# -------- Tests -------- |
| 124 | +.PHONY: test test-lib test-int |
| 125 | + |
| 126 | +# Run all tests |
| 127 | +test: |
| 128 | + cargo test --workspace |
| 129 | + |
| 130 | +# Run library tests only |
| 131 | +test-lib: |
| 132 | + cargo test -p rclib --lib |
| 133 | + |
| 134 | +# Run integration tests only |
| 135 | +test-int: |
| 136 | + cargo test -p rclib --test integration_tests |
| 137 | + |
| 138 | +# -------- Code coverage -------- |
| 139 | +.PHONY: coverage coverage-text |
| 140 | + |
| 141 | +# Generate code coverage report (HTML) |
| 142 | +coverage: |
| 143 | + @command -v cargo-llvm-cov >/dev/null || (echo "Installing cargo-llvm-cov..." && cargo install cargo-llvm-cov) |
| 144 | + cargo llvm-cov --workspace --html |
| 145 | + @echo "Coverage report generated at target/llvm-cov/html/index.html" |
| 146 | + |
| 147 | +# Generate code coverage report (text) |
| 148 | +coverage-text: |
| 149 | + @command -v cargo-llvm-cov >/dev/null || (echo "Installing cargo-llvm-cov..." && cargo install cargo-llvm-cov) |
| 150 | + cargo llvm-cov --workspace |
| 151 | + |
| 152 | +# -------- Build -------- |
| 153 | +.PHONY: build run |
| 154 | + |
| 155 | +# Make a release build using stable toolchain |
| 156 | +build: |
| 157 | + cargo +stable build --release |
| 158 | + |
| 159 | +# Run the dummyjson-cli example |
| 160 | +run: |
| 161 | + cargo run -p dummyjson-cli -- --help |
| 162 | + |
| 163 | +# -------- Main targets -------- |
| 164 | +.PHONY: check ci all |
| 165 | + |
| 166 | +# Run all quality checks |
| 167 | +check: fmt clippy lint test security |
| 168 | + |
| 169 | +# Run CI pipeline |
| 170 | +ci: check |
| 171 | + |
| 172 | +# Run all necessary quality checks and tests and then build the release binary |
| 173 | +all: check build |
| 174 | + @echo "All checks passed and release binary built successfully" |
0 commit comments