Understanding rustc and cargo
Understanding rustc and cargo
While rustc is the underlying compiler, production Rust projects are almost exclusively managed with Cargo.
The Role of Cargo
Cargo handles four essential engineering responsibilities: 1. Dependency Resolution: Downloading, pinning, and compiling external crates from crates.io. 2. Build Orchestration: Invoking rustc with optimal optimization flags, link arguments, and target settings. 3. Test & Benchmark Execution: Discovering and executing unit tests, integration tests, and performance benchmarks. 4. Documentation Generation: Generating standard HTML documentation directly from doc-comments.
Common Cargo Commands
cargo check # Fast syntax and type verification without binary emission
cargo build # Compile debug build with symbols into target/debug
cargo run # Build and execute the binary
cargo test # Run automated test harness
cargo doc # Build HTML documentation for current project and dependencies