// This Source Code Form is subject to the terms of the Mozilla Public // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. extern crate bindgen; extern crate pkg_config; use bindgen::callbacks::{MacroParsingBehavior, ParseCallbacks}; use std::env; use std::sync::{Arc, RwLock}; use std::path::PathBuf; use std::collections::HashSet; #[derive(Debug)] struct MacroCallback { macros: Arc>>, } impl ParseCallbacks for MacroCallback { fn will_parse_macro(&self, name: &str) -> MacroParsingBehavior { self.macros.write().unwrap().insert(name.into()); let annoying_macros = vec![ "FP_NORMAL", "FP_NAN", "FP_INFINITE", "FP_ZERO", "FP_SUBNORMAL", "IPPORT_RESERVED", ]; for macro_name in annoying_macros { if name == macro_name { return MacroParsingBehavior::Ignore } } MacroParsingBehavior::Default } } fn main() { println!("cargo:rustc-link-lib=ecore"); println!("cargo:rustc-link-lib=efl"); println!("cargo:rustc-link-lib=eo"); println!("cargo:rustc-link-lib=eina"); println!("cargo:rustc-link-lib=elementary"); let libs = vec![ "ecore", "efl", "eo", "eina", "elementary", ]; let mut include_dirs = Vec::new(); for library in libs { match pkg_config::Config::new().probe(library) { Ok(lib) => { for path in lib.include_paths { include_dirs.push(format!("-I{}", path.display())); } } Err(e) => { eprintln!("Failed to find library {}: {}", library, e); std::process::exit(1); } } } let macros = Arc::new(RwLock::new(HashSet::new())); let bindings = bindgen::Builder::default() .header("wrapper.h") .clang_args(&include_dirs) .parse_callbacks(Box::new(MacroCallback {macros: macros.clone()})) .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!"); }