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
Create project-local Cargo config
[build]
target-dir = "target-fast"

[term]
verbose = true

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

Override config on one command
cargo --config build.target-dir="target-ci" test

# Pass a config key or file path at runtime.

Set target dir by environment variable
CARGO_TARGET_DIR=target-ci cargo build

# Redirect build artifacts without editing config files.

## Environment variables
Enable Cargo debug logging
CARGO_LOG=debug cargo build

# Emit tracing logs from Cargo itself.

Change Cargo home
CARGO_HOME=$HOME/.cargo-alt cargo install ripgrep

# Use a non-default cache and install location.

Show a backtrace on panic
RUST_BACKTRACE=1 cargo run

# Display stack traces from Rust panics.

Pass custom compiler flags
RUSTFLAGS="-D warnings" cargo check

# Inject compiler flags for one build.

## Documentation
Build documentation
cargo doc

# Generate docs for the package and dependencies.

Build docs and open in a browser
cargo doc --open

# Generate docs then open the entry page.

Document only your crate
cargo doc --no-deps

# Skip building dependency docs.

Pass options to rustdoc
cargo rustdoc -- --document-private-items

# Forward arguments to rustdoc for advanced control.

## Inspection and troubleshooting
Show the dependency tree
cargo tree

# Inspect the dependency graph for the package.

See reverse dependencies
cargo tree -i serde

# Show what depends on a specific crate.

Inspect feature activation
cargo tree -e features

# Show the tree with features included.

Generate or refresh Cargo.lock
cargo generate-lockfile

# Create a lockfile without building.

Update dependency lockfile
cargo update

# Refresh locked dependency versions.

Recommended next

No recommendations yet.