From c8213e33e17acf2cd2ff11e06a6ea69abe1a8db3 Mon Sep 17 00:00:00 2001 From: Adrien Cacciaguerra Date: Fri, 9 Feb 2024 13:10:54 +0100 Subject: [PATCH 1/3] feat(cargo-codspeed): build all benches in a single cargo build --- crates/cargo-codspeed/src/build.rs | 53 +++++++++++++++--------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/crates/cargo-codspeed/src/build.rs b/crates/cargo-codspeed/src/build.rs index bdd05b4..9f57cd4 100644 --- a/crates/cargo-codspeed/src/build.rs +++ b/crates/cargo-codspeed/src/build.rs @@ -17,7 +17,7 @@ fn get_compile_options( config: &Config, features: &Option>, package: &Package, - bench: &str, + benches: Vec<&str>, ) -> Result { let mut compile_opts = CompileOptions::new(config, CompileMode::Build)?; compile_opts.spec = Packages::Packages(vec![package.name().to_string()]); @@ -38,7 +38,7 @@ fn get_compile_options( false, vec![], false, - vec![bench.into()], + benches.iter().map(|s| s.to_string()).collect(), false, false, ); @@ -92,27 +92,20 @@ pub fn build_benches( )?; let config = ws.config(); - let mut built_benches = vec![]; - for bench in benches { - ws.config() - .shell() - .status_with_color("Building", bench.name(), Color::Yellow)?; - let compile_opts = get_compile_options(config, &features, package, bench.name())?; - let result = cargo::ops::compile(ws, &compile_opts)?; - let built_targets = result - .tests - .into_iter() - .filter(|u| u.unit.target.is_bench()) - .collect_vec(); - if let Some(built_bench) = built_targets.into_iter().next() { - built_benches.push(built_bench); - } else { - bail!("No benchmark target found.") - } - ws.config() - .shell() - .status_with_color("Built", bench.name(), Color::Green)?; - } + + let benches_names = benches.iter().map(|t| t.name()).collect_vec(); + let benches_names_str = benches_names.join(", "); + + ws.config() + .shell() + .status_with_color("Building", benches_names_str.clone(), Color::Yellow)?; + let compile_opts = get_compile_options(config, &features, package, benches_names)?; + let result = cargo::ops::compile(ws, &compile_opts)?; + let built_benches = result + .tests + .into_iter() + .filter(|u| u.unit.target.is_bench()) + .collect_vec(); if built_benches.is_empty() { bail!( @@ -121,6 +114,10 @@ pub fn build_benches( ); } + ws.config() + .shell() + .status_with_color("Built", benches_names_str, Color::Green)?; + let mut codspeed_target_dir = get_codspeed_dir(ws); create_dir_all(&codspeed_target_dir)?; if let Some(name) = package_name.as_ref() { @@ -129,14 +126,16 @@ pub fn build_benches( } clear_dir(&codspeed_target_dir)?; - for bench in built_benches.iter() { - let bench_dest = codspeed_target_dir.clone().join(bench.unit.target.name()); - std::fs::copy(bench.path.clone(), bench_dest)?; + for built_bench in built_benches.iter() { + let bench_dest = codspeed_target_dir + .clone() + .join(built_bench.unit.target.name()); + std::fs::copy(built_bench.path.clone(), bench_dest)?; } ws.config().shell().status_with_color( "Finished", - format!("built {} benchmark suite(s)", built_benches.len()), + format!("built {} benchmark suite(s)", benches.len()), Color::Green, )?; From 2b094d518faf96ef8b1e929e329112318831966b Mon Sep 17 00:00:00 2001 From: Adrien Cacciaguerra Date: Sat, 10 Feb 2024 16:24:34 +0100 Subject: [PATCH 2/3] fix(cargo-codspeed): ensure cargo-codspeed can be installed on rust < 1.74 --- crates/cargo-codspeed/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cargo-codspeed/Cargo.toml b/crates/cargo-codspeed/Cargo.toml index 5425e82..2aa5d56 100644 --- a/crates/cargo-codspeed/Cargo.toml +++ b/crates/cargo-codspeed/Cargo.toml @@ -19,7 +19,7 @@ keywords = ["codspeed", "benchmark", "cargo"] [dependencies] cargo = "0.66.0" -clap = { version = "4.0.29", features = ["derive"] } +clap = { version = "=4.0.29", features = ["derive"] } termcolor = "1.0" anyhow = "1.0.66" itertools = "0.10.5" From 69c8309d433141638356cf678ea121e7acc7c66a Mon Sep 17 00:00:00 2001 From: Adrien Cacciaguerra Date: Sat, 10 Feb 2024 16:24:49 +0100 Subject: [PATCH 3/3] chore: fix clippy errors --- crates/cargo-codspeed/src/prelude.rs | 1 + crates/criterion_compat/src/compat/mod.rs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/cargo-codspeed/src/prelude.rs b/crates/cargo-codspeed/src/prelude.rs index 62b2fc6..5e69e14 100644 --- a/crates/cargo-codspeed/src/prelude.rs +++ b/crates/cargo-codspeed/src/prelude.rs @@ -1,3 +1,4 @@ +#[allow(unused_imports)] pub use anyhow::{anyhow, bail, Error, Ok, Result}; pub use cargo::core::Workspace; pub use itertools::Itertools; diff --git a/crates/criterion_compat/src/compat/mod.rs b/crates/criterion_compat/src/compat/mod.rs index abf4f60..cc7f709 100644 --- a/crates/criterion_compat/src/compat/mod.rs +++ b/crates/criterion_compat/src/compat/mod.rs @@ -6,4 +6,3 @@ mod macros; pub use self::bencher::*; pub use self::criterion::*; pub use self::group::*; -pub use self::macros::*;