-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
61 lines (53 loc) · 1.58 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
extern crate cc;
use std::path::PathBuf;
use std::{env, fs};
fn get_ff_path() -> Option<String> {
if let Some(val) = env::var_os("FF_PATH") {
let s = val.to_str().unwrap();
return Some(String::from(s));
}
if let Some(val) = dirs::home_dir() {
let ff_home = val.join("fastflow");
if ff_home.is_dir() {
let s = ff_home.to_str().unwrap();
return Some(String::from(s));
}
}
return None;
}
fn main() {
// search for FastFlow
let ff_path = get_ff_path();
if ff_path.is_none() {
panic!("FastFlow not found!");
}
let ff_path = ff_path.unwrap();
println!("FF_PATH={}", ff_path);
// get c++ benches path
let benches: Vec<PathBuf> = fs::read_dir("libffbuffer/benches")
.expect("read_dir call failed")
.map(|a| a.expect("read_file failed").path())
.collect();
// general configuration
let mut build = cc::Build::new();
build
.file("libffbuffer/ff_ubuffer.cpp")
.files(benches.clone())
.cpp(true)
.opt_level(3)
.warnings(false)
.include(ff_path);
// optinal cross language feature
if cfg!(feature = "crosslto") {
build.flag("-flto=thin")
.compiler("clang");
}
// comnpile c++ library
build.compile("ffbuffer");
// set rerun if c++ lib change
println!("cargo:rerun-if-changed=./libffbuffer/ff_ubuffer.cpp");
println!("cargo:rerun-if-changed=./libffbuffer/ff_ubuffer.hpp");
for p in benches {
println!("cargo:rerun-if-changed={}", p.display());
}
}