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 package metadata and validate how Cargo sees the workspace.

Inspect resolved metadata

Print package and dependency metadata as JSON.

bashANYcargometadataworkspace
bash
cargo metadata --format-version 1

Useful when diagnosing workspace membership, package names, targets, and dependency resolution.

Locate the active Cargo.toml

Show which manifest Cargo is using.

bashANYcargomanifestlocate-project
bash
cargo locate-project

Helpful when commands are being run from nested directories and the active manifest is unclear.

Locate the workspace root

Show the workspace root manifest path.

bashANYcargoworkspacemanifest
bash
cargo locate-project --workspace

Useful when troubleshooting commands that behave differently in a workspace root versus a package directory.

Build one workspace member

Select a specific package inside a workspace.

bashANYcargoworkspacepackage
bash
cargo build -p my-cli

Avoids accidentally building the wrong package or the whole workspace when only one member matters.

Run one package and one binary

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

bashANYcargorunworkspacebin
bash
cargo run -p my-cli --bin my-cli

Useful when multiple binaries or packages share similar names.

Clean one package target directory

Remove build artifacts for a package or target selection context.

bashANYcargocleanworkspace
bash
cargo clean -p my-cli

Sometimes stale artifacts or profile mismatches make a local clean rebuild useful.

Manifest repair snippets

Examples for frequent Cargo.toml issues in CLI projects.

Define workspace members explicitly

Basic workspace root snippet.

tomlANYcargoworkspacetoml
toml
[workspace]
members = ["crates/my-cli", "crates/common"]
resolver = "2"

When a package is missing from workspace commands, verify that it is listed under `members` or matched by a glob you intended.

Define an explicit binary target

Name and path a binary target clearly.

tomlANYcargobinmanifest
toml
[[bin]]
name = "my-cli"
path = "src/main.rs"

Useful if Cargo cannot find the binary target you expect or if the project contains multiple executables.

Declare optional dependencies with features

Avoid feature-resolution confusion.

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

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

Feature wiring mistakes in `Cargo.toml` are a common source of build confusion in CLI apps.

Recommended next

No recommendations yet.