| 1 |
extern crate cc; |
| 2 |
extern crate pkg_config; |
| 3 |
|
| 4 |
#[cfg(feature = "bindgen")] |
| 5 |
extern crate bindgen; |
| 6 |
|
| 7 |
#[cfg(feature = "bindgen")] |
| 8 |
#[path = "bindgen.rs"] |
| 9 |
mod generate; |
| 10 |
|
| 11 |
use std::env; |
| 12 |
use std::path::PathBuf; |
| 13 |
|
| 14 |
#[cfg(feature = "mdb_idl_logn_8")] |
| 15 |
const MDB_IDL_LOGN: u8 = 8; |
| 16 |
#[cfg(feature = "mdb_idl_logn_9")] |
| 17 |
const MDB_IDL_LOGN: u8 = 9; |
| 18 |
#[cfg(feature = "mdb_idl_logn_10")] |
| 19 |
const MDB_IDL_LOGN: u8 = 10; |
| 20 |
#[cfg(feature = "mdb_idl_logn_11")] |
| 21 |
const MDB_IDL_LOGN: u8 = 11; |
| 22 |
#[cfg(feature = "mdb_idl_logn_12")] |
| 23 |
const MDB_IDL_LOGN: u8 = 12; |
| 24 |
#[cfg(feature = "mdb_idl_logn_13")] |
| 25 |
const MDB_IDL_LOGN: u8 = 13; |
| 26 |
#[cfg(feature = "mdb_idl_logn_14")] |
| 27 |
const MDB_IDL_LOGN: u8 = 14; |
| 28 |
#[cfg(feature = "mdb_idl_logn_15")] |
| 29 |
const MDB_IDL_LOGN: u8 = 15; |
| 30 |
#[cfg(not(any( |
| 31 |
feature = "mdb_idl_logn_8", |
| 32 |
feature = "mdb_idl_logn_9", |
| 33 |
feature = "mdb_idl_logn_10", |
| 34 |
feature = "mdb_idl_logn_11", |
| 35 |
feature = "mdb_idl_logn_12", |
| 36 |
feature = "mdb_idl_logn_13", |
| 37 |
feature = "mdb_idl_logn_14", |
| 38 |
feature = "mdb_idl_logn_15", |
| 39 |
)))] |
| 40 |
const MDB_IDL_LOGN: u8 = 16; |
| 41 |
|
| 42 |
macro_rules! warn { |
| 43 |
($message:expr) => { |
| 44 |
println!("cargo:warning={}", $message); |
| 45 |
}; |
| 46 |
} |
| 47 |
|
| 48 |
fn main() { |
| 49 |
#[cfg(feature = "bindgen")] |
| 50 |
generate::generate(); |
| 51 |
|
| 52 |
let mut lmdb = PathBuf::from(&env::var("CARGO_MANIFEST_DIR").unwrap()); |
| 53 |
lmdb.push("lmdb"); |
| 54 |
lmdb.push("libraries"); |
| 55 |
lmdb.push("liblmdb"); |
| 56 |
|
| 57 |
if cfg!(feature = "with-fuzzer") && cfg!(feature = "with-fuzzer-no-link") { |
| 58 |
warn!("Features `with-fuzzer` and `with-fuzzer-no-link` are mutually exclusive."); |
| 59 |
warn!("Building with `-fsanitize=fuzzer`."); |
| 60 |
} |
| 61 |
|
| 62 |
if !pkg_config::find_library("liblmdb").is_ok() { |
| 63 |
let mut builder = cc::Build::new(); |
| 64 |
|
| 65 |
builder |
| 66 |
.define("MDB_IDL_LOGN", Some(MDB_IDL_LOGN.to_string().as_str())) |
| 67 |
.file(lmdb.join("mdb.c")) |
| 68 |
.file(lmdb.join("midl.c")) |
| 69 |
// https://github.com/mozilla/lmdb/blob/b7df2cac50fb41e8bd16aab4cc5fd167be9e032a/libraries/liblmdb/Makefile#L23 |
| 70 |
.flag_if_supported("-Wno-unused-parameter") |
| 71 |
.flag_if_supported("-Wbad-function-cast") |
| 72 |
.flag_if_supported("-Wuninitialized"); |
| 73 |
|
| 74 |
if env::var("CARGO_FEATURE_WITH_ASAN").is_ok() { |
| 75 |
builder.flag("-fsanitize=address"); |
| 76 |
} |
| 77 |
|
| 78 |
if env::var("CARGO_FEATURE_WITH_FUZZER").is_ok() { |
| 79 |
builder.flag("-fsanitize=fuzzer"); |
| 80 |
} else if env::var("CARGO_FEATURE_WITH_FUZZER_NO_LINK").is_ok() { |
| 81 |
builder.flag("-fsanitize=fuzzer-no-link"); |
| 82 |
} |
| 83 |
|
| 84 |
builder.compile("liblmdb.a") |
| 85 |
} |
| 86 |
} |