-
Notifications
You must be signed in to change notification settings - Fork 2
/
build.rs
40 lines (37 loc) · 1.62 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
use std::path::Path;
fn main() {
/* tell Cargo to rerun this build script if the given directories change */
println!("cargo:rerun-if-changed=client/src");
println!("cargo:rerun-if-changed=client/public");
println!("cargo:rerun-if-changed=shared/src");
/* set up some environmental variables */
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let js_file = Path::new(&out_dir).join("client.js");
let wasm_file = Path::new(&out_dir).join("client_bg.wasm");
/* build the Web-Assembly module */
let success = std::process::Command::new("wasm-pack")
.args(&[
"build",
"--target",
"web",
"--out-name",
"client",
"--out-dir"
])
.arg(out_dir)
.arg("client")
.spawn()
.expect("Could not execute wasm-pack, is it installed? https://rustwasm.github.io/wasm-pack/installer/")
.wait()
.expect("Could not execute wasm-pack, is it installed? https://rustwasm.github.io/wasm-pack/installer/")
.success();
/* check compilation exit code and if generated files exist */
assert!(success, "Failed to compile client");
eprintln!("Checking if {} exists", wasm_file.to_string_lossy());
assert!(wasm_file.exists(), "WebAssembly module not generated");
eprintln!("Checking if {} exists", js_file.to_string_lossy());
assert!(wasm_file.exists(), "Javascript bindings not generated");
/* set up some environmental variables */
println!("cargo:rustc-env=CLIENT_JS={}", js_file.display());
println!("cargo:rustc-env=CLIENT_WASM={}", wasm_file.display());
}