diff --git a/crates/codspeed/build.rs b/crates/codspeed/build.rs index 22f58401..0cb8be40 100644 --- a/crates/codspeed/build.rs +++ b/crates/codspeed/build.rs @@ -1,17 +1,34 @@ use std::{env, path::PathBuf}; fn main() { + println!("cargo:rerun-if-changed=instrument-hooks/dist/core.c"); + println!("cargo:rerun-if-changed=instrument-hooks/includes/core.h"); + println!("cargo:rerun-if-changed=build.rs"); + if cfg!(not(target_os = "linux")) { // The instrument-hooks library is only supported on Linux. return; } - // Compile the C library - cc::Build::new() + let mut build = cc::Build::new(); + build + .flag("-std=c11") .file("instrument-hooks/dist/core.c") .include("instrument-hooks/includes") - .flag("-w") // Suppress all warnings - .compile("instrument_hooks"); + .warnings(false) + .extra_warnings(false) + .cargo_warnings(false); + + let result = build.try_compile("instrument_hooks"); + if let Err(e) = result { + let compiler = build.try_get_compiler().expect("Failed to get C compiler"); + + eprintln!("\n\nERROR: Failed to compile instrument-hooks native library with cc-rs. Ensure you have an up-to-date C compiler installed."); + eprintln!("Compiler information: {:?}", compiler); + eprintln!("Compilation error: {e}"); + + std::process::exit(1); + } let bindings = bindgen::Builder::default() .header("instrument-hooks/includes/core.h")