-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
69 lines (59 loc) · 1.99 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
64
65
66
67
68
69
use std::process::Command;
fn main() {
// This tells Cargo to re-run the build script if the worker code changes.
println!("cargo:rerun-if-changed=audio_worker/src/");
println!("cargo:rerun-if-changed=static/rust_audio_processor.js");
println!("cargo:rerun-if-changed=static/text_decoder.js");
println!("cargo:rerun-if-changed=audio_worker/Cargo.toml");
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:warning=Building worker code");
// Build the worker's Rust code as WebAssembly
let status = Command::new("cargo")
.args(&[
"build",
"--target",
"wasm32-unknown-unknown",
"--release",
"--manifest-path",
"audio_worker/Cargo.toml",
])
.status()
.expect("Failed to build worker's Rust code");
if !status.success() {
panic!("Failed to build worker's Rust code");
}
// Run wasm-bindgen to generate the JavaScript bindings
let status = Command::new("wasm-bindgen")
.args(&[
"--out-dir",
"static/worker",
"--target",
"web",
"--no-typescript",
"audio_worker/target/wasm32-unknown-unknown/release/audio_worker.wasm",
])
.status()
.expect("Failed to run wasm-bindgen");
if !status.success() {
panic!("Failed to run wasm-bindgen");
}
// Bundle the worker JavaScript files using esbuild
let status = Command::new(get_esbuild())
.args(&[
"--bundle",
"static/rust_audio_processor.js",
"--outfile=static/worker/bundled_rust_audio_processor.js",
"--format=iife",
])
.status()
.expect("Failed to bundle worker JavaScript files");
if !status.success() {
panic!("Failed to bundle worker JavaScript files");
}
}
fn get_esbuild() -> &'static str {
if cfg!(target_os = "windows") {
return "esbuild.cmd";
}
return "esbuild";
}