Skip to content

Instantly share code, notes, and snippets.

@heeh
Created December 5, 2025 14:42
Show Gist options
  • Select an option

  • Save heeh/0e6317e511168e194f2df945fd1aa90a to your computer and use it in GitHub Desktop.

Select an option

Save heeh/0e6317e511168e194f2df945fd1aa90a to your computer and use it in GitHub Desktop.
Rust pre-build Check (Strict)
#!/usr/bin/env bash
set -euo pipefail
echo "=== Enforced Rust Repo Checks ==="
# Require tools
required_tools=(
"cargo"
"cargo fmt"
"cargo clippy"
"cargo-audit"
"cargo-deny"
)
for tool in "${required_tools[@]}"; do
bin="${tool%% *}"
if ! command -v "$bin" >/dev/null 2>&1; then
echo "ERROR: Required tool '$tool' is not installed."
echo "Install it before running this script."
exit 1
fi
done
# 1. Formatting must be exact
echo "[1/6] Enforcing formatting"
cargo fmt --all -- --check
# 2. Clippy lints must be clean (no warnings)
echo "[2/6] Enforcing lint rules"
cargo clippy --all-targets --all-features -- -D warnings
# 3. Dependency security must pass
echo "[3/6] Enforcing dependency security (cargo-audit)"
cargo audit
# 4. Dependency + license policy must pass
echo "[4/6] Enforcing deny policy (cargo-deny)"
cargo deny check
# 5. Tests must pass
echo "[5/6] Running tests"
cargo test --all
# 6. Disallow unstable features in non-nightly repo (optional strict rule)
if grep -R "#![feature" -n src/ 2>/dev/null; then
echo "ERROR: Usage of unstable Rust features is forbidden in this repository."
exit 1
fi
echo "=== All rules enforced and passed. Proceeding to build ==="
cargo build --all
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment