diff --git a/crates/cli-support/src/lib.rs b/crates/cli-support/src/lib.rs index 0ae49289c0e..41145965cda 100644 --- a/crates/cli-support/src/lib.rs +++ b/crates/cli-support/src/lib.rs @@ -27,6 +27,7 @@ mod wasm_utils; pub struct Bindgen { input: Input, + out_name: Option, nodejs: bool, nodejs_experimental_modules: bool, browser: bool, @@ -56,6 +57,7 @@ impl Bindgen { pub fn new() -> Bindgen { Bindgen { input: Input::None, + out_name: None, nodejs: false, nodejs_experimental_modules: false, browser: false, @@ -77,6 +79,11 @@ impl Bindgen { self } + pub fn out_name(&mut self, name: &str) -> &mut Bindgen { + self.out_name = Some(name.to_string()); + self + } + /// Explicitly specify the already parsed input module. pub fn input_module(&mut self, name: &str, module: Module) -> &mut Bindgen { let name = name.to_string(); @@ -155,7 +162,10 @@ impl Bindgen { .with_context(|_| format!("failed to read `{}`", path.display()))?; let module = parity_wasm::deserialize_buffer::(&contents) .context("failed to parse input file as wasm")?; - let stem = path.file_stem().unwrap().to_str().unwrap(); + let stem = match &self.out_name { + Some(name) => &name, + None => path.file_stem().unwrap().to_str().unwrap(), + }; (module, stem) } }; diff --git a/crates/cli/src/bin/wasm-bindgen.rs b/crates/cli/src/bin/wasm-bindgen.rs index 2b0e240e4c2..70401212c6d 100644 --- a/crates/cli/src/bin/wasm-bindgen.rs +++ b/crates/cli/src/bin/wasm-bindgen.rs @@ -29,6 +29,7 @@ Usage: Options: -h --help Show this screen. --out-dir DIR Output directory + --out-name VAR Set a custom output filename (Without extension. Defaults to crate name) --nodejs Generate output that only works in node.js --browser Generate output that only works in a browser --no-modules Generate output that only works in a browser (without modules) @@ -50,6 +51,7 @@ struct Args { flag_typescript: bool, flag_no_typescript: bool, flag_out_dir: Option, + flag_out_name: Option, flag_debug: bool, flag_version: bool, flag_no_demangle: bool, @@ -101,6 +103,9 @@ fn rmain(args: &Args) -> Result<(), Error> { if let Some(ref name) = args.flag_no_modules_global { b.no_modules_global(name); } + if let Some(ref name) = args.flag_out_name { + b.out_name(name); + } let out_dir = match args.flag_out_dir { Some(ref p) => p,