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;
|
2018-03-01 19:19:12 -08:00
|
|
|
extern crate wasm_bindgen_shared;
|
2018-04-25 11:42:22 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate failure;
|
2017-12-14 19:31:01 -08:00
|
|
|
|
|
|
|
use std::path::PathBuf;
|
2018-04-25 11:42:22 -07:00
|
|
|
use std::process;
|
2017-12-14 19:31:01 -08:00
|
|
|
|
|
|
|
use docopt::Docopt;
|
2018-04-25 11:42:22 -07:00
|
|
|
use failure::Error;
|
2018-06-27 22:42:34 -07: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>
|
2017-12-27 07:50:43 -08:00
|
|
|
wasm-bindgen -h | --help
|
2018-03-01 19:19:12 -08:00
|
|
|
wasm-bindgen -V | --version
|
2017-12-14 19:31:01 -08:00
|
|
|
|
|
|
|
Options:
|
2018-03-07 08:50:56 -08:00
|
|
|
-h --help Show this screen.
|
|
|
|
--out-dir DIR Output directory
|
2018-03-28 07:37:56 -07:00
|
|
|
--nodejs Generate output that only works in node.js
|
|
|
|
--browser Generate output that only works in a browser
|
2018-04-11 13:59:58 +05:45
|
|
|
--no-modules Generate output that only works in a browser (without modules)
|
2018-04-19 13:33:58 -07:00
|
|
|
--no-modules-global VAR Name of the global variable to initialize
|
2018-04-27 07:14:46 -07:00
|
|
|
--typescript Output a TypeScript definition file (on by default)
|
|
|
|
--no-typescript Don't emit a *.d.ts file
|
2018-03-07 08:50:56 -08:00
|
|
|
--debug Include otherwise-extraneous debug checks in output
|
2018-04-11 11:43:18 -07:00
|
|
|
--no-demangle Don't demangle Rust symbol names
|
2018-07-13 08:10:51 -07:00
|
|
|
--keep-debug Keep debug sections in wasm files
|
2018-03-07 08:50:56 -08:00
|
|
|
-V --version Print the version number of wasm-bindgen
|
2017-12-14 19:31:01 -08:00
|
|
|
";
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize)]
|
|
|
|
struct Args {
|
2017-12-14 21:55:21 -08:00
|
|
|
flag_nodejs: bool,
|
2018-03-28 07:37:56 -07:00
|
|
|
flag_browser: bool,
|
2018-04-11 13:59:58 +05:45
|
|
|
flag_no_modules: bool,
|
2018-01-29 21:20:38 -08:00
|
|
|
flag_typescript: bool,
|
2018-04-27 07:14:46 -07:00
|
|
|
flag_no_typescript: bool,
|
2018-01-29 21:20:38 -08:00
|
|
|
flag_out_dir: Option<PathBuf>,
|
2017-12-20 12:50:10 -08:00
|
|
|
flag_debug: bool,
|
2018-03-01 19:19:12 -08:00
|
|
|
flag_version: bool,
|
2018-04-11 11:43:18 -07:00
|
|
|
flag_no_demangle: bool,
|
2018-04-19 13:33:58 -07:00
|
|
|
flag_no_modules_global: Option<String>,
|
2018-07-13 08:10:51 -07:00
|
|
|
flag_keep_debug: bool,
|
2018-03-01 19:19:12 -08:00
|
|
|
arg_input: Option<PathBuf>,
|
2017-12-14 19:31:01 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let args: Args = Docopt::new(USAGE)
|
|
|
|
.and_then(|d| d.deserialize())
|
|
|
|
.unwrap_or_else(|e| e.exit());
|
|
|
|
|
2018-03-01 19:19:12 -08:00
|
|
|
if args.flag_version {
|
|
|
|
println!("wasm-bindgen {}", wasm_bindgen_shared::version());
|
2018-04-04 20:06:53 +05:45
|
|
|
return;
|
2018-03-01 19:19:12 -08:00
|
|
|
}
|
2018-04-25 11:42:22 -07:00
|
|
|
let err = match rmain(&args) {
|
|
|
|
Ok(()) => return,
|
|
|
|
Err(e) => e,
|
|
|
|
};
|
2018-04-30 13:24:29 -07:00
|
|
|
eprintln!("error: {}", err);
|
2018-08-01 16:15:09 -05:00
|
|
|
for cause in err.iter_causes() {
|
2018-04-30 13:24:29 -07:00
|
|
|
eprintln!("\tcaused by: {}", cause);
|
2018-04-25 11:42:22 -07:00
|
|
|
}
|
|
|
|
process::exit(1);
|
|
|
|
}
|
2018-03-01 19:19:12 -08:00
|
|
|
|
2018-04-25 11:42:22 -07:00
|
|
|
fn rmain(args: &Args) -> Result<(), Error> {
|
2018-03-01 19:19:12 -08:00
|
|
|
let input = match args.arg_input {
|
2018-04-25 11:42:22 -07:00
|
|
|
Some(ref s) => s,
|
|
|
|
None => bail!("input file expected"),
|
2018-03-01 19:19:12 -08:00
|
|
|
};
|
|
|
|
|
2018-04-27 07:14:46 -07:00
|
|
|
let typescript = args.flag_typescript || !args.flag_no_typescript;
|
|
|
|
|
2017-12-14 19:31:01 -08:00
|
|
|
let mut b = Bindgen::new();
|
2018-04-25 11:42:22 -07:00
|
|
|
b.input_path(input)
|
2018-04-04 20:06:53 +05:45
|
|
|
.nodejs(args.flag_nodejs)
|
|
|
|
.browser(args.flag_browser)
|
2018-04-11 13:59:58 +05:45
|
|
|
.no_modules(args.flag_no_modules)
|
2018-04-04 20:06:53 +05:45
|
|
|
.debug(args.flag_debug)
|
2018-04-13 07:34:27 -07:00
|
|
|
.demangle(!args.flag_no_demangle)
|
2018-07-13 08:10:51 -07:00
|
|
|
.keep_debug(args.flag_keep_debug)
|
2018-04-27 07:14:46 -07:00
|
|
|
.typescript(typescript);
|
2018-04-19 14:28:30 -07:00
|
|
|
if let Some(ref name) = args.flag_no_modules_global {
|
2018-04-19 13:33:58 -07:00
|
|
|
b.no_modules_global(name);
|
|
|
|
}
|
2018-01-29 21:20:38 -08:00
|
|
|
|
|
|
|
let out_dir = match args.flag_out_dir {
|
|
|
|
Some(ref p) => p,
|
2018-04-25 11:42:22 -07:00
|
|
|
None => bail!("the `--out-dir` argument is now required"),
|
2018-01-29 21:20:38 -08:00
|
|
|
};
|
|
|
|
|
2018-04-25 11:42:22 -07:00
|
|
|
b.generate(out_dir)
|
2017-12-14 19:31:01 -08:00
|
|
|
}
|