extern crate bindgen; use std::collections::HashSet; use std::path::PathBuf; #[derive(Debug)] struct IgnoreMacros(HashSet); impl bindgen::callbacks::ParseCallbacks for IgnoreMacros { fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior { if self.0.contains(name) { bindgen::callbacks::MacroParsingBehavior::Ignore } else { bindgen::callbacks::MacroParsingBehavior::Default } } } // https://fitzgeraldnick.com/2016/12/14/using-libbindgen-in-build-rs.html fn main() { println!("cargo:rustc-link-lib=gvc"); println!("cargo:rustc-link-lib=cgraph"); // https://github.com/rust-lang/rust-bindgen/issues/687 let ignored_macros = IgnoreMacros( vec![ "FP_INFINITE".into(), "FP_NAN".into(), "FP_NORMAL".into(), "FP_SUBNORMAL".into(), "FP_ZERO".into(), ] .into_iter() .collect(), ); // The bindgen::Builder is the main entry point // to bindgen, and lets you build up options for // the resulting bindings. let bindings = bindgen::Builder::default() // The input header we would like to generate // bindings for. .header("wrapper.h") .parse_callbacks(Box::new(ignored_macros)) .rustfmt_bindings(true) // Finish the builder and generate the bindings. .generate() // Unwrap the Result and panic on failure. .expect("Unable to generate bindings"); // Write the bindings to the given file. let out_path = PathBuf::from(std::env::var("OUT_DIR").unwrap()); bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); }