Skip to content

Commit

Permalink
Merge pull request rustwasm#1084 from David-OConnor/master
Browse files Browse the repository at this point in the history
Added an --out-name param to the CLI, to allow custom output file names
  • Loading branch information
alexcrichton authored Dec 5, 2018
2 parents 5665a0e + a4bc504 commit 7768328
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
12 changes: 11 additions & 1 deletion crates/cli-support/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ mod wasm_utils;

pub struct Bindgen {
input: Input,
out_name: Option<String>,
nodejs: bool,
nodejs_experimental_modules: bool,
browser: bool,
Expand Down Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -155,7 +162,10 @@ impl Bindgen {
.with_context(|_| format!("failed to read `{}`", path.display()))?;
let module = parity_wasm::deserialize_buffer::<Module>(&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)
}
};
Expand Down
5 changes: 5 additions & 0 deletions crates/cli/src/bin/wasm-bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -50,6 +51,7 @@ struct Args {
flag_typescript: bool,
flag_no_typescript: bool,
flag_out_dir: Option<PathBuf>,
flag_out_name: Option<String>,
flag_debug: bool,
flag_version: bool,
flag_no_demangle: bool,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 7768328

Please sign in to comment.