Skip to content

feat: add Windows build support #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 17 additions & 7 deletions crates/cargo-codspeed/src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ use cargo_metadata::{Metadata, Package};
use codspeed::walltime_results::WalltimeResults;
use std::{
io::{self, Write},
os::unix::process::ExitStatusExt,
path::{Path, PathBuf},
};

#[cfg(unix)]
use std::os::unix::process::ExitStatusExt;

struct BenchToRun {
bench_path: PathBuf,
bench_name: String,
Expand Down Expand Up @@ -156,13 +158,21 @@ pub fn run_benches(
if status.success() {
Ok(())
} else {
let code = status
.code()
.or(status.signal().map(|s| 128 + s)) // 128+N indicates that a command was interrupted by signal N (see: https://tldp.org/LDP/abs/html/exitcodes.html)
.unwrap_or(1);
#[cfg(unix)]
{
let code = status
.code()
.or(status.signal().map(|s| 128 + s)) // 128+N indicates that a command was interrupted by signal N (see: https://tldp.org/LDP/abs/html/exitcodes.html)
.unwrap_or(1);

eprintln!("failed to execute the benchmark process, exit code: {code}");

eprintln!("failed to execute the benchmark process, exit code: {code}");
std::process::exit(code);
std::process::exit(code);
}
#[cfg(not(unix))]
{
bail!("failed to execute the benchmark process: {}", status)
}
}
})?;
eprintln!("Done running {bench_name}");
Expand Down
3 changes: 3 additions & 0 deletions crates/codspeed/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
pub mod codspeed;

#[cfg(unix)]
pub mod fifo;

mod macros;
mod measurement;
mod request;
Expand Down
2 changes: 2 additions & 0 deletions crates/codspeed/src/shared.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! WARNING: Has to be in sync with `runner`.

#[cfg(unix)]
pub const RUNNER_CTL_FIFO: &str = "/tmp/runner.ctl.fifo";
#[cfg(unix)]
pub const RUNNER_ACK_FIFO: &str = "/tmp/runner.ack.fifo";

#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
Expand Down
1 change: 1 addition & 0 deletions crates/codspeed/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ mod tests {
assert_eq!(relative_path, path_dir.canonicalize().unwrap());
}

#[cfg(unix)]
#[test]
fn test_get_git_relative_path_not_found_with_symlink() {
let dir = tempdir().unwrap();
Expand Down
17 changes: 11 additions & 6 deletions crates/criterion_compat/criterion_fork/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,12 +297,17 @@ mod codspeed {
) {
let (uri, bench_name) = create_uri_and_name(id, c);

if let Err(error) = ::codspeed::fifo::send_cmd(codspeed::fifo::Command::CurrentBenchmark {
pid: std::process::id(),
uri: uri.clone(),
}) {
if codspeed::utils::running_with_codspeed_runner() {
eprintln!("Failed to send benchmark URI to runner: {error:?}");
#[cfg(unix)]
{
if let Err(error) =
::codspeed::fifo::send_cmd(codspeed::fifo::Command::CurrentBenchmark {
pid: std::process::id(),
uri: uri.clone(),
})
{
if codspeed::utils::running_with_codspeed_runner() {
eprintln!("Failed to send benchmark URI to runner: {error:?}");
}
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/criterion_compat/criterion_fork/src/routine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ pub(crate) trait Routine<M: Measurement, T: ?Sized> {
}

let m_elapsed = {
#[cfg(unix)]
let _guard = codspeed::fifo::BenchGuard::new_with_runner_fifo();
self.bench(measurement, &m_iters, parameter)
};
Expand Down
2 changes: 2 additions & 0 deletions crates/divan_compat/divan_fork/src/bench/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ impl<'a> BenchContext<'a> {

let bench_overheads = timer.bench_overheads();

#[cfg(unix)]
let _guard = codspeed::fifo::BenchGuard::new_with_runner_fifo();
while {
// Conditions for when sampling is over:
Expand Down Expand Up @@ -811,6 +812,7 @@ impl<'a> BenchContext<'a> {
elapsed_picos = elapsed_picos.saturating_add(progress_picos);
}
}
#[cfg(unix)]
core::mem::drop(_guard);

// Reset flag for ignoring allocations.
Expand Down
17 changes: 11 additions & 6 deletions crates/divan_compat/divan_fork/src/divan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,12 +430,17 @@ mod codspeed {
bench_context.samples.time_samples.iter().map(|s| s.duration.picos / 1_000).collect();
let max_time_ns = bench_context.options.max_time.map(|t| t.as_nanos());

if let Err(error) = ::codspeed::fifo::send_cmd(codspeed::fifo::Command::CurrentBenchmark {
pid: std::process::id(),
uri: uri.clone(),
}) {
if codspeed::utils::running_with_codspeed_runner() {
eprintln!("Failed to send benchmark URI to runner: {error:?}");
#[cfg(unix)]
{
if let Err(error) =
::codspeed::fifo::send_cmd(codspeed::fifo::Command::CurrentBenchmark {
pid: std::process::id(),
uri: uri.clone(),
})
{
if codspeed::utils::running_with_codspeed_runner() {
eprintln!("Failed to send benchmark URI to runner: {error:?}");
}
}
}

Expand Down