Skip to content

cargo.star

Bump Rust crate dependencies and rust-version in Cargo.toml files.

Edits are line-based, so comments, features and table layout stay as they were. Cargo.lock is not touched: follow with a run step such as cargo update -p <crate> when the lockfile is committed.

load("@fleet//cargo.star", "manifests", "set_dependency", "rust_version", "set_rust_version")
Function What it does
manifests Lists the repo's Cargo manifests.
set_dependency Sets a crate's version wherever a Cargo.toml already depends on it.
rust_version Reads the rust-version of a Cargo.toml.
set_rust_version Raises rust-version in every Cargo.toml that sets it, never lowering it.

manifests

manifests(repo)

Lists the repo's Cargo manifests.

Arguments

Name Description
repo The repo passed to change(repo).

Returns: The sorted paths of every Cargo.toml outside target directories.

Example

manifests(repo)
# returns ["Cargo.toml", "crates/core/Cargo.toml"]

Cargo.toml

[workspace]

crates/core/Cargo.toml

[package]

target/package/x/Cargo.toml

[package]

Source

set_dependency

set_dependency(repo, name, version)

Sets a crate's version wherever a Cargo.toml already depends on it.

A newer version already there is kept, so a campaign never lowers one.

Covers [dependencies], [dev-dependencies], [build-dependencies], [workspace.dependencies] and their [target.'...'.dependencies] forms, written as name = "1.0" or name = { version = "1.0", ... }. Dependencies given only by path or git have no version and are left alone.

Arguments

Name Description
repo The repo passed to change(repo).
name The crate name.
version The new version requirement, such as 1.0.210.

Returns: The list of paths that changed.

Example

set_dependency(repo, "serde", "1.0.210")
# returns ["Cargo.toml"]

Cargo.toml

[dependencies]
serde = { version = "1.0.100", features = ["derive"] }
tokio = "1.30"

[dev-dependencies]
serde = "1.0"

Cargo.toml

[dependencies]
serde = { version = "1.0.210", features = ["derive"] }
tokio = "1.30"

[dev-dependencies]
serde = "1.0.210"

Used in: cargo-dependency-bump

Source

rust_version

rust_version(repo, path = "Cargo.toml")

Reads the rust-version of a Cargo.toml.

Arguments

Name Description
repo The repo passed to change(repo).
path The Cargo.toml to read.

Returns: The version, such as 1.70, or None.

Example

rust_version(repo)
# returns "1.70"

Cargo.toml

[package]
name = "api"
rust-version = "1.70"

Source

set_rust_version

set_rust_version(repo, version)

Raises rust-version in every Cargo.toml that sets it, never lowering it.

Arguments

Name Description
repo The repo passed to change(repo).
version The minimum Rust version, such as 1.75.

Returns: The list of paths that changed.

Example

set_rust_version(repo, "1.75")
# returns ["Cargo.toml"]

Cargo.toml

[package]
name = "api"
rust-version = "1.70"

Cargo.toml

[package]
name = "api"
rust-version = "1.75"

Source