set -euo pipefail
RED='\033[0;31m'
GREEN='\033[0;32m'
BOLD='\033[1m'
RESET='\033[0m'
pass() { echo -e " ${GREEN}✓${RESET} $1"; }
fail() { echo -e " ${RED}✗${RESET} $1"; exit 1; }
echo -e "${BOLD}Running local CI checks...${RESET}"
cargo fmt -- --check 2>/dev/null || fail "cargo fmt -- --check"
pass "fmt"
RUSTFLAGS="-Dwarnings" cargo clippy --quiet 2>&1 || fail "cargo clippy -Dwarnings"
pass "clippy"
cargo test --quiet 2>&1 || fail "cargo test"
pass "test"
if cargo deny --version &>/dev/null; then
cargo deny check 2>&1 || fail "cargo deny check"
pass "deny"
else
echo " - deny (skipped, cargo-deny not installed)"
fi
if rg -n 'libc::(SIGPIPE|SIG_DFL|signal)' --type rust src/ | rg -v '#\[cfg(unix)\]' | rg -v '// *#\[cfg' | rg -qv '^$'; then
violations=$(rg -n 'libc::(SIGPIPE|SIG_DFL|signal)' --type rust src/ 2>/dev/null || true)
if [ -n "$violations" ]; then
while IFS= read -r line; do
file=$(echo "$line" | cut -d: -f1)
lineno=$(echo "$line" | cut -d: -f2)
before=$(sed -n "$((lineno > 3 ? lineno - 3 : 1)),${lineno}p" "$file")
if ! echo "$before" | rg -q 'cfg\(unix\)'; then
fail "libc unix-only API used without #[cfg(unix)] at $file:$lineno"
fi
done <<< "$violations"
fi
pass "windows compat"
else
pass "windows compat"
fi
echo -e "${BOLD}${GREEN}All checks passed.${RESET}"