Week 1 - The Toolchain and the Compiler Pipeline¶
1.1 Conceptual Core¶
rustupis a toolchain multiplexer, not a compiler. Understand the channel model (stable,beta,nightly, dated nightlies), components (rust-src,rust-analyzer,miri,rustc-dev), and target triples.cargois a build orchestrator on top ofrustc. It is not the compiler. Almost every "cargo problem" is arustcinvocation problem in disguise. Learn to print the actualrustccommand withcargo build -vv.- The compilation pipeline: source → lexer → parser → AST → HIR (high-level IR) → THIR → MIR (mid-level IR, where borrow checking runs) → LLVM IR → object code → linker. You will revisit this in Month 6; this week you only need to name the stages.
1.2 Mechanical Detail¶
rustc --print=cfg,rustc --print=target-list,rustc --print=sysroot. Learn these by muscle memory.- The
Cargo.lockdiscipline: committed for binaries, gitignored for libraries-and why (the dependency-resolver contract). cargo tree -dfor duplicate dependency detection;cargo metadata --format-version=1 | jqfor programmatic inspection.- The role of
build.rs: when it runs, what it can emit (cargo:rustc-link-lib,cargo:rerun-if-changed), and why it is a frequent supply-chain attack vector.
1.3 Lab-"Hello World, Audited"¶
- Create
hello-audited. Pin a specific stable toolchain viarust-toolchain.toml. - Build with - -release
. Runobjdump -h target/release/hello-auditedand identify the.text,.rodata,.data,.bss, and.eh_frame` sections. - Strip with
strip -sand compare binary sizes. Now rebuild withRUSTFLAGS="-C strip=symbols -C panic=abort"and compare again. - Document the size delta from each flag in
NOTES.md. You should observe.eh_frameshrinking dramatically when panic=abort is set-explain why.
1.4 Idiomatic & Clippy Drill¶
- Enable
#![deny(clippy::pedantic, clippy::nursery)]in your crate root. Half of the lints will fire on idiomatic-looking code. Read each one's rationale on the clippy lint index-not just the fix.
1.5 Production Hardening Slice¶
- Add a
.cargo/config.tomlthat sets[profile.release] lto = "fat"andcodegen-units = 1. Rebuild. Note compile-time cost vs. binary-size win. - Set up
cargo-denywith a baselinedeny.toml(license allowlist, advisory database). This file will grow each week.