Add a --debug option to suppress --release.

master
Christopher Lane Hinson 7 years ago
parent 1d946d6a19
commit fb4c8e2731
  1. 8
      src/bindgen.rs
  2. 18
      src/build.rs
  3. 17
      src/command.rs

@ -34,6 +34,7 @@ pub fn wasm_bindgen_build(
name: &str, name: &str,
disable_dts: bool, disable_dts: bool,
target: String, target: String,
debug: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
let step = format!( let step = format!(
"{} {}Running WASM-bindgen...", "{} {}Running WASM-bindgen...",
@ -42,8 +43,11 @@ pub fn wasm_bindgen_build(
); );
let pb = PBAR.message(&step); let pb = PBAR.message(&step);
let binary_name = name.replace("-", "_"); 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 { let dts_arg = if disable_dts == false {
"--typescript" "--typescript"
} else { } else {

@ -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!( let step = format!(
"{} {}Compiling to WASM...", "{} {}Compiling to WASM...",
style("[2/7]").bold().dim(), style("[2/7]").bold().dim(),
emoji::CYCLONE emoji::CYCLONE
); );
let pb = PBAR.message(&step); let pb = PBAR.message(&step);
let output = Command::new("cargo") let output = {
.current_dir(path) let mut cmd = Command::new("cargo");
.arg("build") cmd.current_dir(path).arg("build");
.arg("--release") if !debug {
.arg("--target") cmd.arg("--release");
.arg("wasm32-unknown-unknown") }
.output()?; cmd.arg("--target").arg("wasm32-unknown-unknown");
cmd.output()?
};
pb.finish(); pb.finish();
if !output.status.success() { if !output.status.success() {
let s = String::from_utf8_lossy(&output.stderr); let s = String::from_utf8_lossy(&output.stderr);

@ -32,6 +32,10 @@ pub enum Command {
#[structopt(long = "target", short = "t", default_value = "browser")] #[structopt(long = "target", short = "t", default_value = "browser")]
/// Sets the target environment. [possible values: browser, nodejs] /// Sets the target environment. [possible values: browser, nodejs]
target: String, target: String,
#[structopt(long = "debug")]
/// Build without --release.
debug: bool,
}, },
#[structopt(name = "pack")] #[structopt(name = "pack")]
@ -84,17 +88,19 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error
scope, scope,
disable_dts, disable_dts,
target, target,
debug,
} => { } => {
info!(&log, "Running init command..."); info!(&log, "Running init command...");
info!( info!(
&log, &log,
"Path: {:?}, Scope: {:?}, Disable Dts: {}, Target: {}", "Path: {:?}, Scope: {:?}, Disable Dts: {}, Target: {}, Debug: {}",
&path, &path,
&scope, &scope,
&disable_dts, &disable_dts,
&target &target,
debug
); );
init(path, scope, disable_dts, target, &log) init(path, scope, disable_dts, target, &log, debug)
} }
Command::Pack { path } => { Command::Pack { path } => {
info!(&log, "Running pack command..."); info!(&log, "Running pack command...");
@ -164,6 +170,7 @@ fn init(
disable_dts: bool, disable_dts: bool,
target: String, target: String,
log: &Logger, log: &Logger,
debug: bool,
) -> result::Result<(), Error> { ) -> result::Result<(), Error> {
let started = Instant::now(); let started = Instant::now();
@ -174,7 +181,7 @@ fn init(
info!(&log, "Adding wasm-target was successful."); info!(&log, "Adding wasm-target was successful.");
info!(&log, "Building wasm..."); info!(&log, "Building wasm...");
build::cargo_build_wasm(&crate_path)?; build::cargo_build_wasm(&crate_path, debug)?;
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
info!( info!(
@ -229,7 +236,7 @@ fn init(
); );
info!(&log, "Building the wasm bindings..."); info!(&log, "Building the wasm bindings...");
bindgen::wasm_bindgen_build(&crate_path, &name, disable_dts, target)?; bindgen::wasm_bindgen_build(&crate_path, &name, disable_dts, target, debug)?;
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
info!(&log, "wasm bindings were built at {}/pkg.", &crate_path); info!(&log, "wasm bindings were built at {}/pkg.", &crate_path);
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]

Loading…
Cancel
Save