Rust CLI Cargo Config, Environment, Docs, and Debugging

Cargo configuration, environment variables, docs generation, and troubleshooting commands for Rust CLI development.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all

Cargo config

Set global or project-level Cargo configuration.

Create project-local Cargo config

Store configuration in the project under `.cargo/config.toml`.

tomlANYcargoconfigtoml
toml
[build]
target-dir = "target-fast"

[term]
verbose = true

Cargo supports configuration files and many keys under `.cargo/config.toml`.

Override config on one command

Pass a config key or file path at runtime.

bashANYcargoconfigcli
bash
cargo --config build.target-dir="target-ci" test

Cargo supports `--config KEY=VALUE` or a config path on the command line.

Set target dir by environment variable

Redirect build artifacts without editing config files.

bashANYcargoenvtarget-dir
bash
CARGO_TARGET_DIR=target-ci cargo build

Useful in CI, benchmarking, or separate debug and release workflows.

Environment variables

Control Cargo behavior and debugging through environment settings.

Enable Cargo debug logging

Emit tracing logs from Cargo itself.

bashANYcargoenvlogging
bash
CARGO_LOG=debug cargo build

`CARGO_LOG` is used for Cargo debug logging.

Change Cargo home

Use a non-default cache and install location.

bashANYcargoenvcargo-home
bash
CARGO_HOME=$HOME/.cargo-alt cargo install ripgrep

Cargo home stores downloaded dependencies and install state.

Show a backtrace on panic

Display stack traces from Rust panics.

bashANYrustpanicbacktrace
bash
RUST_BACKTRACE=1 cargo run

A basic but essential debugging technique for CLI apps.

Pass custom compiler flags

Inject compiler flags for one build.

bashANYrustrustflagscompiler
bash
RUSTFLAGS="-D warnings" cargo check

Handy for stricter CI or low-level compiler experiments.

Documentation

Generate docs and open them locally.

Build documentation

Generate docs for the package and dependencies.

bashANYcargodoc
bash
cargo doc

Cargo writes docs to `target/doc`.

Build docs and open in a browser

Generate docs then open the entry page.

bashANYcargodocopen
bash
cargo doc --open

Useful for reviewing APIs while developing.

Document only your crate

Skip building dependency docs.

bashANYcargodocno-deps
bash
cargo doc --no-deps

Often much faster for day-to-day crate docs.

Pass options to rustdoc

Forward arguments to rustdoc for advanced control.

bashANYcargorustdoc
bash
cargo rustdoc -- --document-private-items

Useful when exploring internal APIs or custom doc generation.

Inspection and troubleshooting

Commands that help explain workspace state and resolution.

Show the dependency tree

Inspect the dependency graph for the package.

bashANYcargotreedependencies
bash
cargo tree

Great for understanding duplicate versions and feature activation.

See reverse dependencies

Show what depends on a specific crate.

bashANYcargotreereverse
bash
cargo tree -i serde

Helpful when chasing why a transitive dependency exists.

Inspect feature activation

Show the tree with features included.

bashANYcargotreefeatures
bash
cargo tree -e features

Useful when debugging why a feature got enabled.

Generate or refresh Cargo.lock

Create a lockfile without building.

bashANYcargolockfile
bash
cargo generate-lockfile

Useful in automation or before commits when a lockfile is required.

Update dependency lockfile

Refresh locked dependency versions.

bashANYcargoupdatelockfile
bash
cargo update

Updates versions recorded in `Cargo.lock` according to manifest constraints.

Recommended next

No recommendations yet.