Skip to content

Commit 53c0f95

Browse files
art049claude
andcommitted
feat: add Windows build support
Add conditional compilation for Unix-specific features to enable Windows builds: - Wrap FIFO-related code with cfg(unix) attributes - Use platform-specific exit status handling in cargo-codspeed - Make fifo module Unix-only in lib.rs - Guard FIFO constants and operations across all crates This allows the project to build on Windows (build-only, not runtime support). 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 6f3aa29 commit 53c0f95

File tree

8 files changed

+48
-19
lines changed

8 files changed

+48
-19
lines changed

crates/cargo-codspeed/src/run.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ use cargo_metadata::{Metadata, Package};
99
use codspeed::walltime_results::WalltimeResults;
1010
use std::{
1111
io::{self, Write},
12-
os::unix::process::ExitStatusExt,
1312
path::{Path, PathBuf},
1413
};
1514

15+
#[cfg(unix)]
16+
use std::os::unix::process::ExitStatusExt;
17+
1618
struct BenchToRun {
1719
bench_path: PathBuf,
1820
bench_name: String,
@@ -156,13 +158,21 @@ pub fn run_benches(
156158
if status.success() {
157159
Ok(())
158160
} else {
159-
let code = status
160-
.code()
161-
.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)
162-
.unwrap_or(1);
161+
#[cfg(unix)]
162+
{
163+
let code = status
164+
.code()
165+
.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)
166+
.unwrap_or(1);
167+
168+
eprintln!("failed to execute the benchmark process, exit code: {code}");
163169

164-
eprintln!("failed to execute the benchmark process, exit code: {code}");
165-
std::process::exit(code);
170+
std::process::exit(code);
171+
}
172+
#[cfg(not(unix))]
173+
{
174+
bail!("failed to execute the benchmark process: {}", status)
175+
}
166176
}
167177
})?;
168178
eprintln!("Done running {bench_name}");

crates/codspeed/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
pub mod codspeed;
2+
3+
#[cfg(unix)]
24
pub mod fifo;
5+
36
mod macros;
47
mod measurement;
58
mod request;

crates/codspeed/src/shared.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! WARNING: Has to be in sync with `runner`.
22
3+
#[cfg(unix)]
34
pub const RUNNER_CTL_FIFO: &str = "/tmp/runner.ctl.fifo";
5+
#[cfg(unix)]
46
pub const RUNNER_ACK_FIFO: &str = "/tmp/runner.ack.fifo";
57

68
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]

crates/codspeed/src/utils.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ mod tests {
7171
assert_eq!(relative_path, path_dir.canonicalize().unwrap());
7272
}
7373

74+
#[cfg(unix)]
7475
#[test]
7576
fn test_get_git_relative_path_not_found_with_symlink() {
7677
let dir = tempdir().unwrap();

crates/criterion_compat/criterion_fork/src/analysis/mod.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -297,12 +297,17 @@ mod codspeed {
297297
) {
298298
let (uri, bench_name) = create_uri_and_name(id, c);
299299

300-
if let Err(error) = ::codspeed::fifo::send_cmd(codspeed::fifo::Command::CurrentBenchmark {
301-
pid: std::process::id(),
302-
uri: uri.clone(),
303-
}) {
304-
if codspeed::utils::running_with_codspeed_runner() {
305-
eprintln!("Failed to send benchmark URI to runner: {error:?}");
300+
#[cfg(unix)]
301+
{
302+
if let Err(error) =
303+
::codspeed::fifo::send_cmd(codspeed::fifo::Command::CurrentBenchmark {
304+
pid: std::process::id(),
305+
uri: uri.clone(),
306+
})
307+
{
308+
if codspeed::utils::running_with_codspeed_runner() {
309+
eprintln!("Failed to send benchmark URI to runner: {error:?}");
310+
}
306311
}
307312
}
308313

crates/criterion_compat/criterion_fork/src/routine.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ pub(crate) trait Routine<M: Measurement, T: ?Sized> {
192192
}
193193

194194
let m_elapsed = {
195+
#[cfg(unix)]
195196
let _guard = codspeed::fifo::BenchGuard::new_with_runner_fifo();
196197
self.bench(measurement, &m_iters, parameter)
197198
};

crates/divan_compat/divan_fork/src/bench/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ impl<'a> BenchContext<'a> {
657657

658658
let bench_overheads = timer.bench_overheads();
659659

660+
#[cfg(unix)]
660661
let _guard = codspeed::fifo::BenchGuard::new_with_runner_fifo();
661662
while {
662663
// Conditions for when sampling is over:
@@ -811,6 +812,7 @@ impl<'a> BenchContext<'a> {
811812
elapsed_picos = elapsed_picos.saturating_add(progress_picos);
812813
}
813814
}
815+
#[cfg(unix)]
814816
core::mem::drop(_guard);
815817

816818
// Reset flag for ignoring allocations.

crates/divan_compat/divan_fork/src/divan.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -430,12 +430,17 @@ mod codspeed {
430430
bench_context.samples.time_samples.iter().map(|s| s.duration.picos / 1_000).collect();
431431
let max_time_ns = bench_context.options.max_time.map(|t| t.as_nanos());
432432

433-
if let Err(error) = ::codspeed::fifo::send_cmd(codspeed::fifo::Command::CurrentBenchmark {
434-
pid: std::process::id(),
435-
uri: uri.clone(),
436-
}) {
437-
if codspeed::utils::running_with_codspeed_runner() {
438-
eprintln!("Failed to send benchmark URI to runner: {error:?}");
433+
#[cfg(unix)]
434+
{
435+
if let Err(error) =
436+
::codspeed::fifo::send_cmd(codspeed::fifo::Command::CurrentBenchmark {
437+
pid: std::process::id(),
438+
uri: uri.clone(),
439+
})
440+
{
441+
if codspeed::utils::running_with_codspeed_runner() {
442+
eprintln!("Failed to send benchmark URI to runner: {error:?}");
443+
}
439444
}
440445
}
441446

0 commit comments

Comments
 (0)