use std::env;
use std::path::Path;
use std::process::Command;
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let compiler = env::var("ZIG_COMPILER").expect("Failed to find ZIG_COMPILER");
let target = env::var("TB_TARGET").expect("TB_TARGET env var unspecified");
let dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let path = Path::new(&dir);
env::set_current_dir(path.join("tigerbeetle")).unwrap();
let target_flag = format!("-Dtarget={}", target);
Command::new(compiler)
.args(&["build", "tb_client", "-Drelease-safe", &target_flag])
.output()
.expect("Failed to compile Tigerbeetle Zig lib");
env::set_current_dir(path).unwrap();
println!(
"cargo:rustc-link-search=native={}",
Path::new(&dir).join("zig/zig-cache/lib").display()
);
}