diff --git a/crates/cargo-codspeed/src/run.rs b/crates/cargo-codspeed/src/run.rs index e6f21be2..4dbd646f 100644 --- a/crates/cargo-codspeed/src/run.rs +++ b/crates/cargo-codspeed/src/run.rs @@ -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, @@ -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}"); diff --git a/crates/codspeed/src/lib.rs b/crates/codspeed/src/lib.rs index ec32f26d..aa7a51d1 100644 --- a/crates/codspeed/src/lib.rs +++ b/crates/codspeed/src/lib.rs @@ -1,5 +1,8 @@ pub mod codspeed; + +#[cfg(unix)] pub mod fifo; + mod macros; mod measurement; mod request; diff --git a/crates/codspeed/src/shared.rs b/crates/codspeed/src/shared.rs index 86c1433e..1c8481c0 100644 --- a/crates/codspeed/src/shared.rs +++ b/crates/codspeed/src/shared.rs @@ -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)] diff --git a/crates/codspeed/src/utils.rs b/crates/codspeed/src/utils.rs index 07960fff..886cdf57 100644 --- a/crates/codspeed/src/utils.rs +++ b/crates/codspeed/src/utils.rs @@ -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(); diff --git a/crates/criterion_compat/criterion_fork/src/analysis/mod.rs b/crates/criterion_compat/criterion_fork/src/analysis/mod.rs index 815dcf27..9a1bc6f2 100644 --- a/crates/criterion_compat/criterion_fork/src/analysis/mod.rs +++ b/crates/criterion_compat/criterion_fork/src/analysis/mod.rs @@ -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:?}"); + } } } diff --git a/crates/criterion_compat/criterion_fork/src/routine.rs b/crates/criterion_compat/criterion_fork/src/routine.rs index f418b44f..09ee41b4 100644 --- a/crates/criterion_compat/criterion_fork/src/routine.rs +++ b/crates/criterion_compat/criterion_fork/src/routine.rs @@ -192,6 +192,7 @@ pub(crate) trait Routine { } let m_elapsed = { + #[cfg(unix)] let _guard = codspeed::fifo::BenchGuard::new_with_runner_fifo(); self.bench(measurement, &m_iters, parameter) }; diff --git a/crates/divan_compat/divan_fork/src/bench/mod.rs b/crates/divan_compat/divan_fork/src/bench/mod.rs index 0234babf..e5e6de6c 100644 --- a/crates/divan_compat/divan_fork/src/bench/mod.rs +++ b/crates/divan_compat/divan_fork/src/bench/mod.rs @@ -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: @@ -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. diff --git a/crates/divan_compat/divan_fork/src/divan.rs b/crates/divan_compat/divan_fork/src/divan.rs index 3953aff5..54bbce2c 100644 --- a/crates/divan_compat/divan_fork/src/divan.rs +++ b/crates/divan_compat/divan_fork/src/divan.rs @@ -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:?}"); + } } }