Skip to content

Commit

Permalink
build(snip): hidde snip into build
Browse files Browse the repository at this point in the history
  • Loading branch information
csmoe committed Aug 2, 2018
1 parent a0ce253 commit a57d0a0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
16 changes: 16 additions & 0 deletions src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,4 +245,20 @@ impl Build {
);
Ok(())
}

fn set_run_wasm_snip(&mut self, step: &Step, log: &Logger) -> Result<(), Error> {
let msg = format!("{}Running WASM-opt...", emoji::RUNNER);
PBAR.step(step, &msg);

snip::set_run_wasm_snip(
// FIXME(csmoe) add wasm_snip_config() in build
self.wasm_snip_config(),
)?;
info!(
&log,
"wasm bindings were snipped at {:#?}.",
&self.crate_path.join("pkg")
);
Ok(())
}
}
9 changes: 0 additions & 9 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ mod build;
mod login;
mod pack;
mod publish;
mod snip;
pub mod utils;

use self::build::{Build, BuildMode, BuildOptions};
Expand Down Expand Up @@ -72,10 +71,6 @@ pub enum Command {
/// strategies besides classic username/password entry in legacy npm.
auth_type: Option<String>,
},

#[structopt(name = "snip")]
/// Replace a wasm function with an `unreachable`.
Snip(SnipOptions),
}

/// Run a command with the given logger!
Expand Down Expand Up @@ -119,10 +114,6 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), Error
);
login(registry, scope, always_auth, auth_type, &log)
}
Command::Snip(opts) => {
info!(&log, "Running snip command...");
snip(opts)
}
};

match status {
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub mod manifest;
pub mod npm;
pub mod progressbar;
pub mod readme;
pub mod snip;

use progressbar::ProgressOutput;

Expand Down
6 changes: 3 additions & 3 deletions src/command/snip.rs → src/snip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use parity_wasm::elements::{self, Serialize};
use wasm_snip;

#[derive(Clone, Debug, StructOpt)]
pub struct SnipOptions {
pub struct WasmSnipConfig {
input: String,
#[structopt(long = "output", short = "o")]
pub(crate) output: Option<String>,
Expand All @@ -16,7 +16,7 @@ pub struct SnipOptions {
snip_rust_panicking_code: bool,
}

impl Into<wasm_snip::Options> for SnipOptions {
impl Into<wasm_snip::Options> for WasmSnipConfig {
fn into(self) -> wasm_snip::Options {
wasm_snip::Options {
input: ::std::path::PathBuf::from(self.input),
Expand All @@ -28,7 +28,7 @@ impl Into<wasm_snip::Options> for SnipOptions {
}
}

pub(crate) fn snip(opts: SnipOptions) -> Result<(), Error> {
pub(crate) fn run_wasm_snip(opts: WasmSnipConfig) -> Result<(), Error> {
let module = wasm_snip::snip(opts.clone().into())?;

if let Some(output) = opts.output {
Expand Down

0 comments on commit a57d0a0

Please sign in to comment.