Saltar a contenido

Week 1 - The Toolchain and the Compiler Pipeline

1.1 Conceptual Core

  • rustup is 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.
  • cargo is a build orchestrator on top of rustc. It is not the compiler. Almost every "cargo problem" is a rustc invocation problem in disguise. Learn to print the actual rustc command with cargo 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.lock discipline: committed for binaries, gitignored for libraries-and why (the dependency-resolver contract).
  • cargo tree -d for duplicate dependency detection; cargo metadata --format-version=1 | jq for 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"

  1. Create hello-audited. Pin a specific stable toolchain via rust-toolchain.toml.
  2. Build with - -release. Runobjdump -h target/release/hello-auditedand identify the.text,.rodata,.data,.bss, and.eh_frame` sections.
  3. Strip with strip -s and compare binary sizes. Now rebuild with RUSTFLAGS="-C strip=symbols -C panic=abort" and compare again.
  4. Document the size delta from each flag in NOTES.md. You should observe .eh_frame shrinking 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.toml that sets [profile.release] lto = "fat" and codegen-units = 1. Rebuild. Note compile-time cost vs. binary-size win.
  • Set up cargo-deny with a baseline deny.toml (license allowlist, advisory database). This file will grow each week.

Comments