54 lines
1.5 KiB
Rust
Raw Normal View History

2017-12-18 12:39:14 -08:00
extern crate wasm_bindgen_cli_support;
2017-12-14 19:31:01 -08:00
#[macro_use]
extern crate serde_derive;
extern crate docopt;
use std::path::PathBuf;
use docopt::Docopt;
2017-12-18 12:39:14 -08:00
use wasm_bindgen_cli_support::Bindgen;
2017-12-14 19:31:01 -08:00
const USAGE: &'static str = "
Generating JS bindings for a wasm file
Usage:
wasm-bindgen [options] <input>
Options:
-h --help Show this screen.
--output-ts FILE Output TypeScript file
2017-12-14 19:31:01 -08:00
--output-wasm FILE Output WASM file
2017-12-14 21:55:21 -08:00
--nodejs Generate output for node.js, not the browser
2017-12-20 12:50:10 -08:00
--debug Include otherwise-extraneous debug checks in output
2017-12-14 19:31:01 -08:00
";
#[derive(Debug, Deserialize)]
struct Args {
flag_output_ts: Option<PathBuf>,
2017-12-14 19:31:01 -08:00
flag_output_wasm: Option<PathBuf>,
2017-12-14 21:55:21 -08:00
flag_nodejs: bool,
2017-12-20 12:50:10 -08:00
flag_debug: bool,
2017-12-14 19:31:01 -08:00
arg_input: PathBuf,
}
fn main() {
let args: Args = Docopt::new(USAGE)
.and_then(|d| d.deserialize())
.unwrap_or_else(|e| e.exit());
let mut b = Bindgen::new();
b.input_path(&args.arg_input)
.nodejs(args.flag_nodejs)
.debug(args.flag_debug)
.uglify_wasm_names(!args.flag_debug);
2017-12-14 19:31:01 -08:00
let ret = b.generate().expect("failed to generate bindings");
if let Some(ref ts) = args.flag_output_ts {
ret.write_ts_to(ts).expect("failed to write TypeScript output file");
2017-12-14 21:55:21 -08:00
} else {
println!("{}", ret.generate_ts());
2017-12-14 19:31:01 -08:00
}
if let Some(ref wasm) = args.flag_output_wasm {
ret.write_wasm_to(wasm).expect("failed to write wasm output file");
}
}