Skip to content

Instantly share code, notes, and snippets.

@utdemir
Created January 3, 2020 10:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utdemir/4012bbd7c6fcf1856f503efc24efa099 to your computer and use it in GitHub Desktop.
Save utdemir/4012bbd7c6fcf1856f503efc24efa099 to your computer and use it in GitHub Desktop.
extern crate bindgen;
use std::env;
use std::path::PathBuf;
// Fix for: the name `IPPORT_RESERVED` is defined multiple times
// Issue: https://github.com/rust-lang/rust-bindgen/issues/687
#[derive(Debug)]
struct IgnoreMacros(Vec<String>);
impl bindgen::callbacks::ParseCallbacks for IgnoreMacros {
fn will_parse_macro(&self, name: &str) -> bindgen::callbacks::MacroParsingBehavior {
if self.0.contains(&name.to_string()) {
bindgen::callbacks::MacroParsingBehavior::Ignore
} else {
bindgen::callbacks::MacroParsingBehavior::Default
}
}
}
fn main() {
println!("cargo:rustc-link-lib=ssh");
println!("cargo:rerun-if-changed=wrapper.h");
let ignored_macros = IgnoreMacros(vec!["IPPORT_RESERVED".into()]);
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.parse_callbacks(Box::new(ignored_macros))
.rustfmt_bindings(true)
.blacklist_type("IPPORT_RESERVED")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment