-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
29 lines (23 loc) · 856 Bytes
/
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
use bindgen;
use cc;
use std::env;
use std::path::PathBuf;
// https://doc.rust-lang.org/cargo/reference/build-scripts.html
fn main() {
let c_lib_name = "mylib";
println!("cargo:rerun-if-changed=c-src/*");
println!("cargo:rustc-link-lib={}", c_lib_name);
cc::Build::new()
.file(format!("c-src/{}.c", c_lib_name))
.compile(c_lib_name);
let bindings = bindgen::Builder::default()
.header(format!("c-src/{}.h", c_lib_name))
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.rustfmt_bindings(true)
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join(format!("{}.rs", c_lib_name)))
.expect(format!("Can not write bindings to {:?}", out_path).as_str());
}