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 Oct 25, 2018
1 parent 75d44c7 commit 2f266f9
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
16 changes: 16 additions & 0 deletions src/command/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -311,4 +311,20 @@ impl Build {
info!(&log, "wasm bindings were built at {:#?}.", &self.out_dir);
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(())
}
}
14 changes: 10 additions & 4 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,17 @@
pub mod build;
mod login;
mod pack;
<<<<<<< HEAD
/// Data structures and functions for publishing a package.
pub mod publish;
pub mod test;
mod snip;
||||||| merged common ancestors
mod publish;
mod snip;
=======
mod publish;
>>>>>>> build(snip): hidde snip into build
pub mod utils;

use self::build::{Build, BuildOptions};
Expand Down Expand Up @@ -84,6 +91,9 @@ pub enum Command {
/// 👩‍🔬 test your wasm!
Test(TestOptions),

#[structopt(name = "snip")]
/// Replace a wasm function with an `unreachable`.
#[structopt(name = "snip")]
/// Replace a wasm function with an `unreachable`.
Snip(SnipOptions),
Expand Down Expand Up @@ -125,18 +135,14 @@ pub fn run_wasm_pack(command: Command, log: &Logger) -> result::Result<(), failu
);
login(registry, scope, always_auth, auth_type, &log)
}
<<<<<<< HEAD
Command::Test(test_opts) => {
info!(&log, "Running test command...");
Test::try_from_opts(test_opts).and_then(|t| t.run(&log))
}
||||||| merged common ancestors
=======
Command::Snip(opts) => {
info!(&log, "Running snip command...");
snip(opts)
}
>>>>>>> cmd(snip): rebase
};

match status {
Expand Down
5 changes: 5 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,13 @@ pub mod manifest;
pub mod npm;
pub mod progressbar;
pub mod readme;
<<<<<<< HEAD
pub mod target;
pub mod test;
||||||| merged common ancestors
=======
pub mod snip;
>>>>>>> build(snip): hidde snip into build

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 2f266f9

Please sign in to comment.