4.3 Summary

  • rustc is the Rust compiler, analogous to gcc or clang, 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 via cargo fmt), clippy (linting via cargo 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