-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
60 lines (53 loc) · 1.9 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
extern crate cmake;
//extern crate cpp_build;
extern crate bindgen;
use std::env;
fn main()
{
let tensorrt_root = env::var("TENSORRT_ROOT")
.expect("Can not find TENSORRT_ROOT env var.");
let cuda_root = match env::var("CUDA_HOME") {
Ok(v) => v,
Err(_) => String::from("/usr/local/cuda"),
};
let cpp_libs = cmake::Config::new(".")
.define("TENSORRT_ROOT", &tensorrt_root)
.build();
println!("cargo:rustc-link-search=native={}", cpp_libs.display());
println!("cargo:rustc-link-search=native={}/lib", &tensorrt_root);
println!("cargo:rustc-link-search=native={}/lib64", &cuda_root);
println!("cargo:rustc-link-lib=nvinfer");
println!("cargo:rustc-link-lib=cudart");
println!("cargo:rustc-link-lib=static=retinaface");
println!("cargo:rerun-if-changed=libretinaface/**/*");
println!("cargo:rerun-if-changed=wrapper.hpp");
let target = env::var("TARGET").unwrap();
if target.contains("apple")
{
println!("cargo:rustc-link-lib=dylib=c++");
} else if target.contains("linux")
{
println!("cargo:rustc-link-lib=dylib=stdc++");
} else {
unimplemented!();
}
let bindings = bindgen::Builder::default()
.header("wrapper.hpp")
.clang_arg("-x")
.clang_arg("c++")
.clang_arg(format!("-I{}/include", &tensorrt_root))
.clang_arg(format!("-I{}/include", &cuda_root))
.whitelist_type("mal::.*")
.whitelist_function("mal::.*")
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file("src/bindings.rs")
.expect("Couldn't write bindings!");
// cpp_build::Config::new()
// .include(format!("{}/include", &tensorrt_root))
// .include(format!("{}/include", &cuda_root))
// .include("/usr/local/include/opencv4")
// .include("libretinaface/src")
// .build("src/lib.rs");
}