cargo
rust package manager and build system
TLDR
Build project
SYNOPSIS
cargo command [options]
DESCRIPTION
cargo is the Rust package manager and build system. It handles dependency management, compiling packages, running tests, generating documentation, and publishing crates to crates.io.
The tool is essential for Rust development and comes bundled with Rust.
PARAMETERS
new name
Create new projectbuild [--release]
Compile projectrun
Build and runtest
Run testscheck
Check compilation without buildingadd crate
Add dependencyinstall crate
Install binary cratepublish
Publish to crates.iodoc [--open]
Build documentationclean
Remove build artifactsupdate
Update dependencies
FEATURES
- Dependency resolution
- Build management
- Test runner
- Documentation generator
- Benchmarking
- Publishing to crates.io
- Workspace support
- Custom build scripts
PROJECT STRUCTURE
├── Cargo.toml # Project manifest
├── Cargo.lock # Dependency lock file
└── src/
└── main.rs # Source code
CARGO.TOML
name = "myproject"
version = "0.1.0"
edition = "2021"
[dependencies]
serde = "1.0"
tokio = { version = "1.0", features = ["full"] }
WORKFLOW
cargo new myapp
# Create library
cargo new --lib mylib
# Build debug version
cargo build
# Build optimized release
cargo build --release
# Run project
cargo run
# Run tests
cargo test
# Check without building
cargo check
# Generate and open docs
cargo doc --open
CAVEATS
First build downloads dependencies (slow). Release builds significantly slower than debug. Cargo.lock should be committed for binaries (not libraries). Large projects have long compile times. Target directory can grow large.
HISTORY
Cargo was developed alongside Rust starting around 2013, becoming the standard build tool and package manager for the Rust ecosystem.
