trifid/nebula-ffi/build.rs

40 lines
1.2 KiB
Rust

use std::env;
use std::path::PathBuf;
use bindgen::CargoCallbacks;
use std::path::Path;
fn main() {
// Find compiler: if /usr/local/go/bin/go exists, use that
// otherwise, rely on PATH
let compiler;
if Path::new("/usr/local/go/bin/go").exists() {
println!("Using /usr/local/go/bin/go");
compiler = "/usr/local/go/bin/go";
} else {
compiler = "go";
}
gobuild::Build::new().compiler(compiler).file("main.go").compile("nebulaffi");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
println!("cargo:rustc-link-search={}", out_path.display());
println!("cargo:rustc-link-lib=static=nebulaffi");
println!("cargo:rerun-if-changed=go.mod");
println!("cargo:rerun-if-changed=go.sum");
println!("cargo:rerun-if-changed=main.go");
println!("Bindgen start");
let bindings = bindgen::Builder::default()
.header(out_path.join("libnebulaffi.h").display().to_string())
.parse_callbacks(Box::new(CargoCallbacks))
.generate()
.expect("Error generating CFFI bindings");
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}