use std::path::Path;
use std::process::Command;
const GLIBC_BASELINE: &str = "2.17";
fn main() {
let out_dir = std::env::var("OUT_DIR").expect("cargo sets OUT_DIR for build scripts");
let out_so = Path::new(&out_dir).join("dstest_clock.so");
println!("cargo:rerun-if-changed=shim/clock.c");
let target = format!("x86_64-linux-gnu.{GLIBC_BASELINE}");
let out = Command::new("zig")
.args(["cc", "-shared", "-fPIC", "-Werror"])
.args(["-target", &target])
.arg("-o")
.arg(&out_so)
.arg("shim/clock.c")
.output();
match out {
Ok(o) if o.status.success() => {}
Ok(o) => {
let stderr = String::from_utf8_lossy(&o.stderr);
panic!(
"zig cc failed to compile the clock shim (target {target})\n{}",
stderr.trim()
);
}
Err(e) => panic!(
"zig is required to build the clock shim but was not found: {e}\n\
Install it, for example: `nix profile install nixpkgs#zig`"
),
}
}