4.3 Summary
rustc
is the Rust compiler, analogous togcc
orclang
, but rarely invoked directly in larger projects.- Cargo is Rust’s integrated build system and package manager, comparable to combining Make/CMake with a package manager like apt, Conan, or vcpkg.
- Cargo handles project creation (
cargo new
), building (cargo build
), running (cargo run
), testing (cargo test
), and dependency management (cargo add
,Cargo.toml
). - Rust libraries are called crates, primarily distributed via crates.io.
- Cargo integrates with essential tools like
rustfmt
(formatting viacargo fmt
),clippy
(linting viacargo clippy
), and documentation generation (cargo doc
). - The
Cargo.toml
file defines project metadata and dependencies. - Cargo distinguishes between debug builds (fast compile, checks enabled) and release builds (optimized for performance).
This chapter provided a functional overview of rustc
and Cargo. You now have the basic tools to compile, run, and manage dependencies for Rust projects. For more advanced topics like workspaces, custom build configurations, publishing crates, and features, refer to Chapter 23 and the official documentation.
4.3.1 Further Resources
- The Cargo Book
- Rustc Book (less commonly needed for general development)