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 builds and environments (crucial for applications). - Build Profiles:
dev
(fast compiles, incremental by default) andrelease
(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
, andrustdoc
(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.