-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
62 lines (54 loc) · 1.83 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
extern crate pkg_config;
extern crate vergen;
use std::env;
use std::fs;
use std::path::PathBuf;
use std::process::{Command, Stdio};
use vergen::*;
fn main() {
let mut flags = OutputFns::all();
flags.toggle(NOW);
assert!(vergen(flags).is_ok());
let latest = env::var("CARGO_FEATURE_LATEST").is_ok();
if latest {
build_tokyocabinet();
} else {
let has_pkgconfig = Command::new("pkg-config").output().is_ok();
if has_pkgconfig && pkg_config::find_library("libtokyocabinet").is_ok() {
return;
} else {
build_tokyocabinet();
}
}
}
fn build_tokyocabinet() {
let manifest_dir = match env::var_os("CARGO_MANIFEST_DIR") {
Some(d) => d,
None => panic!("Unable to read manifest dir"),
};
let out_dir = match env::var_os("OUT_DIR") {
Some(d) => d,
None => panic!("Unable to read output dir"),
};
let src = PathBuf::from(&manifest_dir).join("tokyocabinet");
let dst = PathBuf::from(&out_dir).join("build");
let _ = fs::create_dir(&dst);
run(Command::new("./configure")
.args(&["--enable-fastest", "--disable-bzip"]) // bzip2-sys has some trouble playing nicely.
.env("CFLAGS", "-fPIC")
.env("CPPFLAGS", "-fPIC")
.current_dir(&src));
run(Command::new("make").current_dir(&src));
let _ = fs::copy(&src.join("libtokyocabinet.a"), &dst.join("libtokyocabinet.a"));
println!("cargo:rustc-link-lib=static=tokyocabinet");
println!("cargo:rustc-link-search=native=/usr/lib64");
println!("cargo:rustc-link-lib=z");
println!("cargo:rustc-flags=-L {}", dst.display());
}
fn run(cmd: &mut Command) {
assert!(cmd.stdout(Stdio::inherit())
.stderr(Stdio::inherit())
.status()
.unwrap()
.success());
}