-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.rs
63 lines (52 loc) · 1.76 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
use lazy_static::lazy_static;
use std::{env, path::PathBuf};
// Target triple for WASM
const WASM32_UNKNOWN_EMSCRIPTEN: &str = "wasm32-unknown-emscripten";
// Target-specifc build settings
struct BuildSettings {
link_args: Vec<String>,
}
fn is_wasm_build() -> bool {
match env::var("TARGET") {
Ok(target) => target == WASM32_UNKNOWN_EMSCRIPTEN,
Err(_) => panic!("TARGET environment variable not set"),
}
}
lazy_static! {
// Native library dependencies
static ref TARGET_BUILD_SETTINGS: BuildSettings = match is_wasm_build() {
true => BuildSettings{
link_args: vec![String::from("--no-entry"), String::from("-sERROR_ON_UNDEFINED_SYMBOLS=0")],
},
_ => BuildSettings{
link_args: vec![],
},
};
}
fn register_link_arg(arg: &String) {
println!("cargo:rustc-link-arg={}", arg);
}
fn apply_build_settings(build_settings: &BuildSettings) {
build_settings.link_args.iter().for_each(register_link_arg);
}
fn main() {
// Always re-run the build script
println!("cargo:rerun-if-changed=NULL");
if is_wasm_build() {
uniffi::generate_scaffolding("src/dotlottie_player_cpp.udl").unwrap();
} else {
uniffi::generate_scaffolding("src/dotlottie_player.udl").unwrap();
}
// Apply build settings
apply_build_settings(&TARGET_BUILD_SETTINGS);
// Execute cbindgen
let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
let config_path = PathBuf::from(&crate_dir).join("cbindgen.toml");
let config = cbindgen::Config::from_file(config_path).unwrap();
cbindgen::Builder::new()
.with_crate(crate_dir)
.with_config(config)
.generate()
.expect("Unable to generate bindings")
.write_to_file("bindings.h");
}