From c1b0f79c146a07e10065f9c56c649a91bfe9947e Mon Sep 17 00:00:00 2001 From: Niko PLP Date: Tue, 8 Aug 2023 00:36:07 +0300 Subject: [PATCH] updated build.rs with more flags and settings --- librocksdb-sys/build.rs | 101 ++++++++++++++++++------- librocksdb-sys/rocksdb | 2 +- librocksdb-sys/rocksdb_lib_sources.txt | 2 + 3 files changed, 75 insertions(+), 30 deletions(-) diff --git a/librocksdb-sys/build.rs b/librocksdb-sys/build.rs index 40ab253..84c2888 100644 --- a/librocksdb-sys/build.rs +++ b/librocksdb-sys/build.rs @@ -53,6 +53,7 @@ fn build_rocksdb() { config.include("rocksdb/include/"); config.include("rocksdb/"); config.include("rocksdb/third-party/gtest-1.8.1/fused-src/"); + config.include("rocksdb/plugin/ippcp/library/include"); if cfg!(feature = "snappy") { config.define("SNAPPY", Some("1")); @@ -102,71 +103,95 @@ fn build_rocksdb() { .filter(|file| !matches!(*file, "util/build_version.cc")) .collect::>(); - if let (true, Ok(target_feature_value)) = ( + if let (true, Ok(_target_feature_value)) = ( target.contains("x86_64"), env::var("CARGO_CFG_TARGET_FEATURE"), ) { // This is needed to enable hardware CRC32C. Technically, SSE 4.2 is // only available since Intel Nehalem (about 2010) and AMD Bulldozer // (about 2011). - let target_features: Vec<_> = target_feature_value.split(',').collect(); - - if target_features.contains(&"sse2") { - config.flag_if_supported("-msse2"); - } - if target_features.contains(&"sse4.1") { - config.flag_if_supported("-msse4.1"); - } - if target_features.contains(&"sse4.2") { - config.flag_if_supported("-msse4.2"); - } - // Pass along additional target features as defined in - // build_tools/build_detect_platform. - if target_features.contains(&"avx2") { - config.flag_if_supported("-mavx2"); - } - if target_features.contains(&"bmi1") { - config.flag_if_supported("-mbmi"); - } - if target_features.contains(&"lzcnt") { - config.flag_if_supported("-mlzcnt"); - } - if !target.contains("android") && target_features.contains(&"pclmulqdq") { - config.flag_if_supported("-mpclmul"); - } + // let target_features: Vec<_> = target_feature_value.split(',').collect(); + + // if target_features.contains(&"sse2") { + // config.flag_if_supported("-msse2"); + // } + // if target_features.contains(&"sse4.1") { + // config.flag_if_supported("-msse4.1"); + // } + // if target_features.contains(&"sse4.2") { + // config.flag_if_supported("-msse4.2"); + // } + // // Pass along additional target features as defined in + // // build_tools/build_detect_platform. + // if target_features.contains(&"avx2") { + // config.flag_if_supported("-mavx2"); + // } + // if target_features.contains(&"bmi1") { + // config.flag_if_supported("-mbmi"); + // } + // if target_features.contains(&"lzcnt") { + // config.flag_if_supported("-mlzcnt"); + // } + // if !target.contains("android") && target_features.contains(&"pclmulqdq") { + // config.flag_if_supported("-mpclmul"); + // } + + // We want a portable library that can run on any x86_64. + // but we optimize for haswell which supports + // many or most of the available optimizations while still being compatible with + // most processors made since roughly 2013. + // if this becomes a problem for some app installers with older hardware, a special install + // file should be generated with a lib compiled without this flag + config.flag("-march=haswell"); } if target.contains("apple-ios") { config.define("OS_MACOSX", None); - config.define("IOS_CROSS_COMPILE", None); config.define("PLATFORM", "IOS"); config.define("NIOSTATS_CONTEXT", None); config.define("NPERF_CONTEXT", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); - env::set_var("IPHONEOS_DEPLOYMENT_TARGET", "12.0"); } else if target.contains("darwin") { config.define("OS_MACOSX", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); + println!("cargo:rustc-link-arg=-mmacosx-version-min=10.14"); + config.flag("-Wshorten-64-to-32"); + config.flag("-mmacosx-version-min=10.14"); + config.define("DHAVE_FULLFSYNC", None); + config.define("HAVE_UINT128_EXTENSION", None); + config.flag_if_supported("-faligned-new"); + config.define("AVE_ALIGNED_NEW", None); } else if target.contains("android") { config.define("OS_ANDROID", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); + config.define("_REENTRANT", None); + config.flag("-fno-builtin-memcmp"); } else if target.contains("linux") { config.define("OS_LINUX", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); + println!("cargo:rustc-link-arg=-lpthread"); + println!("cargo:rustc-link-arg=-lrt"); + println!("cargo:rustc-link-arg=-ldl"); } else if target.contains("freebsd") { config.define("OS_FREEBSD", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); + println!("cargo:rustc-link-arg=-lpthread"); + config.flag("-fno-builtin-memcmp"); + config.define("_REENTRANT", None); } else if target.contains("openbsd") { config.define("OS_OPENBSD", None); config.define("ROCKSDB_PLATFORM_POSIX", None); config.define("ROCKSDB_LIB_IO_POSIX", None); + println!("cargo:rustc-link-arg=-pthread"); + config.flag("-fno-builtin-memcmp"); + config.define("_REENTRANT", None); } else if target.contains("windows") { link("rpcrt4", false); link("shlwapi", false); @@ -237,7 +262,15 @@ fn build_rocksdb() { if target.contains("msvc") { config.flag("-EHsc"); config.flag("-std:c++17"); + // set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zi /nologo /EHsc /GS /Gd /GR /GF /fp:precise /Zc:wchar_t /Zc:forScope /errorReport:queue") + // set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /FC /d2Zi+ /W4 /wd4127 /wd4800 /wd4996 /wd4351 /wd4100 /wd4204 /wd4324") } else { + if target.contains("x86_64") { + config.flag("-Wstrict-prototypes"); + } + //-W -Wextra -Wall -pthread + //-fno-omit-frame-pointer + //-momit-leaf-frame-pointer config.flag(&cxx_standard()); // matches the flags in CMakeLists.txt from rocksdb config.flag("-Wsign-compare"); @@ -260,6 +293,16 @@ fn build_rocksdb() { config.cpp(true); config.flag_if_supported("-std=c++17"); + + let dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + println!( + "cargo:rustc-link-search=native={}", + Path::new(&dir) + .join("rocksdb/plugin/ippcp/library/lib") + .display() + ); + println!("cargo:rustc-link-lib=static=ippcp"); + config.compile("librocksdb.a"); } @@ -351,7 +394,7 @@ fn main() { } let target = env::var("TARGET").unwrap(); if target.contains("openbsd") { - env::set_var("LIBCLANG_PATH","/usr/local/lib"); + env::set_var("LIBCLANG_PATH", "/usr/local/lib"); } bindgen_rocksdb(); diff --git a/librocksdb-sys/rocksdb b/librocksdb-sys/rocksdb index 293fe1a..217f764 160000 --- a/librocksdb-sys/rocksdb +++ b/librocksdb-sys/rocksdb @@ -1 +1 @@ -Subproject commit 293fe1abf86a497efcaa777500565326f9be3a5a +Subproject commit 217f7642119aa60a9fa64bc64e02d7f78813d911 diff --git a/librocksdb-sys/rocksdb_lib_sources.txt b/librocksdb-sys/rocksdb_lib_sources.txt index caa9031..3b7346a 100644 --- a/librocksdb-sys/rocksdb_lib_sources.txt +++ b/librocksdb-sys/rocksdb_lib_sources.txt @@ -243,6 +243,7 @@ util/stderr_logger.cc util/string_util.cc util/thread_local.cc util/threadpool_imp.cc +util/udt_util.cc util/xxhash.cc utilities/agg_merge/agg_merge.cc utilities/backup/backup_engine.cc @@ -309,3 +310,4 @@ utilities/ttl/db_ttl_impl.cc utilities/wal_filter.cc utilities/write_batch_with_index/write_batch_with_index.cc utilities/write_batch_with_index/write_batch_with_index_internal.cc +plugin/ippcp/ippcp_provider.cc