Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[workspace]
members = [
"releases",
"tasks",
"cargo-rbmt",
]
resolver = "2"
File renamed without changes.
4 changes: 2 additions & 2 deletions tasks/Cargo.toml → cargo-rbmt/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "rust-bitcoin-maintainer-tools"
name = "cargo-rbmt"
version = "0.1.0"
authors = ["Nick Johnson <[email protected]>"]
license = "CC0-1.0"
edition = "2021"
rust-version = "1.74.0"

[[bin]]
name = "rbmt"
name = "cargo-rbmt"
path = "src/main.rs"

[dependencies]
Expand Down
40 changes: 20 additions & 20 deletions tasks/README.md → cargo-rbmt/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ Maintainer tools for Rust-based projects in the Bitcoin domain. Built with [xshe

## Configuration

Configuration for `rbmt` is stored in `contrib/rbmt.toml`. The file can live at both the workspace root (e.g. `$ROOT/contrib/rbmt.toml`) as well as per-crate (e.g. `$ROOT/$CRATE/contrib/rbmt.toml`) within a repository.
Configuration for `rbmt` is stored in `rbmt.toml`. The file can live at both the workspace root (e.g. `$ROOT/rbmt.toml`) as well as per-package (e.g. `$ROOT/$PACKAGE/rbmt.toml`) within a repository.

### Lint

The `lint` command detects duplicate dependencies, but some may be unavoidable (e.g., during dependency updates where transitive dependencies haven't caught up). Configure the `[lint]` section to whitelist specific duplicates for a workspace (or a crate if only one crate in a repository).
The `lint` command detects duplicate dependencies, but some may be unavoidable (e.g., during dependency updates where transitive dependencies haven't caught up). Configure the `[lint]` section to whitelist specific duplicates for a workspace (or a package if only one package in a repository).

```toml
[lint]
Expand All @@ -20,7 +20,7 @@ allowed_duplicates = [

### Test

The `test` command can be configured to run feature matrix testing for your crate. Configure with the `contrib/rbmt.toml` file at the crate level.
The `test` command can be configured to run feature matrix testing for your package. Configure with the `rbmt.toml` file at the package level.

```toml
[test]
Expand All @@ -42,7 +42,7 @@ features_with_std = ["serde", "rand"]
features_without_std = ["serde", "rand"]

# Exact feature combinations to test.
# Use for crates that don't follow conventional `std` patterns.
# Use for packages that don't follow conventional `std` patterns.
# Each inner array is tested as-is with no automatic combinations.
# Example: [["serde", "rand"], ["rand"]] tests exactly those two combinations
exact_features = [
Expand All @@ -51,7 +51,7 @@ exact_features = [
]

# Features to test with an explicit `no-std` feature enabled.
# Only use if your crate has a `no-std` feature (rust-miniscript pattern).
# Only use if your package has a `no-std` feature (rust-miniscript pattern).
# Tests each feature with no-std, all pairs, and all together.
# Example: ["serde", "rand"] tests: no-std+serde, no-std+rand, no-std+serde+rand
features_with_no_std = ["serde", "rand"]
Expand All @@ -63,19 +63,19 @@ features_with_no_std = ["serde", "rand"]

## Lock Files

To ensure your crate works with the full range of declared dependency versions, `rbmt` requires two lock files in your repository.
To ensure your package works with the full range of declared dependency versions, `cargo-rbmt` requires two lock files in your repository.

* `Cargo-minimal.lock` - Minimum versions that satisfy your dependency constraints.
* `Cargo-recent.lock` - Recent/updated versions of dependencies.

The `rbmt lock` command generates and maintains these files for you. You can then use `--lock-file` with any command to test against either version set.
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.

### Usage

**Generate/update lock files**

```bash
rbmt lock
cargo rbmt lock
```

1. Verify that direct dependency versions aren't being bumped by transitive dependencies.
Expand All @@ -86,49 +86,49 @@ rbmt lock

```bash
# Test with minimal versions.
rbmt --lock-file minimal test stable
cargo rbmt --lock-file minimal test stable

# Test with recent versions.
rbmt --lock-file recent test stable
cargo rbmt --lock-file recent test stable

# Works with any command.
rbmt --lock-file minimal lint
rbmt --lock-file minimal docs
cargo rbmt --lock-file minimal lint
cargo rbmt --lock-file minimal docs
```

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.

## Workspace Integration

`rbmt` can simply be installed globally, or as a dev-dependency for more granular control of dependency versions.
`cargo-rbmt` can simply be installed globally on a system or added as a dev-dependency to a package.

### 1. Install globally
### 1. Install on system

Install the tool globally on your system with `cargo install`.

```bash
cargo install rust-bitcoin-maintainer-tools@0.1.0
cargo install cargo-rbmt@0.1.0
```

Then run from anywhere in your repository.
Then run from anywhere in your repository as a cargo subcommand. It can also be called directly as `cargo-rbmt`.

```bash
rbmt lint
cargo rbmt lint
```

### 2. Add as a dev-dependency

Add as a dev-dependency to a workspace member. This pins the tool version in your lockfile for reproducible builds.
Add as a dev-dependency to a workspace member. This pins the tool version in your lockfile for reproducible builds. But this also means that `cargo-rbmt` dependencies could influence version resolution for the workspace.

```toml
[dev-dependencies]
rust-bitcoin-maintainer-tools = "0.1.0"
cargo-rbmt = "0.1.0"
```

Then run via cargo.

```bash
cargo run --bin rbmt -- lint
cargo run --bin cargo-rbmt -- lint
```

It might be worth wrapping in an [xtask](https://github.com/matklad/cargo-xtask) package for a clean interface.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion tasks/src/environment.rs → cargo-rbmt/src/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use xshell::{cmd, Shell};
const LOG_LEVEL_ENV_VAR: &str = "RBMT_LOG_LEVEL";

/// Path to the RBMT configuration file relative to workspace/crate root.
pub const CONFIG_FILE_PATH: &str = "contrib/rbmt.toml";
pub const CONFIG_FILE_PATH: &str = "rbmt.toml";

/// Check if we're in quiet mode via environment variable.
pub fn is_quiet_mode() -> bool {
Expand Down
2 changes: 1 addition & 1 deletion tasks/src/lint.rs → cargo-rbmt/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::environment::{get_crate_dirs, quiet_println, CONFIG_FILE_PATH};
use crate::quiet_cmd;
use crate::toolchain::{check_toolchain, Toolchain};

/// Lint configuration loaded from contrib/rbmt.toml.
/// Lint configuration loaded from rbmt.toml.
#[derive(Debug, serde::Deserialize, Default)]
#[serde(default)]
struct Config {
Expand Down
File renamed without changes.
12 changes: 10 additions & 2 deletions tasks/src/main.rs → cargo-rbmt/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use lock::LockFile;
use toolchain::Toolchain;

#[derive(Parser)]
#[command(name = "rbmt")]
#[command(name = "cargo-rbmt")]
#[command(about = "Rust Bitcoin Maintainer Tools", long_about = None)]
struct Cli {
/// Lock file to use for dependencies (defaults to recent).
Expand Down Expand Up @@ -51,7 +51,15 @@ enum Commands {
}

fn main() {
let cli = Cli::parse();
// Cargo automatically adds the subcommand name as an extra argument.
// `cargo rbmt test` becomes `cargo-rbmt rbmt test`, so filter it out.
let args = std::env::args()
.enumerate()
.filter(|(i, arg)| !(*i == 1 && arg == "rbmt"))
.map(|(_, arg)| arg);

let cli = Cli::parse_from(args);

let sh = Shell::new().unwrap();
configure_log_level(&sh);
change_to_repo_root(&sh);
Expand Down
2 changes: 1 addition & 1 deletion tasks/src/test.rs → cargo-rbmt/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use serde::Deserialize;
use std::path::Path;
use xshell::Shell;

/// Test configuration loaded from contrib/rbmt.toml.
/// Test configuration loaded from rbmt.toml.
#[derive(Debug, Deserialize, Default)]
#[serde(default)]
struct Config {
Expand Down
File renamed without changes.