Rust Engineering Practices

Quick Reference Card

Cheat Sheet: Commands at a Glance

# ─── Build Scripts ───cargo build                          # Compiles build.rs first, then cratecargo build -vv                      # Verbose — shows build.rs output# ─── Cross-Compilation ───rustup target add x86_64-unknown-linux-muslcargo build --release --target x86_64-unknown-linux-muslcargo zigbuild --release --target x86_64-unknown-linux-gnu.2.17cross build --release --target aarch64-unknown-linux-gnu# ─── Benchmarking ───cargo bench                          # Run all benchmarkscargo bench -- parse                 # Run benchmarks matching "parse"cargo flamegraph -- --args           # Generate flamegraph from binaryperf record -g ./target/release/bin  # Record perf dataperf report                          # View perf data interactively# ─── Coverage ───cargo llvm-cov --html                # HTML reportcargo llvm-cov --lcov --output-path lcov.infocargo llvm-cov --workspace --fail-under-lines 80cargo tarpaulin --out Html           # Alternative tool# ─── Safety Verification ───cargo +nightly miri test             # Run tests under MiriMIRIFLAGS="-Zmiri-disable-isolation" cargo +nightly miri testvalgrind --leak-check=full ./target/debug/binaryRUSTFLAGS="-Zsanitizer=address" cargo +nightly test -Zbuild-std --target x86_64-unknown-linux-gnu# ─── Audit & Supply Chain ───cargo audit                          # Known vulnerability scancargo audit --deny warnings          # Fail CI on any advisorycargo deny check                     # License + advisory + ban + source checkscargo deny list                      # List all licenses in dep treecargo vet                            # Supply chain trust verificationcargo outdated --workspace           # Find outdated dependenciescargo semver-checks                  # Detect breaking API changescargo geiger                         # Count unsafe in dependency tree# ─── Binary Optimization ───cargo bloat --release --crates       # Size contribution per cratecargo bloat --release -n 20          # 20 largest functionscargo +nightly udeps --workspace     # Find unused dependenciescargo machete                        # Fast unused dep detectioncargo expand --lib module::name      # See macro expansionscargo msrv find                      # Discover minimum Rust versioncargo clippy --fix --workspace --allow-dirty  # Auto-fix lint warnings# ─── Compile-Time Optimization ───export RUSTC_WRAPPER=sccache         # Shared compilation cachesccache --show-stats                 # Cache hit statisticscargo nextest run                    # Faster test runnercargo nextest run --retries 2        # Retry flaky tests# ─── Platform Engineering ───cargo check --target thumbv7em-none-eabihf   # Verify no_std buildscargo build --target x86_64-pc-windows-gnu   # Cross-compile to Windowscargo xwin build --target x86_64-pc-windows-msvc  # MSVC ABI cross-compilecfg!(target_os = "linux")                    # Compile-time cfg (evaluates to bool)# ─── Release ───cargo release patch --dry-run        # Preview releasecargo release patch --execute        # Bump, commit, tag, publishcargo 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.