Skip to content

Commit

Permalink
Merge branch 'main' into fix/path-strip-panic-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencaccia committed Feb 15, 2024
2 parents d115c99 + 69c8309 commit fe8a165
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
2 changes: 1 addition & 1 deletion crates/cargo-codspeed/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
53 changes: 26 additions & 27 deletions crates/cargo-codspeed/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ fn get_compile_options(
config: &Config,
features: &Option<Vec<String>>,
package: &Package,
bench: &str,
benches: Vec<&str>,
) -> Result<CompileOptions> {
let mut compile_opts = CompileOptions::new(config, CompileMode::Build)?;
compile_opts.spec = Packages::Packages(vec![package.name().to_string()]);
Expand All @@ -38,7 +38,7 @@ fn get_compile_options(
false,
vec![],
false,
vec![bench.into()],
benches.iter().map(|s| s.to_string()).collect(),
false,
false,
);
Expand Down Expand Up @@ -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!(
Expand All @@ -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() {
Expand All @@ -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,
)?;

Expand Down
1 change: 1 addition & 0 deletions crates/cargo-codspeed/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#[allow(unused_imports)]
pub use anyhow::{anyhow, bail, Error, Ok, Result};
pub use cargo::core::Workspace;
pub use itertools::Itertools;
1 change: 0 additions & 1 deletion crates/criterion_compat/src/compat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ mod macros;
pub use self::bencher::*;
pub use self::criterion::*;
pub use self::group::*;
pub use self::macros::*;

0 comments on commit fe8a165

Please sign in to comment.