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
use anyhow::{format_err, Result};
use std::process::Command;
use structopt::StructOpt;
#[derive(StructOpt)]
struct Opts {
input_path: String,
output_path: String,
}
const MISSING_MESSAGE: &'static str = "Failed to execute wasm-bindgen.
Ensure you have 'wasm-bindgen' installed locally: cargo install wasm-bindgen-cli
If you are seeing this error in CQ you have made a mistake with your dependencies, ensure 'rust_wasmify' is not included in your build.";
fn main() -> Result<()> {
let opts = Opts::from_args();
let result = Command::new("wasm-bindgen")
.arg("--target=web")
.arg("--typescript")
.arg("--out-dir")
.arg(&opts.output_path)
.arg(&opts.input_path)
.status();
match result {
Err(e) => {
println!("{}", MISSING_MESSAGE);
Err(e.into())
}
Ok(s) => {
if s.success() {
Ok(())
} else {
Err(format_err!("Exit status was {}", s.code().unwrap_or_default()))
}
}
}
}