-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
37 lines (30 loc) · 1.01 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
extern crate bindgen;
use std::path::PathBuf;
use std::process::Command;
use std::env;
fn gen_bindings() {
let bindings = bindgen::Builder::default()
.header("adder.h")
// Uncomment this to make build successful
// .trust_clang_mangling(false)
.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("Couldn't write bindings!");
}
fn main() {
gen_bindings();
let current_dir = env::current_dir().unwrap();
let _ = Command::new("emcc")
.args(&["-o", "adder.bc", "adder.c"])
.status()
.expect("failed to compile adder.c");
let _ = Command::new("emar")
.args(&["cr", "libadder.a", "adder.bc"])
.status()
.expect("failed to archive libadder.a");
println!("cargo:rustc-link-search=native={}", current_dir.to_str().unwrap());
println!("cargo:rustc-link-lib=static=adder");
}