Overview
cargo is the only interface a Rust developer uses day to day: it drives
rustc with the right flags, resolves and fetches
dependencies from crates.io, runs tests and benchmarks, invokes rustfmt and clippy, and
dispatches any cargo-* binary as a subcommand. This note covers the daily surface; the
project-model machinery — workspaces, features, profiles, build.rs, publishing —
has its own note in the build group:
Cargo in depth.
Key points
- The core loop:
cargo check(type-check without codegen — the fast feedback command, and what rust-analyzer runs),cargo build(debug by default),cargo run,cargo test,cargo build --releasewhen you actually need speed. cargo checkis the habit that matters: an order of magnitude faster than a full build because it stops before LLVM; the edit-check loop is where Rust development actually happens.- Dependency edits are commands, not file surgery:
cargo add serde --features derive,cargo remove,cargo update(respecting semver ranges),cargo treeto see the resolved graph andcargo tree -dto find duplicate versions. - Quality commands front the components:
cargo fmtandcargo clippyrun the rustup-installed rustfmt and clippy;cargo doc --openruns rustdoc. - The plugin convention: any binary named
cargo-fooonPATHis callable ascargo foo;cargo installputs binaries in~/.cargo/bin. The entire ecosystem of nextest, expand, audit, deny, dist rides on this. - Target selection:
--bin,--lib,--example,--test,--benchpick which target of the package to build;cargo run --example demois how examples double as runnable docs. - Output lives in
target/: shared per workspace, keyed by profile; it grows without bound —cargo clean, orcargo-sweep/sccacheon CI. - Offline & locked:
--locked(fail ifCargo.lockwould change — use in CI) and--offlinemake builds reproducible and network-free.
Examples
cargo new my-tool --bin # scaffold: src/main.rs + Cargo.toml
cargo check # the fast loop
cargo add axum tokio --features tokio/full
cargo tree -d # which deps pull two versions of the same crate?
cargo test -- --nocapture # let println! through
cargo build --release --locked # CI build
Related
- The Rust toolchain — parent catalog.
- Cargo in depth — the project model behind these commands: workspaces, features, profiles, publishing, lockfile semantics.
- rustc — what cargo is actually invoking.
- cargo-nextest — the drop-in upgrade for
cargo test. - go build, go run, go install — the Go counterpart of the daily loop.