Skip to content

Commit 19ad9f2

Browse files
committed
fix(codspeed): fallback to noop when build fails
1 parent 1d5c36b commit 19ad9f2

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

crates/codspeed/build.rs

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
fn main() {
2+
println!("cargo:rustc-check-cfg=cfg(use_instrument_hooks)");
3+
24
println!("cargo:rerun-if-changed=instrument-hooks/dist/core.c");
35
println!("cargo:rerun-if-changed=instrument-hooks/includes/core.h");
46
println!("cargo:rerun-if-changed=build.rs");
57

6-
if cfg!(not(target_os = "linux")) {
7-
// The instrument-hooks library is only supported on Linux.
8-
return;
9-
}
10-
118
let mut build = cc::Build::new();
129
build
1310
.flag("-std=c11")
@@ -18,13 +15,17 @@ fn main() {
1815
.cargo_warnings(false);
1916

2017
let result = build.try_compile("instrument_hooks");
21-
if let Err(e) = result {
22-
let compiler = build.try_get_compiler().expect("Failed to get C compiler");
18+
match result {
19+
Ok(_) => println!("cargo:rustc-cfg=use_instrument_hooks"),
20+
Err(e) => {
21+
let compiler = build.try_get_compiler().expect("Failed to get C compiler");
2322

24-
eprintln!("\n\nERROR: Failed to compile instrument-hooks native library with cc-rs. Ensure you have an up-to-date C compiler installed.");
25-
eprintln!("Compiler information: {compiler:?}");
26-
eprintln!("Compilation error: {e}");
23+
eprintln!("\n\nWARNING: Failed to compile instrument-hooks native library with cc-rs.");
24+
eprintln!("The library will still compile, but instrument-hooks functionality will be disabled.");
25+
eprintln!("Compiler information: {compiler:?}");
26+
eprintln!("Compilation error: {e}\n");
2727

28-
std::process::exit(1);
28+
println!("cargo:warning=Failed to compile instrument-hooks native library with cc-rs. Continuing with noop implementation.");
29+
}
2930
}
3031
}

crates/codspeed/src/instrument_hooks/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
#[cfg(target_os = "linux")]
1+
#[cfg(use_instrument_hooks)]
22
mod ffi;
33

4-
#[cfg(target_os = "linux")]
4+
#[cfg(use_instrument_hooks)]
55
mod linux_impl {
66
use nix::sys::time::TimeValLike;
77

@@ -131,7 +131,7 @@ mod linux_impl {
131131
}
132132
}
133133

134-
#[cfg(not(target_os = "linux"))]
134+
#[cfg(not(use_instrument_hooks))]
135135
mod other_impl {
136136
pub struct InstrumentHooks;
137137

@@ -169,10 +169,10 @@ mod other_impl {
169169
}
170170
}
171171

172-
#[cfg(target_os = "linux")]
172+
#[cfg(use_instrument_hooks)]
173173
pub use linux_impl::InstrumentHooks;
174174

175-
#[cfg(not(target_os = "linux"))]
175+
#[cfg(not(use_instrument_hooks))]
176176
pub use other_impl::InstrumentHooks;
177177

178178
#[cfg(test)]

0 commit comments

Comments
 (0)