Rust CLI Troubleshooting: Manifest, Packages, and Workspaces

Commands and examples for debugging Cargo.toml issues, package selection mistakes, and workspace confusion in Rust CLI repos.

View
StandardDetailedCompact
Export
Copy the compact sheet, download it, or print it.
Download
`D` dense toggle · `C` copy all
## Manifest and metadata checks
Inspect resolved metadata
cargo metadata --format-version 1

# Print package and dependency metadata as JSON.

Locate the active Cargo.toml
cargo locate-project

# Show which manifest Cargo is using.

Locate the workspace root
cargo locate-project --workspace

# Show the workspace root manifest path.

Build one workspace member
cargo build -p my-cli

# Select a specific package inside a workspace.

Run one package and one binary
cargo run -p my-cli --bin my-cli

# Disambiguate package and binary target in a multi-package repo.

Clean one package target directory
cargo clean -p my-cli

# Remove build artifacts for a package or target selection context.

## Manifest repair snippets
Define workspace members explicitly
[workspace]
members = ["crates/my-cli", "crates/common"]
resolver = "2"

# Basic workspace root snippet.

Define an explicit binary target
[[bin]]
name = "my-cli"
path = "src/main.rs"

# Name and path a binary target clearly.

Declare optional dependencies with features
[dependencies]
clap = { version = "4", features = ["derive"] }
serde_json = { version = "1", optional = true }

[features]
default = []
json = ["dep:serde_json"]

# Avoid feature-resolution confusion.

Recommended next

No recommendations yet.