Add features for building with asan and fuzzing

Signed-off-by: Victor Porof <victor.porof@gmail.com>
without.crypto
Victor Porof 5 years ago
parent 8fc50a8f74
commit 0603615a2d
  1. 6
      Cargo.toml
  2. 3
      lmdb-sys/Cargo.toml
  3. 21
      lmdb-sys/build.rs

@ -50,3 +50,9 @@ lmdb-rkv-sys = { path = "./lmdb-sys" }
[dev-dependencies]
rand = "0.4.6"
tempdir = "0.3.7"
[features]
default = []
with-clang = ["lmdb-rkv-sys/with-clang"]
with-asan = ["lmdb-rkv-sys/with-asan"]
with-fuzzer = ["lmdb-rkv-sys/with-fuzzer"]

@ -33,6 +33,9 @@ bindgen = "0.51.0"
[features]
default = []
with-clang = []
with-asan = ["with-clang"]
with-fuzzer = ["with-clang"]
# These features configure the MDB_IDL_LOGN macro, which determines
# the size of the free and dirty page lists (and thus the amount of memory

@ -39,14 +39,29 @@ fn main() {
lmdb.push("liblmdb");
if !pkg_config::find_library("liblmdb").is_ok() {
cc::Build::new()
let mut builder = cc::Build::new();
builder
.define("MDB_IDL_LOGN", Some(MDB_IDL_LOGN.to_string().as_str()))
.file(lmdb.join("mdb.c"))
.file(lmdb.join("midl.c"))
// https://github.com/mozilla/lmdb/blob/b7df2cac50fb41e8bd16aab4cc5fd167be9e032a/libraries/liblmdb/Makefile#L23
.flag_if_supported("-Wno-unused-parameter")
.flag_if_supported("-Wbad-function-cast")
.flag_if_supported("-Wuninitialized")
.compile("liblmdb.a")
.flag_if_supported("-Wuninitialized");
if env::var("CARGO_FEATURE_WITH_CLANG").is_ok() {
builder.compiler("clang");
}
if env::var("CARGO_FEATURE_WITH_ASAN").is_ok() {
builder.flag("-fsanitize=address");
}
if env::var("CARGO_FEATURE_WITH_FUZZER").is_ok() {
builder.flag("-fsanitize=fuzzer");
}
builder.compile("liblmdb.a")
}
}

Loading…
Cancel
Save