trifid/nebula-ffi/build.rs

26 lines
826 B
Rust
Raw Normal View History

2023-06-26 02:00:36 +00:00
use std::env;
use std::path::PathBuf;
use bindgen::CargoCallbacks;
fn main() {
gobuild::Build::new().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");
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!");
}