-
Notifications
You must be signed in to change notification settings - Fork 5
/
build.rs
67 lines (55 loc) · 2.14 KB
/
build.rs
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
use std::process::{Command, exit};
use std::env;
use std::path::Path;
use std::fs::File;
use std::io::{BufRead, BufReader, Write, stderr};
fn main() {
let mut stderr = stderr();
let out_dir = env::var("OUT_DIR").unwrap();
let num_jobs = env::var("NUM_JOBS");
let mut cmd = Command::new("make");
cmd.current_dir(Path::new("rocksdb"))
.arg("EXTRA_CFLAGS=-fPIC")
.arg("EXTRA_CXXFLAGS=-fPIC")
.arg(format!("INSTALL_PATH={}", out_dir));
if let Ok(jobs) = num_jobs {
cmd.arg(format!("-j{}", jobs));
}
cmd.arg("install-static");
match cmd.output() {
Ok(out) => if !out.status.success() {
let _ = writeln!(&mut stderr, "build failed:\nstdout:\n{}\nstderr:\n{}",
String::from_utf8(out.stdout).unwrap(), String::from_utf8(out.stderr).unwrap());
exit(1);
},
Err(e) => { let _ = writeln!(&mut stderr, "command execution failed: {:?}", e); exit(1) }
}
let config = match File::open("rocksdb/make_config.mk") {
Ok(c) => c,
Err(e) => { let _ = writeln!(&mut stderr, "Failed to open rocksdb/make_config.mk: {}", e); exit(1) }
};
let config = BufReader::new(config);
let mut lz4 = false;
let mut snappy = false;
let mut zlib = false;
let mut bzip2 = false;
for line in config.lines() {
let line = line.unwrap();
let words: Vec<_> = line.split_whitespace().collect();
if !words[0].starts_with("PLATFORM_LDFLAGS=") {
continue
}
lz4 = words.iter().any(|w| *w == "-llz4");
snappy = words.iter().any( |w| *w == "-lsnappy");
zlib = words.iter().any(|w| *w == "-lz");
bzip2 = words.iter().any(|w| *w == "-lbz2");
break;
}
println!("cargo:rustc-link-search=native={}/lib", out_dir);
println!("cargo:rustc-link-lib=static=rocksdb");
println!("cargo:rustc-link-lib=stdc++");
if lz4 { println!("cargo:rustc-link-lib=lz4"); }
if snappy { println!("cargo:rustc-link-lib=snappy"); }
if zlib { println!("cargo:rustc-link-lib=z"); }
if bzip2 { println!("cargo:rustc-link-lib=bz2"); }
}