🦀/🏗️/13. Quick Reference Card

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

GoalToolWhen to Use
Embed git hash / build infobuild.rsBinary needs traceability
Compile C code with Rustcc crate in build.rsFFI to small C libraries
Generate code from schemasprost-build / tonic-buildProtobuf, gRPC, FlatBuffers
Link system librarypkg-config in build.rsOpenSSL, libpci, systemd
Static Linux binary--target x86_64-unknown-linux-muslContainer/cloud deployment
Target old glibccargo-zigbuildRHEL 7, CentOS 7 compatibility
ARM server binarycross or cargo-zigbuildGraviton/Ampere deployment
Statistical benchmarksCriterion.rsPerformance regression detection
Quick perf checkDivanDevelopment-time profiling
Find hot spotscargo flamegraph / perfAfter benchmark identifies slow code
Line/branch coveragecargo-llvm-covCI coverage gates, gap analysis
Quick coverage checkcargo-tarpaulinLocal development
Rust UB detectionMiriPure-Rust unsafe code
C FFI memory safetyValgrind memcheckMixed Rust/C codebases
Data race detectionTSan or MiriConcurrent unsafe code
Buffer overflow detectionASanunsafe pointer arithmetic
Leak detectionValgrind or LSanLong-running services
Local CI equivalentcargo-makeDeveloper workflow automation
Pre-commit checkscargo-husky or git hooksCatch issues before push
Automated releasescargo-release + cargo-distVersion management + distribution
Dependency auditingcargo-audit / cargo-denySupply chain security
License compliancecargo-deny (licenses)Commercial / enterprise projects
Supply chain trustcargo-vetHigh-security environments
Find outdated depscargo-outdatedScheduled maintenance
Detect breaking changescargo-semver-checksLibrary crate publishing
Dependency tree analysiscargo tree --duplicatesDedup and trim dep graph
Binary size analysiscargo-bloatSize-constrained deployments
Find unused depscargo-udeps / cargo-macheteTrim compile time and size
LTO tuninglto = true or "thin"Release binary optimization
Size-optimized binaryopt-level = "z" + strip = trueEmbedded / WASM / containers
Unsafe usage auditcargo-geigerSecurity policy enforcement
Macro debuggingcargo-expandDerive / macro_rules debugging
Faster linkingmold linkerDeveloper inner loop
Compilation cachesccacheCI and local build speed
Faster testscargo-nextestCI and local test speed
MSRV compliancecargo-msrvLibrary publishing
no_std library#![no_std] + default-features = falseEmbedded, UEFI, WASM
Windows cross-compilecargo-xwin / MinGWLinux → Windows builds
Platform abstraction#[cfg] + trait patternMulti-OS codebases
Windows API callswindows-sys / windows crateNative Windows functionality
End-to-end timinghyperfineWhole-binary benchmarks, before/after comparison
Property-based testingproptestEdge case discovery, parser robustness
Snapshot testinginstaLarge structured output verification
Coverage-guided fuzzingcargo-fuzzCrash discovery in parsers
Concurrency model checkingloomLock-free data structures, atomic ordering
Feature combination testingcargo-hackCrates with multiple #[cfg] features
Fast UB checks (near-native)cargo-carefulCI safety gate, lighter than Miri
Auto-rebuild on savecargo-watchDeveloper inner loop, tight feedback
Workspace documentationcargo doc + rustdocAPI discovery, onboarding, doc-link CI
Reproducible builds--locked + SOURCE_DATE_EPOCHRelease integrity verification
CI cache tuningSwatinem/rust-cache@v2Build time reduction (cold → cached)
Workspace lint policy[workspace.lints] in Cargo.tomlConsistent Clippy/compiler lints across all crates
Auto-fix lint warningscargo clippy --fixAutomated cleanup of trivial issues

Further Reading

TopicResource
Cargo build scriptsCargo Book — Build Scripts
Cross-compilationRust Cross-Compilation
cross toolcross-rs/cross
cargo-zigbuildcargo-zigbuild docs
Criterion.rsCriterion User Guide
DivanDivan docs
cargo-llvm-covcargo-llvm-cov
cargo-tarpaulintarpaulin docs
MiriMiri GitHub
Sanitizers in Rustrustc Sanitizer docs
cargo-makecargo-make book
cargo-releasecargo-release docs
cargo-distcargo-dist docs
Profile-guided optimizationRust PGO guide
Flamegraphscargo-flamegraph
cargo-denycargo-deny docs
cargo-vetcargo-vet docs
cargo-auditcargo-audit
cargo-bloatcargo-bloat
cargo-udepscargo-udeps
cargo-geigercargo-geiger
cargo-semver-checkscargo-semver-checks
cargo-nextestnextest docs
sccachesccache
mold linkermold
cargo-msrvcargo-msrv
LTOrustc Codegen Options
Cargo ProfilesCargo Book — Profiles
no_stdRust Embedded Book
windows-sys cratewindows-rs
cargo-xwincargo-xwin docs
cargo-hackcargo-hack
cargo-carefulcargo-careful
cargo-watchcargo-watch
Rust CI cacheSwatinem/rust-cache
Rustdoc bookRustdoc Book
Conditional compilationRust Reference — cfg
Embedded RustAwesome Embedded Rust
hyperfinehyperfine
proptestproptest
instainsta snapshot testing
cargo-fuzzcargo-fuzz
loomloom concurrency testing

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.