-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
55 lines (49 loc) · 1.53 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
use std::{
env,
io::{Error, ErrorKind},
path::{Path, PathBuf},
process::Command,
};
const CORE_HEADER: &str = "core/include/triton/core/tritonserver.h";
const CORE_BINDINGS_FILE_NAME: &str = "tritonserver.rs";
fn main() -> Result<(), Error> {
let no_header_file = !Path::new(CORE_HEADER).is_file();
if no_header_file {
Command::new("git")
.arg("submodule")
.arg("update")
.arg("--init")
.arg("--recursive")
.status()
.and_then(|status| {
if status.success() {
Ok(())
} else {
Err(Error::new(
ErrorKind::Other,
format!("Git init return error: {}", status),
))
}
})?;
}
let out_dir = Path::new(&env::var("OUT_DIR").unwrap())
.canonicalize()
.unwrap();
println!("cargo:rerun-if-changed={}", CORE_HEADER);
bindgen::builder()
.header(CORE_HEADER)
.clang_args(["-x", "c++"])
.layout_tests(false)
.dynamic_link_require_all(true)
.generate()
.map_err(|_| Error::new(ErrorKind::Other, "Bindgen generate error"))
.and_then(|bindings| {
bindings.write_to_file(
[out_dir.as_path(), Path::new(CORE_BINDINGS_FILE_NAME)]
.iter()
.collect::<PathBuf>(),
)
})?;
println!("cargo:rustc-link-lib=dylib=tritonserver");
Ok(())
}