Fix building librocksdb-sys with system libraries (#393)

master
Bas van Dijk 5 years ago committed by GitHub
parent 49c679f7f2
commit 8a7996e943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 38
      librocksdb-sys/build.rs

@ -26,9 +26,16 @@ fn fail_on_empty_directory(name: &str) {
} }
} }
fn rocksdb_include_dir() -> String {
match env::var("ROCKSDB_INCLUDE_DIR") {
Ok(val) => return val,
Err(_) => return "rocksdb/include".to_string(),
};
}
fn bindgen_rocksdb() { fn bindgen_rocksdb() {
let bindings = bindgen::Builder::default() let bindings = bindgen::Builder::default()
.header("rocksdb/include/rocksdb/c.h") .header(rocksdb_include_dir() + "/rocksdb/c.h")
.derive_debug(false) .derive_debug(false)
.blacklist_type("max_align_t") // https://github.com/rust-lang-nursery/rust-bindgen/issues/550 .blacklist_type("max_align_t") // https://github.com/rust-lang-nursery/rust-bindgen/issues/550
.ctypes_prefix("libc") .ctypes_prefix("libc")
@ -300,38 +307,37 @@ fn try_to_find_and_link_lib(lib_name: &str) -> bool {
fn main() { fn main() {
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=rocksdb/");
println!("cargo:rerun-if-changed=snappy/");
println!("cargo:rerun-if-changed=lz4/");
println!("cargo:rerun-if-changed=zstd/");
println!("cargo:rerun-if-changed=zlib/");
println!("cargo:rerun-if-changed=bzip2/");
fail_on_empty_directory("rocksdb");
fail_on_empty_directory("snappy");
fail_on_empty_directory("lz4");
fail_on_empty_directory("zstd");
fail_on_empty_directory("zlib");
fail_on_empty_directory("bzip2");
bindgen_rocksdb(); bindgen_rocksdb();
if !try_to_find_and_link_lib("ROCKSDB") { if !try_to_find_and_link_lib("ROCKSDB") {
println!("cargo:rerun-if-changed=rocksdb/");
fail_on_empty_directory("rocksdb");
build_rocksdb(); build_rocksdb();
} }
if cfg!(feature = "snappy") && !try_to_find_and_link_lib("SNAPPY") { if cfg!(feature = "snappy") && !try_to_find_and_link_lib("SNAPPY") {
println!("cargo:rerun-if-changed=snappy/");
fail_on_empty_directory("snappy");
build_snappy(); build_snappy();
} }
if cfg!(feature = "lz4") && !try_to_find_and_link_lib("LZ4") { if cfg!(feature = "lz4") && !try_to_find_and_link_lib("LZ4") {
println!("cargo:rerun-if-changed=lz4/");
fail_on_empty_directory("lz4");
build_lz4(); build_lz4();
} }
if cfg!(feature = "zstd") && !try_to_find_and_link_lib("ZSTD") { if cfg!(feature = "zstd") && !try_to_find_and_link_lib("ZSTD") {
println!("cargo:rerun-if-changed=zstd/");
fail_on_empty_directory("zstd");
build_zstd(); build_zstd();
} }
if cfg!(feature = "zlib") && !try_to_find_and_link_lib("ZLIB") { if cfg!(feature = "zlib") && !try_to_find_and_link_lib("Z") {
println!("cargo:rerun-if-changed=zlib/");
fail_on_empty_directory("zlib");
build_zlib(); build_zlib();
} }
if cfg!(feature = "bzip2") && !try_to_find_and_link_lib("BZIP2") { if cfg!(feature = "bzip2") && !try_to_find_and_link_lib("BZ2") {
println!("cargo:rerun-if-changed=bzip2/");
fail_on_empty_directory("bzip2");
build_bzip2(); build_bzip2();
} }
} }

Loading…
Cancel
Save