-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.rs
38 lines (37 loc) · 1.21 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
use std::env;
use std::fs;
use std::process::{Command, Stdio};
fn main() {
println!("cargo:rerun-if-changed=build.rs");
for entry in fs::read_dir("samples").expect("samples/ dir exists") {
let entry = entry.expect("valid entry");
let path = entry.path();
let path = path.to_str().expect("valid Unicode");
println!("cargo:rerun-if-changed={}", path);
// Compile to native and WASI
let out_dir = env::var("OUT_DIR").expect("OUT_DIR is defined");
let mut cmd = Command::new("rustc");
cmd.args(&["-O", "--out-dir", &out_dir, &path])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit());
match cmd.status() {
Ok(_) => {}
Err(e) => panic!("rustc (native) failed with error: {}", e),
}
let mut cmd = Command::new("rustc");
cmd.args(&[
"--target",
"wasm32-wasi",
"-O",
"--out-dir",
&out_dir,
&path,
])
.stdout(Stdio::inherit())
.stderr(Stdio::inherit());
match cmd.status() {
Ok(_) => {}
Err(e) => panic!("rustc (wasi) failed with error: {}", e),
}
}
}