Skip to content

Commit 3a5f20a

Browse files
committed
chore: Makefile
Signed-off-by: Alexis Delain <quiet.syscall@proton.me>
1 parent 1a69497 commit 3a5f20a

File tree

2 files changed

+307
-0
lines changed

2 files changed

+307
-0
lines changed

Makefile

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
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"

deny.toml

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
# cargo-deny configuration for security, licenses, bans, and sources.
2+
# Docs: https://embarkstudios.github.io/cargo-deny/
3+
4+
################################################################################
5+
# Dependency graph construction
6+
################################################################################
7+
[graph]
8+
# Optionally restrict targets to check (kept commented by default).
9+
# targets = [
10+
# "x86_64-unknown-linux-gnu",
11+
# { triple = "wasm32-unknown-unknown", features = ["atomics"] },
12+
# ]
13+
# all-features = true
14+
# exclude-dev = true
15+
# exclude-unpublished = false
16+
17+
################################################################################
18+
# Security advisories (RustSec)
19+
################################################################################
20+
[advisories]
21+
# Local clone/cache of the RustSec advisory DB
22+
db-path = ".cargo/advisory-db"
23+
# Upstream advisory DBs to use
24+
db-urls = ["https://github.com/RustSec/advisory-db"]
25+
26+
# How to treat "unmaintained" advisories:
27+
# one of: "all" | "workspace" | "transitive" | "none"
28+
# (This is NOT a severity level; it scopes where the rule applies.)
29+
unmaintained = "workspace"
30+
31+
# Yanked crate versions still use classic lint levels.
32+
# one of: "deny" | "warn" | "allow"
33+
yanked = "warn"
34+
35+
# List of advisory IDs to ignore (RUSTSEC-YYYY-XXXX, etc.)
36+
ignore = [
37+
# "RUSTSEC-0000-0000",
38+
]
39+
40+
# Note:
41+
# - Modern cargo-deny versions treat vulnerabilities as hard errors by default.
42+
# - If you must silence a specific vuln, add its ID to `ignore` above.
43+
44+
################################################################################
45+
# License policy
46+
################################################################################
47+
[licenses]
48+
# Allow-list of SPDX license IDs
49+
allow = [
50+
"MIT",
51+
"Apache-2.0",
52+
"Apache-2.0 WITH LLVM-exception",
53+
"BSD-2-Clause",
54+
"BSD-3-Clause",
55+
"BSL-1.0",
56+
"ISC",
57+
"Unicode-3.0",
58+
"CDLA-Permissive-2.0",
59+
"MPL-2.0",
60+
"Zlib"
61+
]
62+
63+
# Confidence threshold (0.0..1.0) for license text detection
64+
confidence-threshold = 0.8
65+
66+
# Per-crate exceptions (license(s) allowed only for a specific crate/version)
67+
exceptions = [
68+
# { name = "some-crate", version = "*", allow = ["Zlib"] },
69+
]
70+
71+
# Private workspace crates handling
72+
[licenses.private]
73+
# If true, ignore unpublished/private workspace crates for license checks
74+
ignore = false
75+
# Private registries considered "published" for the rule above
76+
registries = [
77+
# "https://example.com/registry",
78+
]
79+
80+
################################################################################
81+
# Duplicate versions / wildcards / bans
82+
################################################################################
83+
[bans]
84+
# Multiple versions of the same crate in the graph
85+
multiple-versions = "warn"
86+
87+
# Version wildcards like "*"
88+
wildcards = "allow"
89+
90+
# How to highlight in dot graphs when multiple versions are present
91+
# "lowest-version" | "simplest-path" | "all"
92+
highlight = "all"
93+
94+
# Default lint level for `default-features` on workspace deps (requires the
95+
# `workspace-dependencies` feature in cargo-deny to take effect)
96+
workspace-default-features = "allow"
97+
98+
# Allow-list of specific crates (use carefully)
99+
allow = [
100+
# { name = "ansi_term", version = "=0.11.0" },
101+
]
102+
103+
# Deny-list of specific crates (optionally with version ranges/wrappers)
104+
deny = [
105+
# { name = "some-bad-crate", version = "*", wrappers = [] },
106+
]
107+
108+
# Skip specific crate versions when checking for duplicates
109+
skip = [
110+
# { name = "ansi_term", version = "=0.11.0" },
111+
]
112+
113+
# Remove a crate subtree entirely from the graph for checks (stronger than skip)
114+
skip-tree = [
115+
# { name = "ansi_term", version = "=0.11.0", depth = 1 },
116+
]
117+
118+
################################################################################
119+
# Allowed sources (registries and git)
120+
################################################################################
121+
[sources]
122+
# Non-allowed registry encountered
123+
unknown-registry = "warn"
124+
125+
# Non-allowed git source encountered
126+
unknown-git = "warn"
127+
128+
# Allowed crate registries (empty list => none allowed)
129+
# Default crates.io index:
130+
allow-registry = ["https://github.com/rust-lang/crates.io-index"]
131+
132+
# Allowed git repositories (empty => none)
133+
allow-git = []

0 commit comments

Comments
 (0)