diff --git a/crates/criterion_compat/Cargo.toml b/crates/criterion_compat/Cargo.toml index d3dad315..28859bf7 100644 --- a/crates/criterion_compat/Cargo.toml +++ b/crates/criterion_compat/Cargo.toml @@ -20,7 +20,9 @@ keywords = ["codspeed", "benchmark", "criterion"] criterion = { package = "codspeed-criterion-compat-walltime", path = "./criterion_fork", version = "=5.0.1", default-features = false } codspeed = { path = "../codspeed", version = "=5.0.1" } colored = "3.0.0" -clap = { version = "4", default-features = false, features = ["std"] } +clap = { version = "4", default-features = false, features = [ + "std", +], optional = true } regex = { version = "1.5", default-features = false, features = ["std"] } futures = { version = "0.3", default-features = false, optional = true } @@ -31,7 +33,9 @@ tokio = { version = "1.39", default-features = false, features = [ async-std = { version = "1.12", optional = true } [features] -default = ["rayon", "plotters", "cargo_bench_support"] +default = ["cli", "rayon", "plotters", "cargo_bench_support"] +# Benchmark filtering from CLI arguments, which requires `clap`. +cli = ["dep:clap"] # Criterion.rs features async = ["futures", "criterion/async"] async_futures = ["criterion/async_futures", "futures/executor", "async"] diff --git a/crates/criterion_compat/src/compat/criterion.rs b/crates/criterion_compat/src/compat/criterion.rs index 8031930f..57716d0a 100644 --- a/crates/criterion_compat/src/compat/criterion.rs +++ b/crates/criterion_compat/src/compat/criterion.rs @@ -6,6 +6,7 @@ use criterion::{ profiler::Profiler, PlottingBackend, }; +#[cfg(feature = "cli")] use regex::Regex; use crate::{Bencher, BenchmarkFilter, BenchmarkGroup, BenchmarkId}; @@ -26,7 +27,6 @@ impl Criterion { env!("CARGO_PKG_VERSION"), ); - // Parse CLI arguments to extract filter let filter = Self::parse_filter(); Criterion { @@ -38,6 +38,12 @@ impl Criterion { } } + #[cfg(not(feature = "cli"))] + fn parse_filter() -> BenchmarkFilter { + BenchmarkFilter::AcceptAll + } + + #[cfg(feature = "cli")] fn parse_filter() -> BenchmarkFilter { use clap::{Arg, Command}; diff --git a/crates/divan_compat/Cargo.toml b/crates/divan_compat/Cargo.toml index 30aabd9c..22555441 100644 --- a/crates/divan_compat/Cargo.toml +++ b/crates/divan_compat/Cargo.toml @@ -21,8 +21,16 @@ keywords = ["codspeed", "benchmark", "divan"] codspeed = { path = "../codspeed", version = "=5.0.1" } divan = { package = "codspeed-divan-compat-walltime", path = "./divan_fork", version = "=5.0.1" } codspeed-divan-compat-macros = { version = "=5.0.1", path = './macros' } -regex = "1.11.3" -clap = { version = "4", default-features = false, features = ["std", "env"] } +regex = { version = "1.11.3", optional = true } +clap = { version = "4", default-features = false, features = [ + "std", + "env", +], optional = true } + +[features] +default = ["cli"] +# Benchmark filtering from CLI arguments, which requires `clap`. +cli = ["dep:clap", "dep:regex"] [[bench]] name = "basic_example" diff --git a/crates/divan_compat/src/compat/mod.rs b/crates/divan_compat/src/compat/mod.rs index 5fa6d558..0da6e05d 100644 --- a/crates/divan_compat/src/compat/mod.rs +++ b/crates/divan_compat/src/compat/mod.rs @@ -13,7 +13,9 @@ pub mod __private { } mod bench; +#[cfg(feature = "cli")] mod cli; +#[cfg(feature = "cli")] mod config; mod entry; mod uri; @@ -156,8 +158,10 @@ pub mod counter { } } use codspeed::codspeed::CodSpeed; +#[cfg(feature = "cli")] use config::Filter; use entry::AnyBenchEntry; +#[cfg(feature = "cli")] use regex::Regex; use std::{cell::RefCell, rc::Rc}; @@ -184,6 +188,7 @@ pub fn main() { // codspeed URI from entry metadata directly. // 3. Filtering + #[cfg(feature = "cli")] let should_run_benchmark_from_filters = { let mut command = cli::command(); let matches = command.get_matches_mut(); @@ -215,6 +220,8 @@ pub fn main() { } } }; + #[cfg(not(feature = "cli"))] + let should_run_benchmark_from_filters = |_uri: &str| true; // 4. Scan the tree and execute benchmarks let codspeed = Rc::new(RefCell::new(CodSpeed::new()));