From 0603615a2dc2a0073d3a2f6c65b6b9a35165ea2e Mon Sep 17 00:00:00 2001 From: Victor Porof Date: Fri, 13 Sep 2019 10:17:00 +0200 Subject: [PATCH] Add features for building with asan and fuzzing Signed-off-by: Victor Porof --- Cargo.toml | 6 ++++++ lmdb-sys/Cargo.toml | 3 +++ lmdb-sys/build.rs | 21 ++++++++++++++++++--- 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index db5ccad..067d6e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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"] diff --git a/lmdb-sys/Cargo.toml b/lmdb-sys/Cargo.toml index 946b7a1..8bcd244 100644 --- a/lmdb-sys/Cargo.toml +++ b/lmdb-sys/Cargo.toml @@ -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 diff --git a/lmdb-sys/build.rs b/lmdb-sys/build.rs index 3caeb24..4c99d28 100644 --- a/lmdb-sys/build.rs +++ b/lmdb-sys/build.rs @@ -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") } }