summaryrefslogtreecommitdiffstats
path: root/third_party/rust/lmdb-rkv-sys/bindgen.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/lmdb-rkv-sys/bindgen.rs')
-rw-r--r--third_party/rust/lmdb-rkv-sys/bindgen.rs69
1 files changed, 69 insertions, 0 deletions
diff --git a/third_party/rust/lmdb-rkv-sys/bindgen.rs b/third_party/rust/lmdb-rkv-sys/bindgen.rs
new file mode 100644
index 0000000000..3505fc5906
--- /dev/null
+++ b/third_party/rust/lmdb-rkv-sys/bindgen.rs
@@ -0,0 +1,69 @@
+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<IntKind> {
+ 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("mdb_mode_t")
+ .blacklist_item("mdb_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!");
+}