use bindgen::callbacks::IntKind; use bindgen::callbacks::ParseCallbacks; use std::env; use std::path::PathBuf; #[derive(Debug)] struct Callbacks; impl ParseCallbacks for Callbacks { fn int_macro(&self, name: &str, _value: i64) -> Option { match name { "MDB_SUCCESS" | "MDB_KEYEXIST" | "MDB_NOTFOUND" | "MDB_PAGE_NOTFOUND" | "MDB_CORRUPTED" | "MDB_PANIC" | "MDB_VERSION_MISMATCH" | "MDB_INVALID" | "MDB_MAP_FULL" | "MDB_DBS_FULL" | "MDB_READERS_FULL" | "MDB_TLS_FULL" | "MDB_TXN_FULL" | "MDB_CURSOR_FULL" | "MDB_PAGE_FULL" | "MDB_MAP_RESIZED" | "MDB_INCOMPATIBLE" | "MDB_BAD_RSLOT" | "MDB_BAD_TXN" | "MDB_BAD_VALSIZE" | "MDB_BAD_DBI" | "MDB_LAST_ERRCODE" => Some(IntKind::Int), _ => Some(IntKind::UInt), } } } pub fn generate() { let mut lmdb = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()); lmdb.push("lmdb"); lmdb.push("libraries"); lmdb.push("liblmdb"); let mut out_path = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()); out_path.push("src"); let bindings = bindgen::Builder::default() .header(lmdb.join("lmdb.h").to_string_lossy()) .whitelist_var("^(MDB|mdb)_.*") .whitelist_type("^(MDB|mdb)_.*") .whitelist_function("^(MDB|mdb)_.*") .size_t_is_usize(true) .ctypes_prefix("::libc") .blacklist_item("mode_t") .blacklist_item("filehandle_t") .blacklist_item("^__.*") .parse_callbacks(Box::new(Callbacks {})) .layout_tests(false) .prepend_enum_name(false) .rustfmt_bindings(true) .generate() .expect("Unable to generate bindings"); bindings .write_to_file(out_path.join("bindings.rs")) .expect("Couldn't write bindings!"); }