Skip to content

Commit 32c0c8d

Browse files
committed
Merge #43: Add API subcommand
d0abec0 cargo-rbmt: extend api command with baseline arg (Nick Johnson) a105adc cargo-rbmt: add API command (Nick Johnson) dfcf054 cargo-rbmt: refactor get_packages to return tuples (Nick Johnson) Pull request description: This is a little more complex than the other `rbmt` commands. Up to now, `rbmt` has just orchestrated `cargo` commands, no other tool dependencies. But this patch adds an `api` command which takes over [the exposed API checks](https://github.com/rust-bitcoin/rust-bitcoin/blob/a4d9d21d4fa0c10099e356cd401eac668c042eca/contrib/check-for-api-changes.sh) and uses an internal dependency. The legacy scripts in rust-bitcoin use the `cargo-public-api` tool has a nice library crate, `public-api`. This patch uses the library crate under the hood for `rbmt`'s `api` command. The `api` command has two modes which I think models mostly the usage in rust-bitcoin. The standard `cargo rbmt api` generates exposed API files for all packages. It can use the global `-p` flag to filter which packages. It checks to make sure the feature flags are additive and if anything has changed. The second mode is `cargo rbmt api --baseline $REF` which takes a git ref and does a comparison. It fails if there are any breaking changes. ACKs for top commit: tcharding: ACK d0abec0 Tree-SHA512: 41a40828b63d890e3aedb7decd4277670350048db7eec27ac6d2a4a3e877046eeaf4beb74d72f65fe14f14ee2c1ba78308efa101bd87964dcecd3693a089c905
2 parents 9c82e2f + d0abec0 commit 32c0c8d

File tree

11 files changed

+423
-59
lines changed

11 files changed

+423
-59
lines changed

Cargo.lock

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cargo-rbmt/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ clap = { version = "4", features = ["derive"] }
1616
serde = { version = "1.0", features = ["derive"] }
1717
serde_json = "1.0"
1818
toml = "0.8"
19+
public-api = "0.47"

cargo-rbmt/README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,6 @@ To ensure your package works with the full range of declared dependency versions
115115

116116
The `lock` command generates and maintains these files for you. You can then use `--lock-file` with any command to test against either version set.
117117

118-
### Usage
119-
120-
**Generate/update lock files**
121-
122118
```bash
123119
cargo rbmt lock
124120
```
@@ -127,8 +123,6 @@ cargo rbmt lock
127123
2. Generate `Cargo-minimal.lock` with minimal versions across the entire dependency tree.
128124
3. Update `Cargo-recent.lock` with conservatively updated dependencies.
129125

130-
**Use a specific lock file**
131-
132126
```bash
133127
# Test with minimal versions.
134128
cargo rbmt --lock-file minimal test stable
@@ -143,6 +137,26 @@ cargo rbmt --lock-file minimal docs
143137

144138
When you specify `--lock-file`, the tool copies that lock file to `Cargo.lock` before running the command. This allows you to test your code against different dependency version constraints.
145139

140+
## API Checking
141+
142+
The `api` command helps maintain API stability by generating public API snapshots and checking for breaking changes. It uses the [public-api](https://github.com/Enselic/cargo-public-api) crate to analyze a crate's public interface.
143+
144+
```bash
145+
cargo rbmt api
146+
```
147+
148+
1. Generates API snapshots for each feature configuration (no-features, alloc-only, all-features).
149+
2. Validates that features are additive (enabling features only adds to the API, never removes).
150+
3. Checks for uncommitted changes to API files.
151+
152+
The generated API files are stored in `api/<package-name>/`.
153+
154+
```bash
155+
cargo rbmt api --baseline v0.1.0
156+
```
157+
158+
Compares the current API against a baseline git reference (tag, branch, or commit) to detect breaking changes.
159+
146160
## Workspace Integration
147161

148162
`cargo-rbmt` can simply be installed globally on a system or added as a dev-dependency to a package.

0 commit comments

Comments
 (0)