Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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 CardCommands at a glance, 60+ decision table entries, further reading links