-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
34 lines (31 loc) · 1.29 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
use std::env;
use std::path::PathBuf;
fn main() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let ncnn_include_dir = env::var("NCNN_INCLUDE_DIR")
.map(|dir| PathBuf::from(dir))
.expect(
"ERROR: please set NCNN_INCLUDE_DIR,e.g. export NCNN_INCLUDE_DIR=/path/to/ncnn/include",
);
if !ncnn_include_dir.join("c_api.h").exists() {
panic!(
"ERROR: please set NCNN_INCLUDE_DIR,e.g2. export NCNN_INCLUDE_DIR=/path/to/ncnn/include"
);
}
// println!("cargo:rerun-if-env-changed=NCNN_INCLUDE_DIR");
let bindings = bindgen::Builder::default()
.header(format!("{}/gpu.h", ncnn_include_dir.display())) // 启用gpu相关的函数;# 对cpu模式,包含gpu.h头文件,所以不做处理
.header(format!("{}/c_api.h", ncnn_include_dir.display())) // 通用入口
// .clang_arg(format!("-I{}", ncnn_include_dir.display())) // 无效
.clang_arg("-x")
.clang_arg("c++")
.allowlist_type("regex")
.allowlist_function("ncnn.*")
.allowlist_var("NCNN.*")
.allowlist_type("ncnn.*")
.generate()
.expect("Unable to generate bindings");
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
}