Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions crates/codspeed/build.rs
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Loading