From 9e18b3afc19c05f424bd215bf911b909168b621b Mon Sep 17 00:00:00 2001 From: Arthur Pastel Date: Wed, 8 Oct 2025 10:13:05 +0000 Subject: [PATCH] fix: force C17 to build instrumenthooks Co-authored-by: Matthias Heiden --- crates/codspeed/build.rs | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/crates/codspeed/build.rs b/crates/codspeed/build.rs index 22f58401..52f0256c 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=gnu17") .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")