Rust Reference ยท Tools
Cargo workspaces
Reference for Cargo workspaces: members, shared Cargo.lock and target directory, workspace.dependencies, virtual manifests and commands that act on all crates.
A workspace is a set of packages (members) developed together. They share one Cargo.lock, one target/ directory and, optionally, dependency versions, package metadata and profiles. Workspaces keep large projects fast to build and consistent: a dependency compiled for one member is reused by the others.
The root Cargo.toml contains a [workspace] table. It can also be a virtual manifest, a root with no [package] of its own. This page is a read-only reference; the examples model a workspace with inline modules, since our editor compiles a single file.
[workspace] resolver = "3" members = ["crates/*"] [workspace.dependencies] serde = "1" [workspace.package] version = "0.3.0" edition = "2024"
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with io::stdin().read_line()), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with io::stdin().read_line()), it gets the next line from this box.
Syntax
| Key | Description |
|---|---|
[workspace] members |
Paths (globs allowed) of member packages. |
exclude |
Paths inside the workspace that must not become members. |
default-members |
Packages used when you run a command at the root with no -p. |
resolver |
Feature resolver version; "2" or "3" (edition 2024 uses 3). |
[workspace.package] |
Shared metadata that members inherit with version.workspace = true. |
[workspace.dependencies] |
One place for versions; members write dep.workspace = true (and may add features). |
[workspace.lints] |
Shared lint levels; members opt in with [lints] workspace = true. |
Commands: cargo build --workspace, cargo test -p core, cargo run -p cli, cargo check --workspace --exclude server.
Usage notes
- Any package whose directory is under the root and matched by
membersjoins automatically; path dependencies inside the root become members too. - A member can belong to only one workspace; nested workspaces are not supported.
- Profiles and
[patch]sections are read only from the root manifest. cargo publishpublishes one member at a time; publish dependencies first, and path dependencies need aversiontoo.- Running
cargo buildin a member directory builds that member, but still writes to the shared roottarget/. - Features are unified across members that are built together, which can enable a feature in one crate because of another.
resolver = "2"or later separates dev and build dependencies and target-specific ones. - Keep a virtual manifest for repositories that contain several equal-weight crates; keep a root package when one crate is the main product.