From 6072a984f48c353ac630ea04c75ac11908d20f59 Mon Sep 17 00:00:00 2001 From: not-matthias Date: Tue, 12 May 2026 11:53:23 -0700 Subject: [PATCH] fix(cargo-codspeed): forward args after `--` to bench binaries `cargo codspeed run -- --exact ` previously failed with `unexpected argument '--exact' found` because the `Run` subcommand had no trailing-args field. Add a `bench_args` field with `last = true` and forward it to each bench command, mirroring `cargo bench` behavior. --- crates/cargo-codspeed/src/app.rs | 6 ++++++ crates/cargo-codspeed/src/run.rs | 3 +++ crates/cargo-codspeed/tests/simple-criterion.rs | 17 +++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/crates/cargo-codspeed/src/app.rs b/crates/cargo-codspeed/src/app.rs index 4233b276..841c1279 100644 --- a/crates/cargo-codspeed/src/app.rs +++ b/crates/cargo-codspeed/src/app.rs @@ -100,6 +100,7 @@ impl Cli { package_filters, bench_target_filters, measurement_mode, + bench_args, } => { let mode = measurement_mode.unwrap_or_default(); eprintln!("[cargo-codspeed] Measurement mode: {mode:?}\n"); @@ -109,6 +110,7 @@ impl Cli { package_filters, bench_target_filters, mode, + bench_args, ) } } @@ -211,6 +213,10 @@ enum Commands { /// Automatically set to `walltime` on macro runners #[arg(short = 'm', long = "measurement-mode", env = "CODSPEED_RUNNER_MODE")] measurement_mode: Option, + + /// Arguments forwarded to each benchmark binary after `--` + #[arg(last = true)] + bench_args: Vec, }, } diff --git a/crates/cargo-codspeed/src/run.rs b/crates/cargo-codspeed/src/run.rs index 39ad162b..44ec6d63 100644 --- a/crates/cargo-codspeed/src/run.rs +++ b/crates/cargo-codspeed/src/run.rs @@ -99,6 +99,7 @@ pub fn run_benches( package_filters: PackageFilters, bench_target_filters: BenchTargetFilters, measurement_mode: MeasurementMode, + bench_args: Vec, ) -> Result<()> { let build_mode = measurement_mode.into(); let codspeed_target_dir = get_codspeed_target_dir(metadata, build_mode); @@ -133,6 +134,8 @@ pub fn run_benches( command.arg(bench_name_filter); } + command.args(&bench_args); + command .status() .map_err(|e| anyhow!("failed to execute the benchmark process: {e}")) diff --git a/crates/cargo-codspeed/tests/simple-criterion.rs b/crates/cargo-codspeed/tests/simple-criterion.rs index 5dddb940..2ef010d0 100644 --- a/crates/cargo-codspeed/tests/simple-criterion.rs +++ b/crates/cargo-codspeed/tests/simple-criterion.rs @@ -122,6 +122,23 @@ fn test_criterion_build_and_run_filtered_by_name_single() { teardown(dir); } +#[test] +fn test_criterion_walltime_run_forwards_args_after_double_dash() { + let dir = setup(DIR, Project::Simple); + cargo_codspeed(&dir) + .args(["build", "-m", "walltime"]) + .assert() + .success(); + cargo_codspeed(&dir) + .args(["run", "-m", "walltime", "--", "--exact", "fib 20"]) + .assert() + .success() + .stdout(contains(FIB_BENCH_NAME)) + .stdout(contains(BUBBLE_SORT_BENCH_NAME).not()) + .stderr(contains("Finished running 2 benchmark suite(s)")); + teardown(dir); +} + #[test] fn test_criterion_cargo_bench_no_run() { let dir = setup(DIR, Project::Simple);