Add an option to detect node at runtime

Sometimes builds are done once and used in both the browser and in node, so add
an option to do runtime detection if necessary
This commit is contained in:
Alex Crichton
2018-03-07 08:50:56 -08:00
parent 48c0f290f9
commit 8254d9f516
5 changed files with 59 additions and 14 deletions

View File

@ -18,17 +18,19 @@ Usage:
wasm-bindgen -V | --version
Options:
-h --help Show this screen.
--out-dir DIR Output directory
--nodejs Generate output for node.js, not the browser
--typescript Output a TypeScript definition file
--debug Include otherwise-extraneous debug checks in output
-V --version Print the version number of wasm-bindgen
-h --help Show this screen.
--out-dir DIR Output directory
--nodejs Generate output for node.js, not the browser
--nodejs-runtime-detect Detect at runtime whether we're in node or a browser
--typescript Output a TypeScript definition file
--debug Include otherwise-extraneous debug checks in output
-V --version Print the version number of wasm-bindgen
";
#[derive(Debug, Deserialize)]
struct Args {
flag_nodejs: bool,
flag_nodejs_runtime_detect: bool,
flag_typescript: bool,
flag_out_dir: Option<PathBuf>,
flag_debug: bool,
@ -54,6 +56,7 @@ fn main() {
let mut b = Bindgen::new();
b.input_path(&input)
.nodejs(args.flag_nodejs)
.nodejs_runtime_detect(args.flag_nodejs_runtime_detect)
.debug(args.flag_debug)
.typescript(args.flag_typescript);