-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.rs
39 lines (33 loc) · 1.25 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
use std::env;
use std::path::PathBuf;
fn main() {
// Build verovio. Enable the WASM build as this will also build the c static library
let dst = cmake::Config::new("verovio/cmake")
.define("BUILD_AS_WASM", "ON")
.no_build_target(true)
.build();
println!("cargo:rustc-link-search={}/build", dst.display());
// Static link to verovio
println!("cargo:rustc-link-lib=static=verovio");
// Dynamic link to cpp runtime
let target = env::var("TARGET").unwrap();
if target.contains("apple") {
println!("cargo:rustc-link-lib=dylib=c++");
} else if target.contains("linux") {
println!("cargo:rustc-link-lib=dylib=stdc++");
} else {
unimplemented!();
}
println!("cargo:rerun-if-changed=verovio/tools/c_wrapper.h");
// Generate the bindings from C api
let bindings = bindgen::Builder::default()
.header("verovio/tools/c_wrapper.h")
.clang_arg("-includestdbool.h")
.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("Couldn't write bindings!");
}