πŸ¦€/πŸ—οΈ/Introduction

Rust Engineering Practices β€” Beyond cargo build

Speaker Intro

  • Principal Firmware Architect in Microsoft SCHIE (Silicon and Cloud Hardware Infrastructure Engineering) team
  • Industry veteran with expertise in security, systems programming (firmware, operating systems, hypervisors), CPU and platform architecture, and C++ systems
  • Started programming in Rust in 2017 (@AWS EC2), and have been in love with the language ever since

A practical guide to the Rust toolchain features that most teams discover too late: build scripts, cross-compilation, benchmarking, code coverage, and safety verification with Miri and Valgrind. Each chapter uses concrete examples drawn from a real hardware-diagnostics codebase β€” a large multi-crate workspace β€” so every technique maps directly to production code.

How to Use This Book

This book is designed for self-paced study or team workshops. Each chapter is largely independent β€” read them in order or jump to the topic you need.

Difficulty Legend

SymbolLevelMeaning
🟒StarterStraightforward tools with clear patterns β€” useful on day one
🟑IntermediateRequires understanding of toolchain internals or platform concepts
πŸ”΄AdvancedDeep toolchain knowledge, nightly features, or multi-tool orchestration

Pacing Guide

PartChaptersEst. TimeKey Outcome
I β€” Build & Shipch01–023–4 hBuild metadata, cross-compilation, static binaries
II β€” Measure & Verifych03–054–5 hStatistical benchmarking, coverage gates, Miri/sanitizers
III β€” Harden & Optimizech06–106–8 hSupply chain security, release profiles, compile-time tools, no_std, Windows
IV β€” Integratech11–133–4 hProduction CI/CD pipeline, tricks, capstone exercise
16–21 hFull production engineering pipeline

Working Through Exercises

Each chapter contains πŸ‹οΈ exercises with difficulty indicators. Solutions are provided in expandable <details> blocks β€” try the exercise first, then check your work.

  • 🟒 exercises can often be done in 10–15 minutes
  • 🟑 exercises require 20–40 minutes and may involve running tools locally
  • πŸ”΄ exercises require significant setup and experimentation (1+ hour)

Prerequisites

ConceptWhere to learn it
Cargo workspace layoutRust Book ch14.3
Feature flagsCargo Reference β€” Features
#[cfg(test)] and basic testingRust Patterns ch12
unsafe blocks and FFI basicsRust Patterns ch10

Chapter Dependency Map

                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚ ch00     β”‚
                 β”‚  Intro   β”‚
                 β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”˜
        β”Œβ”€β”€β”€β”€β”€β”¬β”€β”€β”€β”¬β”€β”€β”΄β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”
        β–Ό     β–Ό   β–Ό     β–Ό      β–Ό      β–Ό
      ch01  ch03 ch04  ch05   ch06   ch09
      Build Bench Cov  Miri   Deps   no_std
        β”‚     β”‚    β”‚    β”‚      β”‚      β”‚
        β”‚     β””β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”˜      β”‚      β–Ό
        β”‚          β”‚           β”‚    ch10
        β–Ό          β–Ό           β–Ό   Windows
       ch02      ch07        ch07    β”‚
       Cross    RelProf     RelProf  β”‚
        β”‚          β”‚           β”‚     β”‚
        β”‚          β–Ό           β”‚     β”‚
        β”‚        ch08          β”‚     β”‚
        β”‚      CompTime        β”‚     β”‚
        β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”˜
                   β”‚
                   β–Ό
                 ch11
               CI/CD Pipeline
                   β”‚
                   β–Ό
                ch12 ─── ch13
              Tricks    Quick Ref

Read in any order: ch01, ch03, ch04, ch05, ch06, ch09 are independent. Read after prerequisites: ch02 (needs ch01), ch07–ch08 (benefit from ch03–ch06), ch10 (benefits from ch09). Read last: ch11 (ties everything together), ch12 (tricks), ch13 (reference).

Annotated Table of Contents

Part I β€” Build & Ship

#ChapterDifficultyDescription
1Build Scripts β€” build.rs in Depth🟒Compile-time constants, compiling C code, protobuf generation, system library linking, anti-patterns
2Cross-Compilation β€” One Source, Many Targets🟑Target triples, musl static binaries, ARM cross-compile, cross tool, cargo-zigbuild, GitHub Actions

Part II β€” Measure & Verify

#ChapterDifficultyDescription
3Benchmarking β€” Measuring What Matters🟑Criterion.rs, Divan, perf flamegraphs, PGO, continuous benchmarking in CI
4Code Coverage β€” Seeing What Tests Miss🟒cargo-llvm-cov, cargo-tarpaulin, grcov, Codecov/Coveralls CI integration
5Miri, Valgrind, and SanitizersπŸ”΄MIR interpreter, Valgrind memcheck/Helgrind, ASan/MSan/TSan, cargo-fuzz, loom

Part III β€” Harden & Optimize

#ChapterDifficultyDescription
6Dependency Management and Supply Chain Security🟒cargo-audit, cargo-deny, cargo-vet, cargo-outdated, cargo-semver-checks
7Release Profiles and Binary Size🟑Release profile anatomy, LTO trade-offs, cargo-bloat, cargo-udeps
8Compile-Time and Developer Tools🟑sccache, mold, cargo-nextest, cargo-expand, cargo-geiger, workspace lints, MSRV
9no_std and Feature VerificationπŸ”΄cargo-hack, core/alloc/std layers, custom panic handlers, testing no_std code
10Windows and Conditional Compilation🟑#[cfg] patterns, windows-sys/windows crates, cargo-xwin, platform abstraction

Part IV β€” Integrate

#ChapterDifficultyDescription
11Putting It All Together β€” A Production CI/CD Pipeline🟑GitHub Actions workflow, cargo-make, pre-commit hooks, cargo-dist, capstone
12Tricks from the Trenches🟑10 battle-tested patterns: deny(warnings) trap, cache tuning, dep dedup, RUSTFLAGS, more
13Quick Reference Cardβ€”Commands at a glance, 60+ decision table entries, further reading links