Created
January 3, 2020 10:49
-
-
Save utdemir/4012bbd7c6fcf1856f503efc24efa099 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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