Quick Reference Card
Cheat Sheet: Commands at a Glance
# ─── Build Scripts ───
cargo build # Compiles build.rs first, then crate
cargo build -vv # Verbose — shows build.rs output
# ─── Cross-Compilation ───
rustup target add x86_64-unknown-linux-musl
cargo build --release --target x86_64-unknown-linux-musl
cargo zigbuild --release --target x86_64-unknown-linux-gnu.2.17
cross build --release --target aarch64-unknown-linux-gnu
# ─── Benchmarking ───
cargo bench # Run all benchmarks
cargo bench -- parse # Run benchmarks matching "parse"
cargo flamegraph -- --args # Generate flamegraph from binary
perf record -g ./target/release/bin # Record perf data
perf report # View perf data interactively
# ─── Coverage ───
cargo llvm-cov --html # HTML report
cargo llvm-cov --lcov --output-path lcov.info
cargo llvm-cov --workspace --fail-under-lines 80
cargo tarpaulin --out Html # Alternative tool
# ─── Safety Verification ───
cargo +nightly miri test # Run tests under Miri
MIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri test
valgrind --leak-check=full ./target/debug/binary
RUSTFLAGS="-Zsanitizer=address" cargo +nightly test -Zbuild-std --target x86_64-unknown-linux-gnu
# ─── Audit & Supply Chain ───
cargo audit # Known vulnerability scan
cargo audit --deny warnings # Fail CI on any advisory
cargo deny check # License + advisory + ban + source checks
cargo deny list # List all licenses in dep tree
cargo vet # Supply chain trust verification
cargo outdated --workspace # Find outdated dependencies
cargo semver-checks # Detect breaking API changes
cargo geiger # Count unsafe in dependency tree
# ─── Binary Optimization ───
cargo bloat --release --crates # Size contribution per crate
cargo bloat --release -n 20 # 20 largest functions
cargo +nightly udeps --workspace # Find unused dependencies
cargo machete # Fast unused dep detection
cargo expand --lib module::name # See macro expansions
cargo msrv find # Discover minimum Rust version
cargo clippy --fix --workspace --allow-dirty # Auto-fix lint warnings
# ─── Compile-Time Optimization ───
export RUSTC_WRAPPER=sccache # Shared compilation cache
sccache --show-stats # Cache hit statistics
cargo nextest run # Faster test runner
cargo nextest run --retries 2 # Retry flaky tests
# ─── Platform Engineering ───
cargo check --target thumbv7em-none-eabihf # Verify no_std builds
cargo build --target x86_64-pc-windows-gnu # Cross-compile to Windows
cargo xwin build --target x86_64-pc-windows-msvc # MSVC ABI cross-compile
cfg!(target_os = "linux") # Compile-time cfg (evaluates to bool)
# ─── Release ───
cargo release patch --dry-run # Preview release
cargo release patch --execute # Bump, commit, tag, publish
cargo dist plan # Preview distribution artifacts
Decision Table: Which Tool When
| Goal | Tool | When to Use |
|---|---|---|
| Embed git hash / build info | build.rs | Binary needs traceability |
| Compile C code with Rust | cc crate in build.rs | FFI to small C libraries |
| Generate code from schemas | prost-build / tonic-build | Protobuf, gRPC, FlatBuffers |
| Link system library | pkg-config in build.rs | OpenSSL, libpci, systemd |
| Static Linux binary | --target x86_64-unknown-linux-musl | Container/cloud deployment |
| Target old glibc | cargo-zigbuild | RHEL 7, CentOS 7 compatibility |
| ARM server binary | cross or cargo-zigbuild | Graviton/Ampere deployment |
| Statistical benchmarks | Criterion.rs | Performance regression detection |
| Quick perf check | Divan | Development-time profiling |
| Find hot spots | cargo flamegraph / perf | After benchmark identifies slow code |
| Line/branch coverage | cargo-llvm-cov | CI coverage gates, gap analysis |
| Quick coverage check | cargo-tarpaulin | Local development |
| Rust UB detection | Miri | Pure-Rust unsafe code |
| C FFI memory safety | Valgrind memcheck | Mixed Rust/C codebases |
| Data race detection | TSan or Miri | Concurrent unsafe code |
| Buffer overflow detection | ASan | unsafe pointer arithmetic |
| Leak detection | Valgrind or LSan | Long-running services |
| Local CI equivalent | cargo-make | Developer workflow automation |
| Pre-commit checks | cargo-husky or git hooks | Catch issues before push |
| Automated releases | cargo-release + cargo-dist | Version management + distribution |
| Dependency auditing | cargo-audit / cargo-deny | Supply chain security |
| License compliance | cargo-deny (licenses) | Commercial / enterprise projects |
| Supply chain trust | cargo-vet | High-security environments |
| Find outdated deps | cargo-outdated | Scheduled maintenance |
| Detect breaking changes | cargo-semver-checks | Library crate publishing |
| Dependency tree analysis | cargo tree --duplicates | Dedup and trim dep graph |
| Binary size analysis | cargo-bloat | Size-constrained deployments |
| Find unused deps | cargo-udeps / cargo-machete | Trim compile time and size |
| LTO tuning | lto = true or "thin" | Release binary optimization |
| Size-optimized binary | opt-level = "z" + strip = true | Embedded / WASM / containers |
| Unsafe usage audit | cargo-geiger | Security policy enforcement |
| Macro debugging | cargo-expand | Derive / macro_rules debugging |
| Faster linking | mold linker | Developer inner loop |
| Compilation cache | sccache | CI and local build speed |
| Faster tests | cargo-nextest | CI and local test speed |
| MSRV compliance | cargo-msrv | Library publishing |
no_std library | #![no_std] + default-features = false | Embedded, UEFI, WASM |
| Windows cross-compile | cargo-xwin / MinGW | Linux → Windows builds |
| Platform abstraction | #[cfg] + trait pattern | Multi-OS codebases |
| Windows API calls | windows-sys / windows crate | Native Windows functionality |
| End-to-end timing | hyperfine | Whole-binary benchmarks, before/after comparison |
| Property-based testing | proptest | Edge case discovery, parser robustness |
| Snapshot testing | insta | Large structured output verification |
| Coverage-guided fuzzing | cargo-fuzz | Crash discovery in parsers |
| Concurrency model checking | loom | Lock-free data structures, atomic ordering |
| Feature combination testing | cargo-hack | Crates with multiple #[cfg] features |
| Fast UB checks (near-native) | cargo-careful | CI safety gate, lighter than Miri |
| Auto-rebuild on save | cargo-watch | Developer inner loop, tight feedback |
| Workspace documentation | cargo doc + rustdoc | API discovery, onboarding, doc-link CI |
| Reproducible builds | --locked + SOURCE_DATE_EPOCH | Release integrity verification |
| CI cache tuning | Swatinem/rust-cache@v2 | Build time reduction (cold → cached) |
| Workspace lint policy | [workspace.lints] in Cargo.toml | Consistent Clippy/compiler lints across all crates |
| Auto-fix lint warnings | cargo clippy --fix | Automated cleanup of trivial issues |
Further Reading
Generated as a companion reference — a companion to Rust Patterns and Type-Driven Correctness.
Version 1.3 — Added cargo-hack, cargo-careful, cargo-watch, cargo doc, reproducible builds, CI caching strategies, capstone exercise, and chapter dependency diagram for completeness.