From 7b432eff8432b2440f24fd822b2051765b6cc394 Mon Sep 17 00:00:00 2001 From: Christopher Lane Hinson Date: Fri, 25 May 2018 14:59:41 +0000 Subject: [PATCH] Add a --debug option to suppress --release. --- src/bindgen.rs | 13 +++++++++++-- src/build.rs | 18 ++++++++++-------- src/command.rs | 11 ++++++++--- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/bindgen.rs b/src/bindgen.rs index fa2d5a4b8..43f58ebe8 100644 --- a/src/bindgen.rs +++ b/src/bindgen.rs @@ -28,7 +28,12 @@ pub fn cargo_install_wasm_bindgen() -> Result<(), Error> { } } -pub fn wasm_bindgen_build(path: &str, name: &str, disable_dts: bool) -> Result<(), Error> { +pub fn wasm_bindgen_build( + path: &str, + name: &str, + disable_dts: bool, + debug: bool, +) -> Result<(), Error> { let step = format!( "{} {}Running WASM-bindgen...", style("[7/7]").bold().dim(), @@ -36,7 +41,11 @@ pub fn wasm_bindgen_build(path: &str, name: &str, disable_dts: bool) -> Result<( ); let pb = PBAR.message(&step); let binary_name = name.replace("-", "_"); - let wasm_path = format!("target/wasm32-unknown-unknown/release/{}.wasm", binary_name); + let release_or_debug = if debug { "debug" } else { "release" }; + let wasm_path = format!( + "target/wasm32-unknown-unknown/{}/{}.wasm", + release_or_debug, binary_name + ); let dts_arg = if disable_dts == false { "--typescript" } else { diff --git a/src/build.rs b/src/build.rs index 9793e9014..d5cdb31df 100644 --- a/src/build.rs +++ b/src/build.rs @@ -25,20 +25,22 @@ pub fn rustup_add_wasm_target() -> Result<(), Error> { } } -pub fn cargo_build_wasm(path: &str) -> Result<(), Error> { +pub fn cargo_build_wasm(path: &str, debug: bool) -> Result<(), Error> { let step = format!( "{} {}Compiling to WASM...", style("[2/7]").bold().dim(), emoji::CYCLONE ); let pb = PBAR.message(&step); - let output = Command::new("cargo") - .current_dir(path) - .arg("build") - .arg("--release") - .arg("--target") - .arg("wasm32-unknown-unknown") - .output()?; + let output = { + let mut cmd = Command::new("cargo"); + cmd.current_dir(path).arg("build"); + if !debug { + cmd.arg("--release"); + } + cmd.arg("--target").arg("wasm32-unknown-unknown"); + cmd.output()? + }; pb.finish(); if !output.status.success() { let s = String::from_utf8_lossy(&output.stderr); diff --git a/src/command.rs b/src/command.rs index e96585d3c..96f34e860 100644 --- a/src/command.rs +++ b/src/command.rs @@ -24,6 +24,9 @@ pub enum Command { scope: Option, #[structopt(long = "no-typescript")] disable_dts: bool, + #[structopt(long = "debug")] + /// Build without --release. + debug: bool, }, #[structopt(name = "pack")] @@ -67,7 +70,8 @@ pub fn run_wasm_pack(command: Command) -> result::Result<(), Error> { path, scope, disable_dts, - } => init(path, scope, disable_dts), + debug, + } => init(path, scope, disable_dts, debug), Command::Pack { path } => pack(path), Command::Publish { path } => publish(path), Command::Login { @@ -114,19 +118,20 @@ fn init( path: Option, scope: Option, disable_dts: bool, + debug: bool, ) -> result::Result<(), Error> { let started = Instant::now(); let crate_path = set_crate_path(path); build::rustup_add_wasm_target()?; - build::cargo_build_wasm(&crate_path)?; + build::cargo_build_wasm(&crate_path, debug)?; create_pkg_dir(&crate_path)?; manifest::write_package_json(&crate_path, scope, disable_dts)?; readme::copy_from_crate(&crate_path)?; bindgen::cargo_install_wasm_bindgen()?; let name = manifest::get_crate_name(&crate_path)?; - bindgen::wasm_bindgen_build(&crate_path, &name, disable_dts)?; + bindgen::wasm_bindgen_build(&crate_path, &name, disable_dts, debug)?; PBAR.message(&format!( "{} Done in {}", emoji::SPARKLE,