|
|
@ -29,10 +29,7 @@ fn fail_on_empty_directory(name: &str) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn build_rocksdb() { |
|
|
|
fn bindgen_rocksdb() { |
|
|
|
println!("cargo:rerun-if-changed=build.rs"); |
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed=rocksdb/"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let bindings = bindgen::Builder::default() |
|
|
|
let bindings = bindgen::Builder::default() |
|
|
|
.header("rocksdb/include/rocksdb/c.h") |
|
|
|
.header("rocksdb/include/rocksdb/c.h") |
|
|
|
.hide_type("max_align_t") // https://github.com/rust-lang-nursery/rust-bindgen/issues/550
|
|
|
|
.hide_type("max_align_t") // https://github.com/rust-lang-nursery/rust-bindgen/issues/550
|
|
|
@ -44,7 +41,9 @@ fn build_rocksdb() { |
|
|
|
bindings |
|
|
|
bindings |
|
|
|
.write_to_file(out_path.join("bindings.rs")) |
|
|
|
.write_to_file(out_path.join("bindings.rs")) |
|
|
|
.expect("unable to write rocksdb bindings"); |
|
|
|
.expect("unable to write rocksdb bindings"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn build_rocksdb() { |
|
|
|
let mut config = cc::Build::new(); |
|
|
|
let mut config = cc::Build::new(); |
|
|
|
config.include("rocksdb/include/"); |
|
|
|
config.include("rocksdb/include/"); |
|
|
|
config.include("rocksdb/"); |
|
|
|
config.include("rocksdb/"); |
|
|
@ -148,9 +147,32 @@ fn build_snappy() { |
|
|
|
config.compile("libsnappy.a"); |
|
|
|
config.compile("libsnappy.a"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn try_to_find_and_link_lib(lib_name: &str) -> bool { |
|
|
|
|
|
|
|
if let Ok(lib_dir) = env::var(&format!("{}_LIB_DIR", lib_name)) { |
|
|
|
|
|
|
|
println!("cargo:rustc-link-search=native={}", lib_dir); |
|
|
|
|
|
|
|
let mode = match env::var_os(&format!("{}_STATIC", lib_name)) { |
|
|
|
|
|
|
|
Some(_) => "static", |
|
|
|
|
|
|
|
None => "dylib", |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
println!("cargo:rustc-link-lib={}={}", mode, lib_name.to_lowercase()); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
false |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn main() { |
|
|
|
fn main() { |
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed=build.rs"); |
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed=rocksdb/"); |
|
|
|
|
|
|
|
println!("cargo:rerun-if-changed=snappy/"); |
|
|
|
|
|
|
|
|
|
|
|
fail_on_empty_directory("rocksdb"); |
|
|
|
fail_on_empty_directory("rocksdb"); |
|
|
|
fail_on_empty_directory("snappy"); |
|
|
|
fail_on_empty_directory("snappy"); |
|
|
|
|
|
|
|
bindgen_rocksdb(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !try_to_find_and_link_lib("ROCKSDB") { |
|
|
|
build_rocksdb(); |
|
|
|
build_rocksdb(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if !try_to_find_and_link_lib("SNAPPY") { |
|
|
|
build_snappy(); |
|
|
|
build_snappy(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|