# Cargo workspaces

> How bump finds crates, reads inherited versions, groups crates that share a version, edits dependency ranges and Cargo.lock, and mixes crates with npm packages.

bump releases Rust crates the same way as npm packages. It reads and edits `Cargo.toml` and `Cargo.lock` itself, so it does not need `cargo`.

## Find the crates

Without `packages` in the config, bump reads `[workspace]` in the root `Cargo.toml`:

- Each folder that `members` matches is a member. `exclude` removes folders.
- If the root `Cargo.toml` also has a `[package]`, the root crate is a member.
- Each path dependency of a member is a member too, when it is inside the root and `exclude` does not remove it. Cargo has the same rule.

Without `[workspace]`, bump looks only for a `Cargo.toml` in the root folder.

With `packages` in the config, bump looks for a `Cargo.toml` in each matched folder. See [`packages`](/config/#packages).

A virtual manifest, with `[workspace]` and no `[package]`, is not a crate. bump skips it with no warning.

## Versions

A crate's version is `[package] version`. A crate with no `version` has no version for bump: it is not released, but it still gets range edits.

A crate can inherit the version of its Cargo workspace:

```toml [crates/core/Cargo.toml]
[package]
name = "acme-core"
version.workspace = true
```

The version then comes from `[workspace.package] version` of the Cargo workspace root. bump finds that root like Cargo does:

1. the folder that `package.workspace` names, if it is set;
2. else the crate's own folder, if its `Cargo.toml` has `[workspace]`;
3. else the nearest parent folder, up to the git top level, whose `Cargo.toml` has `[workspace]`.

A repository can hold several Cargo workspaces. bump handles each one alone.

## Shared versions

Crates that inherit the version share one value. bump writes it in one place, so those crates must release together, as one unit.

In lockstep mode, all crates are one unit already. But every crate must have the same version, also the crates with their own `version`. This workspace has `acme-core` and `acme-cli` at the shared `0.3.0`, and `acme-macros` at its own `1.0.0`:

```console
$ bump patch --dryrun
FAIL All packages must share one version in lockstep mode:
│    acme-cli  0.3.0
│    acme-core  0.3.0
│    acme-macros  1.0.0
```

In independent mode, bump needs a group for the crates that share the version:

```console
$ bump patch --dryrun
FAIL Crates "acme-cli", "acme-core" share [workspace.package] version; name them in "groups", e.g. "groups": { "<name>": ["acme-cli"] }
```

bump finds the unit of the crates that inherit the version of one workspace:

1. If only one crate inherits the version, it needs no group.
2. Else, if a group lists any of them, all of them join that group. You need to list only one.
3. Else, if the workspace root `Cargo.toml` has a `[package]` that inherits the version, they form a group with the name of that root crate.
4. Else, bump stops with the error above.

### Example

The workspace root:

```toml [Cargo.toml]
[workspace]
members = ["crates/*"]
resolver = "2"

[workspace.package]
version = "0.3.0"
edition = "2024"

[workspace.dependencies]
acme-core = { path = "crates/core", version = "0.3.0" }
acme-macros = { path = "crates/macros", version = "1.0" }
```

`acme-core` and `acme-cli` inherit the version. `acme-core` depends on `acme-macros`, and `acme-cli` depends on `acme-core`, both through `{ workspace = true }`. One group is enough:

```jsonc [bump.json]
{
  "independent": true,
  "groups": {
    "acme": ["acme-core"]
  }
}
```

`acme-cli` joins the `acme` group. The tags are `acme@0.3.0` and `acme-macros@1.0.0`. After a change to `acme-macros`:

```console
$ bump minor
BUMP acme-macros 1.0.0 → 1.1.0  (changed)
BUMP acme 0.3.0 → 0.3.1  (dependent)
     acme-core, acme-cli
EDIT Cargo.toml workspace.dependencies["acme-core"] 0.3.0 → 0.3.1
EDIT Cargo.toml workspace.dependencies["acme-macros"] 1.0 → 1.1
DONE Committed 8dafdd4 release: acme-macros@1.1.0, acme@0.3.1
     Tagged acme-macros@1.1.0, acme@0.3.1
```

The release commit changes three files: `[workspace.package] version` and `[workspace.dependencies]` in `Cargo.toml`, the `version` in `crates/macros/Cargo.toml`, and `Cargo.lock`.

## Dependencies

An internal dependency is an entry whose crate is in the repository. These tables count:

| Table | Kind |
| --- | --- |
| `[dependencies]`, `[build-dependencies]` | runtime |
| `[target.<cfg>.dependencies]`, `[target.<cfg>.build-dependencies]` | runtime |
| `[dev-dependencies]`, `[target.<cfg>.dev-dependencies]` | dev |

A runtime dependency makes the crate a [dependent](/modes/#dependents). A dev dependency gets range edits only.

bump edits the range of each form:

- `acme-core = "0.3.0"`: the string.
- `acme-core = { path = "../core", version = "0.3.0" }`, or a `[dependencies.acme-core]` table: the `version` key.
- `acme-core = { workspace = true }`: the entry in `[workspace.dependencies]` of the Cargo workspace root, one time for all crates that use it. It is a runtime dependency if any crate uses it at runtime.
- `{ path = "../core" }` with no `version`: nothing to edit. It is still an internal dependency.
- `core = { package = "acme-core", … }`: the dependency is `acme-core`, not `core`.

The new range keeps the prefix and the precision of the old one, as in `1.0` to `1.1`. See [Range rewrite](/how-it-works/#range-rewrite).

An edit in `[workspace.dependencies]` belongs to no crate. Its `EDIT` line shows the file path, and its `package` in the [JSON result](/json/) is `null`.

## Cargo.lock

bump edits each `Cargo.lock` that git tracks. See [Lockfiles](/lockfiles/#cargolock) for the rules. From the example above:

```toml [Cargo.lock]
[[package]]
name = "acme-cli"
version = "0.3.1"
dependencies = [
 "acme-core",
]
```

## Publish

The [JSON result](/json/) gives `publish` for each released crate. It is `false` when the crate has `publish = false` or `publish = []`. With `publish.workspace = true`, bump reads `[workspace.package] publish` with the same rule. Here `acme-cli` has `publish = false`:

```json
{
  "name": "acme-cli",
  "ecosystem": "cargo",
  "dir": "crates/cli",
  "publish": false
}
```

bump releases a crate with `publish = false` like any other crate. Use the field to decide which crates to give to `cargo publish`.

## Changes in the workspace root

A file belongs to the deepest package folder that holds it. A virtual root `Cargo.toml` is no package, so the root folder belongs to no crate. A change to `[workspace.package]` or `[workspace.dependencies]`, such as a new `edition`, releases nothing by itself. A root crate, as in rule 3 above, owns every file that no deeper crate owns. See [Owners](/how-it-works/#owners).

## Mixed npm and Cargo

One repository can hold npm packages and crates. One folder can hold both, such as a Node addon written in Rust:

```json [package.json]
{
  "name": "@acme/fast",
  "version": "1.2.0",
  "main": "index.js"
}
```

```toml [Cargo.toml]
[package]
name = "acme-fast"
version = "1.2.0"
edition = "2024"

[lib]
crate-type = ["cdylib"]
```

With no config, bump finds both in the root folder. In lockstep mode they are one unit:

```console
$ bump minor
BUMP 1.2.0 → 1.3.0  (changed)
     @acme/fast, acme-fast
DONE Committed 2b490a0 v1.3.0
     Tagged v1.3.0
```

The release commit changes `package.json`, `Cargo.toml`, and `Cargo.lock`.

In independent mode, put the two in a [group](/groups/), so that they release together.

- Package names must be unique across both ecosystems. Two packages with the same name are an error.
- A dependency is internal only within its own ecosystem. An npm package cannot depend on a crate, so they make no [dependents](/modes/#dependents) across ecosystems.
