Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

23.14 Summary

Cargo is the cornerstone of the Rust development workflow, integrating build automation, dependency management, and various development tools into a single, cohesive system. Key takeaways include:

  • Unified Tooling: Combines build system and package manager roles, simplifying project setup compared to C/C++ ecosystems. cargo new often sets up a Git repository for the new package, aligning with common version control practices.
  • Core Commands: new, init, build, run, check, test, doc, publish.
  • Manifest: Cargo.toml defines package metadata, dependencies (other packages), features, and build profiles.
  • Reproducibility: Cargo.lock ensures consistent dependency package versions across local builds and within workspaces. For cargo install of application binaries, the --locked flag is crucial to use the package’s Cargo.lock for reproducible installations.
  • Build Profiles: dev (fast compiles, incremental by default) and release (optimized runtime, incremental off by default) with customization options for building package crates.
  • Extensibility: Supports custom subcommands and integration with tools like rustfmt, clippy, miri, and rustdoc (which documents package crates).
  • Workspaces: Efficiently manage multi-package projects with shared dependencies and build outputs. Individual packages within a workspace are published, not the workspace itself.
  • Distribution: Easily publish packages and install binary packages via Crates.io. Commit changes to version control before publishing new versions.

Mastering Cargo is essential for productive Rust development. Its conventions and capabilities foster consistency, reliability, and collaboration within the Rust ecosystem.