Skip to content

Commit 616f1f4

Browse files
committed
Re-add build script
1 parent f58547b commit 616f1f4

File tree

2 files changed

+47
-1
lines changed

2 files changed

+47
-1
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,6 @@ cat.png
184184
*.mlmodel
185185
# Mac OS X
186186
.DS_Store
187-
build*
188187

189188
# Jetbrain
190189
.idea

rust/build.rs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
extern crate bindgen;
2+
3+
use std::{env, path::PathBuf};
4+
5+
fn parse_clang_ver(raw_v: String) -> Vec<u32> {
6+
raw_v
7+
.split_whitespace()
8+
.nth(2)
9+
.unwrap()
10+
.split('.')
11+
.map(|v| v.parse::<u32>().unwrap())
12+
.collect()
13+
}
14+
15+
fn main() {
16+
let clang_ver = parse_clang_ver(bindgen::clang_version().full);
17+
let bindings = bindgen::Builder::default()
18+
.header(concat!(
19+
env!("CARGO_MANIFEST_DIR"),
20+
"/../include/tvm/runtime/c_runtime_api.h"
21+
))
22+
.header(concat!(
23+
env!("CARGO_MANIFEST_DIR"),
24+
"/../include/tvm/runtime/c_backend_api.h"
25+
))
26+
.rust_target(bindgen::RustTarget::Nightly)
27+
.clang_arg(concat!(
28+
"-I",
29+
env!("CARGO_MANIFEST_DIR"),
30+
"/../dlpack/include"
31+
))
32+
.clang_arg(format!("--target={}", env::var("HOST").unwrap()))
33+
.clang_arg("-I/usr/include")
34+
.clang_arg("-I/usr/local/include")
35+
.clang_arg(format!(
36+
"-I/usr/local/lib/clang/{}.{}.{}/include",
37+
clang_ver[0], clang_ver[1], clang_ver[2]
38+
))
39+
.layout_tests(false)
40+
.generate()
41+
.expect("Unable to generate bindings.");
42+
43+
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
44+
bindings
45+
.write_to_file(out_path.join("c_runtime_api.rs"))
46+
.expect("Unable to write bindings.");
47+
}

0 commit comments

Comments
 (0)