use std::env; use std::path::PathBuf; use bindgen::CargoCallbacks; use gobuild::BuildMode; fn main() { gobuild::Build::new().buildmode(BuildMode::CShared).file("main.go").compile("nebulaffi"); println!("Go compile success"); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); println!("cargo:rustc-link-search={}", out_path.display()); println!("cargo:rustc-link-lib=dylib=nebulaffi"); println!("cargo:rerun-if-changed=go.mod"); println!("cargo:rerun-if-changed=go.sum"); println!("cargo:rerun-if-changed=main.go"); println!("Generating bindings"); 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!"); }