From d92c6e51d2a3fd2006bcf6e19aea665c3319c835 Mon Sep 17 00:00:00 2001 From: Chris Fields Date: Thu, 18 Jun 2026 15:46:15 -0500 Subject: [PATCH] Make CLI/logging dependencies optional behind a `cli` feature clap, tracing, and tracing-subscriber are used only by the align_benchmark binary (src/bin/), but were non-optional dependencies, so every library consumer inherited the full CLI/logging dependency tree. Make all four binary-only crates optional and gate them behind features: - `cli` enables clap + tracing + tracing-subscriber - `mimalloc-alloc` enables mimalloc (now via `dep:` syntax) Both are kept in `default` so `cargo build`/`cargo run` still produce the benchmark binary unchanged, and the binary declares `required-features = ["cli"]` so library-only builds (`--no-default-features`) skip it. Library consumers can now depend with `default-features = false` to get a clean dependency graph (verified: `cargo tree --no-default-features` no longer lists clap/tracing/mimalloc). Co-Authored-By: Claude Opus 4.8 --- Cargo.toml | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index a8e019e..d80ee9d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,14 +5,21 @@ edition = "2024" rust-version = "1.91" [features] -default = ["mimalloc-alloc"] -mimalloc-alloc = ["mimalloc"] +# `cli` pulls in everything the `align_benchmark` binary needs (argument +# parsing + logging). It is in `default` so `cargo build`/`cargo run` keep +# producing the benchmark binary as before. Library consumers should depend +# with `default-features = false` to avoid the CLI/logging dependency tree. +default = ["cli", "mimalloc-alloc"] +cli = ["dep:clap", "dep:tracing", "dep:tracing-subscriber"] +mimalloc-alloc = ["dep:mimalloc"] [dependencies] -clap = { version = "4", features = ["derive"] } +# All four are binary-only (used solely under src/bin/), so they are optional +# and enabled via features rather than imposed on library consumers. +clap = { version = "4", features = ["derive"], optional = true } mimalloc = { version = "0.1", optional = true } -tracing = "0.1" -tracing-subscriber = "0.3" +tracing = { version = "0.1", optional = true } +tracing-subscriber = { version = "0.3", optional = true } [profile.release] lto = true @@ -22,3 +29,6 @@ panic = "abort" [[bin]] name = "align_benchmark" path = "src/bin/align_benchmark.rs" +# The binary needs the CLI dependency stack; skip it for library-only builds +# (e.g. `--no-default-features`). +required-features = ["cli"]