-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.rs
54 lines (48 loc) · 1.68 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
use std::env;
use std::path::{Path, PathBuf};
use std::process::Command;
use wasm_bindgen_cli_support::Bindgen;
fn main() -> anyhow::Result<()> {
embuild::build::CfgArgs::output_propagated("ESP_IDF")?;
embuild::build::LinkArgs::output_propagated("ESP_IDF")?;
let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
let frontend_crate_dir = Path::new("./frontend");
let frontend_target_dir = out_dir.join("frontend");
let frontend_out_dir = frontend_target_dir
.join("wasm32-unknown-unknown")
.join("release");
// Rerun build script if frontend crate changed
println!("cargo:rerun-if-changed={}", frontend_crate_dir.display());
println!(
"cargo:rerun-if-changed={}",
Path::new("./Cargo.lock").display()
);
// Compile frontend crate to webassembly
assert!(Command::new("cargo")
.arg("build")
.arg("--release")
.arg("--target=wasm32-unknown-unknown")
.arg("--package=frontend")
.args(["--target-dir", frontend_target_dir.to_str().unwrap()])
.status()?
.success());
// Generate bindgen wasm and js module
Bindgen::new()
.input_path(&frontend_out_dir.join("frontend.wasm"))
.typescript(false)
.remove_name_section(true)
.remove_producers_section(true)
.demangle(false)
.web(true)?
.generate(&frontend_out_dir)?;
// Export path to bg.wasm and js bindings
println!(
"cargo:rustc-env=JS_BLOB_PATH={}",
frontend_out_dir.join("frontend.js").display()
);
println!(
"cargo:rustc-env=WASM_BLOB_PATH={}",
frontend_out_dir.join("frontend_bg.wasm").display()
);
Ok(())
}