diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /third_party/rust/lmdb-rkv-sys/bindgen.rs | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/lmdb-rkv-sys/bindgen.rs')
-rw-r--r-- | third_party/rust/lmdb-rkv-sys/bindgen.rs | 69 |
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!"); +} |