use std::env; use std::path::PathBuf; fn main() { let mut bindings = bindgen::Builder::default() .parse_callbacks(Box::new(bindgen::CargoCallbacks::new())) .allowlist_recursively(false) .allowlist_item("_?dconf_.*") .allowlist_item("_?DCONF_.*") .allowlist_item("_?DConf.*") .raw_line("use glib_sys::*;") .raw_line("use libc::c_char as gchar;") .raw_line("use libc::c_int as gint;") .raw_line("use libc::c_uint as guint;") .raw_line("") .raw_line("enum GObjectClass {}") .raw_line("enum GCancellable {}"); let library = pkg_config::probe_library("dconf").unwrap(); for (key, value) in library.defines { bindings = bindings.clang_arg("-D"); if let Some(value) = value { bindings = bindings.clang_arg(&format!("{}={}", key, value)); } else { bindings = bindings.clang_arg(key); } } for include_path in library.include_paths { bindings = bindings.clang_arg("-I"); bindings = bindings.clang_arg(include_path.to_string_lossy()); } for args in library.ld_args { for arg in args { println!("cargo::rustc-link-arg={}", arg); } } for libs in library.libs { println!("cargo::rustc-link-lib={}", libs); } for link_file in library.link_files { println!("cargo::rustc-link-lib={}", link_file.to_string_lossy()); } for link_path in library.link_paths { println!("cargo::rustc-link-search=native={}", link_path.to_string_lossy()); } for framework_path in library.framework_paths { println!("cargo::rustc-link-search=framework={}", framework_path.to_string_lossy()); } for framework in library.frameworks { println!("cargo::rustc-link-lib=framework={}", framework); } let bindings = bindings .header("wrapper.h") .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!"); }