From 8c59ac01f505efc62bd9ef03f915282c8c8d9c6c Mon Sep 17 00:00:00 2001 From: David Calavera Date: Thu, 7 May 2020 00:04:59 -0700 Subject: [PATCH] Allow to build RocksDB with a different stdlib. (#423) --- librocksdb-sys/build.rs | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/librocksdb-sys/build.rs b/librocksdb-sys/build.rs index 2cf1a42..4be4a1e 100644 --- a/librocksdb-sys/build.rs +++ b/librocksdb-sys/build.rs @@ -163,7 +163,7 @@ fn build_rocksdb() { if target.contains("msvc") { config.flag("-EHsc"); } else { - config.flag("-std=c++11"); + config.flag(&cxx_standard()); // this was breaking the build on travis due to // > 4mb of warnings emitted. config.flag("-Wno-unused-parameter"); @@ -193,6 +193,8 @@ fn build_snappy() { if target.contains("msvc") { config.flag("-EHsc"); } else { + // Snappy requires C++11. + // See: https://github.com/google/snappy/blob/master/CMakeLists.txt#L32-L38 config.flag("-std=c++11"); } @@ -309,6 +311,16 @@ fn try_to_find_and_link_lib(lib_name: &str) -> bool { false } +fn cxx_standard() -> String { + env::var("ROCKSDB_CXX_STD").map_or("-std=c++11".to_owned(), |cxx_std| { + if !cxx_std.starts_with("-std=") { + format!("-std={}", cxx_std) + } else { + cxx_std + } + }) +} + fn main() { println!("cargo:rerun-if-changed=build.rs");