Don't generate bindings as part of the build phase

Signed-off-by: Victor Porof <victor.porof@gmail.com>
without.crypto
Victor Porof 5 years ago
parent a4776c0957
commit 6bd379824c
  1. 2
      lmdb-sys/Cargo.toml
  2. 68
      lmdb-sys/bindgen.rs
  3. 56
      lmdb-sys/build.rs
  4. 1395
      lmdb-sys/src/bindings.rs
  5. 2
      lmdb-sys/src/lib.rs

@ -13,6 +13,8 @@ documentation = "https://docs.rs/lmdb-rkv-sys"
keywords = ["LMDB", "database", "storage-engine", "bindings", "library"] keywords = ["LMDB", "database", "storage-engine", "bindings", "library"]
categories = ["database", "external-ffi-bindings"] categories = ["database", "external-ffi-bindings"]
# NB: When generating bindings, change to "bindgen.rs" or use something
# like `cargo-script` instead.
build = "build.rs" build = "build.rs"
[dependencies] [dependencies]

@ -0,0 +1,68 @@
extern crate bindgen;
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),
}
}
}
fn main() {
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)_.*")
.ctypes_prefix("::libc")
.blacklist_item("mode_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!");
}

@ -1,9 +1,6 @@
extern crate bindgen;
extern crate cc; extern crate cc;
extern crate pkg_config; extern crate pkg_config;
use bindgen::callbacks::IntKind;
use bindgen::callbacks::ParseCallbacks;
use std::env; use std::env;
use std::path::PathBuf; use std::path::PathBuf;
@ -35,39 +32,6 @@ const MDB_IDL_LOGN: u8 = 15;
)))] )))]
const MDB_IDL_LOGN: u8 = 16; const MDB_IDL_LOGN: u8 = 16;
#[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),
}
}
}
fn main() { fn main() {
let mut lmdb = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()); let mut lmdb = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap());
lmdb.push("lmdb"); lmdb.push("lmdb");
@ -82,24 +46,4 @@ fn main() {
.flag_if_supported("-Wno-unused-parameter") .flag_if_supported("-Wno-unused-parameter")
.compile("liblmdb.a") .compile("liblmdb.a")
} }
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)_.*")
.ctypes_prefix("::libc")
.blacklist_item("mode_t")
.blacklist_item("^__.*")
.parse_callbacks(Box::new(Callbacks {}))
.layout_tests(false)
.prepend_enum_name(false)
.rustfmt_bindings(true)
.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!");
} }

File diff suppressed because it is too large Load Diff

@ -11,4 +11,4 @@ pub type mode_t = ::libc::mode_t;
#[allow(non_camel_case_types)] #[allow(non_camel_case_types)]
pub type mode_t = ::libc::c_int; pub type mode_t = ::libc::c_int;
include!(concat!(env!("OUT_DIR"), "/bindings.rs")); include!("bindings.rs");

Loading…
Cancel
Save