blob: 6b4a86dcb8e687d7643178d66bf2b5dd588567cd (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
use std::{env, path::PathBuf};
fn rocksdb_include_dir() -> String {
match env::var("ROCKSDB_INCLUDE_DIR") {
Ok(val) => val,
Err(_) => "/usr/local/include".to_string(), // RW 2024-01-11
}
}
fn bindgen_rocksdb() {
let bindings = bindgen::Builder::default()
.header(rocksdb_include_dir() + "/rocksdb/c.h")
.derive_debug(false)
.blocklist_type("max_align_t") // https://github.com/rust-lang-nursery/rust-bindgen/issues/550
.ctypes_prefix("libc")
.size_t_is_usize(true)
.generate()
.expect("unable to generate rocksdb bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("unable to write rocksdb bindings");
}
fn main() {
println!("cargo:rustc-link-search=all=/usr/local/lib");
bindgen_rocksdb();
let target = env::var("TARGET").unwrap();
// according to https://github.com/alexcrichton/cc-rs/blob/master/src/lib.rs#L2189
if target.contains("apple") || target.contains("freebsd") || target.contains("openbsd") {
println!("cargo:rustc-link-lib=dylib=c++");
} else if target.contains("linux") {
println!("cargo:rustc-link-lib=dylib=stdc++");
}
println!("cargo:rustc-link-lib=dylib=rocksdb");
println!("cargo:rustc-link-lib=dylib=zstd");
// Allow dependent crates to locate the sources and output directory of
// this crate. Notably, this allows a dependent crate to locate the RocksDB
// sources and built archive artifacts provided by this crate.
println!(
"cargo:cargo_manifest_dir={}",
env::var("CARGO_MANIFEST_DIR").unwrap()
);
println!("cargo:out_dir={}", env::var("OUT_DIR").unwrap());
}
|