#!/usr/bin/env bash
# scripts/cargo-parallel — opt-in parallel rustc frontend for big rebuilds
#
# Wraps nightly cargo with -Z threads=16 for the parallel rustc frontend.
# B2 clean-check-server: 6.27s → 2.72s (-56%) on M5 Max.
# Requires: rustup toolchain install nightly

set -euo pipefail

ROOT_DIR="$(cd "$(dirname "$0")/.." && pwd)"
cd "$ROOT_DIR"

export CARGO_TARGET_DIR="${CARGO_TARGET_DIR:-$ROOT_DIR/target-nightly}"
export RUSTC_WRAPPER=""
export RUSTFLAGS="${RUSTFLAGS:-} -Z threads=16"

exec cargo +nightly "$@"
