forked from cholcombe973/libnfs-sys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
59 lines (52 loc) · 1.81 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
extern crate bindgen;
use std::env;
use std::path::{Path, PathBuf};
fn main() {
let link_static_env_if_any = env::var("LIBNFS_LINK_STATIC");
match link_static_env_if_any {
Ok(link_static) => {
if link_static == "true" {
println!("cargo:rustc-link-lib=static=nfs");
} else {
println!("cargo:rustc-link-lib=nfs");
}
},
Err(_) => {
println!("cargo:rustc-link-lib=nfs");
},
}
let libnfs_lib_path_if_any = env::var("LIBNFS_LIB_PATH");
match libnfs_lib_path_if_any {
Ok(lib_dir) => {
let lib_dir = Path::new(&lib_dir);
println!("cargo:rustc-link-search=native={}", lib_dir.display());
},
Err(_) => {},
}
// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let mut builder = bindgen::Builder::default()
// The input header we would like to generate
// bindings for.
.header("wrapper.h");
let libnfs_include_path_if_any = env::var("LIBNFS_INCLUDE_PATH");
match libnfs_include_path_if_any {
Ok(include_path) => {
let include_path = Path::new(&include_path);
builder = builder.clang_arg(format!("-I{}", include_path.display()));
},
Err(_) => {},
}
//.blacklist_type("statvfs")
let bindings = builder
// Finish the builder and generate the bindings.
.generate()
// Unwrap the Result and panic on failure.
.expect("Unable to generate bindings");
// Write the bindings to the $OUT_DIR/bindings.rs file.
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}