mirror of
https://github.com/pezkuwichain/wasm-instrument.git
synced 2026-07-20 09:35:43 +00:00
Merge pull request #82 from paritytech/pack-cli
Standalone wasm-pack binary
This commit is contained in:
@@ -29,6 +29,10 @@ path = "build/main.rs"
|
|||||||
name = "wasm-stack-height"
|
name = "wasm-stack-height"
|
||||||
path = "stack_height/main.rs"
|
path = "stack_height/main.rs"
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "wasm-pack"
|
||||||
|
path = "pack/main.rs"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
parity-wasm = "0.30"
|
parity-wasm = "0.30"
|
||||||
pwasm-utils = { path = "..", version = "0.2" }
|
pwasm-utils = { path = "..", version = "0.2" }
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
extern crate parity_wasm;
|
||||||
|
extern crate pwasm_utils as utils;
|
||||||
|
extern crate pwasm_utils_cli as logger;
|
||||||
|
extern crate clap;
|
||||||
|
|
||||||
|
use clap::{App, Arg};
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
logger::init_log();
|
||||||
|
|
||||||
|
let matches = App::new("wasm-pack")
|
||||||
|
.arg(Arg::with_name("input")
|
||||||
|
.index(1)
|
||||||
|
.required(true)
|
||||||
|
.help("Input WASM file"))
|
||||||
|
.arg(Arg::with_name("output")
|
||||||
|
.index(2)
|
||||||
|
.required(true)
|
||||||
|
.help("Output WASM file"))
|
||||||
|
.get_matches();
|
||||||
|
|
||||||
|
let input = matches.value_of("input").expect("is required; qed");
|
||||||
|
let output = matches.value_of("output").expect("is required; qed");
|
||||||
|
|
||||||
|
let module = parity_wasm::deserialize_file(&input).expect("Input module deserialization failed");
|
||||||
|
let ctor_module = module.clone();
|
||||||
|
let raw_module = parity_wasm::serialize(module).expect("Serialization failed");
|
||||||
|
|
||||||
|
// Invoke packer
|
||||||
|
let mut result_module = utils::pack_instance(raw_module, ctor_module).expect("Packing failed");
|
||||||
|
// Optimize constructor, since it does not need everything
|
||||||
|
utils::optimize(&mut result_module, vec![utils::CALL_SYMBOL]).expect("Optimization failed");
|
||||||
|
|
||||||
|
parity_wasm::serialize_to_file(&output, result_module).expect("Serialization failed");
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user