#!/usr/bin/env bash set -euo pipefail SCRIPT_DIR="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)" fail() { printf 'error: %s\n' "$*" >&2 exit 1 } if [[ -f "$SCRIPT_DIR/Cargo.toml" ]]; then ROOT="$SCRIPT_DIR" elif [[ -f "$SCRIPT_DIR/../Cargo.toml" ]]; then ROOT="$(cd -- "$SCRIPT_DIR/.." && pwd)" else fail "Cargo.toml not found next to the script or one directory above it" fi cd "$ROOT" command -v cargo >/dev/null 2>&1 || fail "Rust/Cargo is required" command -v rustc >/dev/null 2>&1 || fail "rustc is required" command -v python3 >/dev/null 2>&1 || fail "Python 3.10+ is required" command -v cc >/dev/null 2>&1 || fail "a C compiler/linker (cc) is required" python3 - <<'PY' import sys if sys.version_info < (3, 10): raise SystemExit("error: Python 3.10+ is required") PY [[ -f Cargo.toml ]] || fail "Cargo.toml not found; run this script from the RustProxy source tree" [[ -f scripts/preflight.py ]] || fail "scripts/preflight.py not found" [[ -f scripts/version.py ]] || fail "scripts/version.py not found" VERSION="$(python3 scripts/version.py)" printf 'Validating RustProxy %s\n' "$VERSION" python3 scripts/preflight.py python3 scripts/build/panel_css.py --check if [[ ! -f Cargo.lock ]]; then printf 'Cargo.lock not found - generating it...\n' cargo generate-lockfile fi cargo fmt --all -- --check cargo check --locked --all-targets cargo test --locked --all-targets cargo clippy --locked --all-targets -- -D warnings cargo build --release --locked if [[ -f "$ROOT/docker-agent/go.mod" && "${CHECK_DOCKER_AGENT:-1}" != "0" ]]; then command -v go >/dev/null 2>&1 || fail "Go is required to validate docker-agent (or set CHECK_DOCKER_AGENT=0)" ( cd "$ROOT/docker-agent" go test ./... go build ./... ) fi TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT/target}" if [[ "$TARGET_DIR" != /* ]]; then TARGET_DIR="$ROOT/$TARGET_DIR" fi BIN="$TARGET_DIR/release/rust-proxy" [[ -x "$BIN" ]] || fail "RustProxy binary was not produced: $BIN" ACTUAL_VERSION="$($BIN --version)" printf '%s\n' "$ACTUAL_VERSION" [[ "$ACTUAL_VERSION" == *"$VERSION"* ]] || fail "binary version does not match Cargo.toml ($VERSION)" printf 'Built RustProxy: %s\n' "$BIN" printf 'Cargo.lock retained: %s\n' "$ROOT/Cargo.lock"