$ show RalfJung/cargo-careful
cargo-careful is a Rust CLI cargo subcommand that re-runs a user's build/test/run under a specially constructed Rust toolchain. The binary in src/main.rs expects to be invoked as `cargo careful <subcommand>`, supports run, test, build, rustc, nextest, and setup, and locates the active rustc version and host target. It finds the rust-src rustup component (offering to install it interactively unless running in CI), builds a per-target/per-sanitizer sysroot in a user cache directory via the rustc_build_sysroot library, then invokes cargo with that custom sysroot and encoded RUSTFLAGS so both the sysroot and the user's crate get extra runtime checking.
The LLM identified 2 files worth highlighting for reuse:
A self-contained collection of general-purpose CLI and process utilities: an iterator that extracts `--flag value` and `--flag=value` pairs from env::args() while stopping at `--`, a count helper for repeated flags, an ask-to-run helper that disables prompts in CI, and an exec helper that uses POSIX exec on Unix and falls back to spawning on other platforms. It only depends on std and can be lifted into another Rust CLI project with minimal changes.
The `sanitizer_supported` function is a clean, isolated pattern for querying rustc target capabilities at runtime: it invokes `rustc --print target-spec-json --target <target>`, parses the JSON with serde_json, and checks the `supported-sanitizers` array. This is directly reusable by any tool that needs to conditionally enable compiler features based on target support.