-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
48 lines (40 loc) · 1.56 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
use std::fs::metadata;
use std::env;
use std::fs::{self};
use std::path::{Path};
use std::process::{Command};
// use std::io::{stderr};
// use std::io::{self,Write};
static ARCHIVE: &'static str = "librocksdb.a";
static LIBNAME: &'static str = "rocksdb";
static PROJECT: &'static str = "rocksdb";
fn main() {
configure_rocksdb();
}
fn configure_rocksdb() {
//let mut stderr = io::stderr();
let src = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).join(PROJECT);
let archive = src.join(ARCHIVE);
//writeln!(&mut stderr,"looking for {}", archive.display()).unwrap();
if !metadata(archive.clone()).is_ok() {
let mut make = Command::new("make");
make.current_dir(&src);
// writeln!(&mut stderr,"running: {:?}", make).unwrap();
let _ = make.arg("static_lib").status().unwrap();
}
// writeln!(&mut stderr, "validating that archive exists").unwrap();
assert!(metadata(archive.clone()).is_ok(), "Error: archive does not exist after build");
// copy to the output folder
let out = &env::var("OUT_DIR").unwrap();
let dst = Path::new(out);
// writeln!(&mut stderr, "creating {}",dst.display()).unwrap();
let _ = fs::create_dir_all(&dst).unwrap();
match fs::copy(&archive, &dst.join(ARCHIVE)) {
Ok(_) => {},
Err(a) => {
panic!(format!("Error {:?} when copying \n{} \nto {}", a,
archive.display(), dst.display()));
}
}
println!("cargo:rustc-flags=-L native={} -l static={} -l dylib=stdc++ -l dylib=z -l dylib=bz2",dst.display(), LIBNAME);
}