-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
42 lines (36 loc) · 1.13 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
extern crate cc;
extern crate bindgen;
use std::env;
use std::ffi::OsStr;
use std::path::PathBuf;
use glob::glob;
fn main() {
// Generate Rust Bindings for C Library
let bindings = bindgen::Builder::default()
.header("./extern/sofa.h") // Separate header than the source header
.rustfmt_bindings(true)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings.write_to_file(out_path.join("bindings.rs"))
.expect("Unable to save bindings");
// Compile C library
let src_files = glob("./extern/src/*.c")
.expect("Failed to read source files")
.filter(|entry| {
if let Ok(path) = entry {
path.file_name() != Some(OsStr::new("t_sofa_c.c"))
} else {
true
}
});
let mut cc_build = cc::Build::new();
for entry in src_files {
if let Ok(path) = entry {
cc_build.file(path);
}
}
cc_build.include("./extern/src")
.compile("sofa");
}