This repository has been archived by the owner on Sep 13, 2023. It is now read-only.
forked from danburkert/lmdb-rs
-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't generate bindings as part of the build phase
Signed-off-by: Victor Porof <victor.porof@gmail.com>
- Loading branch information
1 parent
63f7cd0
commit 317168b
Showing
5 changed files
with
1,466 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.