diff --git a/Cargo.lock b/Cargo.lock index c73ff17..00a1d1e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -94,6 +94,17 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a" +[[package]] +name = "cargo-rbmt" +version = "0.1.0" +dependencies = [ + "clap", + "serde", + "serde_json", + "toml", + "xshell", +] + [[package]] name = "cc" version = "1.2.44" @@ -881,17 +892,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "rust-bitcoin-maintainer-tools" -version = "0.1.0" -dependencies = [ - "clap", - "serde", - "serde_json", - "toml", - "xshell", -] - [[package]] name = "rustc-hash" version = "2.1.1" diff --git a/Cargo.toml b/Cargo.toml index ffc1f8d..d3fc372 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] members = [ "releases", - "tasks", + "cargo-rbmt", ] resolver = "2" diff --git a/tasks/CHANGELOG.md b/cargo-rbmt/CHANGELOG.md similarity index 100% rename from tasks/CHANGELOG.md rename to cargo-rbmt/CHANGELOG.md diff --git a/tasks/Cargo.toml b/cargo-rbmt/Cargo.toml similarity index 86% rename from tasks/Cargo.toml rename to cargo-rbmt/Cargo.toml index 739447d..646f491 100644 --- a/tasks/Cargo.toml +++ b/cargo-rbmt/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "rust-bitcoin-maintainer-tools" +name = "cargo-rbmt" version = "0.1.0" authors = ["Nick Johnson "] license = "CC0-1.0" @@ -7,7 +7,7 @@ edition = "2021" rust-version = "1.74.0" [[bin]] -name = "rbmt" +name = "cargo-rbmt" path = "src/main.rs" [dependencies] diff --git a/tasks/README.md b/cargo-rbmt/README.md similarity index 66% rename from tasks/README.md rename to cargo-rbmt/README.md index 72fdbd4..679154b 100644 --- a/tasks/README.md +++ b/cargo-rbmt/README.md @@ -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] @@ -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] @@ -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 = [ @@ -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"] @@ -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. @@ -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. diff --git a/tasks/justfile b/cargo-rbmt/justfile similarity index 100% rename from tasks/justfile rename to cargo-rbmt/justfile diff --git a/tasks/src/bench.rs b/cargo-rbmt/src/bench.rs similarity index 100% rename from tasks/src/bench.rs rename to cargo-rbmt/src/bench.rs diff --git a/tasks/src/docs.rs b/cargo-rbmt/src/docs.rs similarity index 100% rename from tasks/src/docs.rs rename to cargo-rbmt/src/docs.rs diff --git a/tasks/src/environment.rs b/cargo-rbmt/src/environment.rs similarity index 98% rename from tasks/src/environment.rs rename to cargo-rbmt/src/environment.rs index 4fe65d8..a7153fe 100644 --- a/tasks/src/environment.rs +++ b/cargo-rbmt/src/environment.rs @@ -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 { diff --git a/tasks/src/lint.rs b/cargo-rbmt/src/lint.rs similarity index 98% rename from tasks/src/lint.rs rename to cargo-rbmt/src/lint.rs index 1ee7e35..cf1e660 100644 --- a/tasks/src/lint.rs +++ b/cargo-rbmt/src/lint.rs @@ -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 { diff --git a/tasks/src/lock.rs b/cargo-rbmt/src/lock.rs similarity index 100% rename from tasks/src/lock.rs rename to cargo-rbmt/src/lock.rs diff --git a/tasks/src/main.rs b/cargo-rbmt/src/main.rs similarity index 89% rename from tasks/src/main.rs rename to cargo-rbmt/src/main.rs index bc8f5a7..5a0cf07 100644 --- a/tasks/src/main.rs +++ b/cargo-rbmt/src/main.rs @@ -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). @@ -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); diff --git a/tasks/src/test.rs b/cargo-rbmt/src/test.rs similarity index 99% rename from tasks/src/test.rs rename to cargo-rbmt/src/test.rs index c35c647..faf09ac 100644 --- a/tasks/src/test.rs +++ b/cargo-rbmt/src/test.rs @@ -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 { diff --git a/tasks/src/toolchain.rs b/cargo-rbmt/src/toolchain.rs similarity index 100% rename from tasks/src/toolchain.rs rename to cargo-rbmt/src/toolchain.rs