From 203cc4fea8427ad2457f95e6fd99645fe0d893ec Mon Sep 17 00:00:00 2001 From: NikVolf Date: Fri, 15 Sep 2017 22:00:35 +0300 Subject: [PATCH 1/3] rename wasm-opt binary to wasm-prune --- Cargo.toml | 4 ++-- opt/.gitignore | 2 -- opt/Cargo.toml | 9 --------- opt/src/main.rs | 44 -------------------------------------------- 4 files changed, 2 insertions(+), 57 deletions(-) delete mode 100644 opt/.gitignore delete mode 100644 opt/Cargo.toml delete mode 100644 opt/src/main.rs diff --git a/Cargo.toml b/Cargo.toml index 2b37e54..b4944ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,8 +14,8 @@ glob = "0.2" [lib] [[bin]] -name = "wasm-opt" -path = "opt/src/main.rs" +name = "wasm-prune" +path = "prune/src/main.rs" [[bin]] name = "wasm-ext" diff --git a/opt/.gitignore b/opt/.gitignore deleted file mode 100644 index f2f9e58..0000000 --- a/opt/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -target -Cargo.lock \ No newline at end of file diff --git a/opt/Cargo.toml b/opt/Cargo.toml deleted file mode 100644 index 5270544..0000000 --- a/opt/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "wasm-opt" -version = "0.1.0" -authors = ["NikVolf "] - -[dependencies] -parity-wasm = "0.12" -wasm-utils = { path = "../" } -clap = "2.24" diff --git a/opt/src/main.rs b/opt/src/main.rs deleted file mode 100644 index 6175ad9..0000000 --- a/opt/src/main.rs +++ /dev/null @@ -1,44 +0,0 @@ -extern crate parity_wasm; -extern crate wasm_utils; -extern crate clap; - -use clap::{App, Arg}; - -fn main() { - wasm_utils::init_log(); - - let matches = App::new("wasm-opt") - .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")) - .arg(Arg::with_name("exports") - .long("exports") - .short("e") - .takes_value(true) - .value_name("functions") - .help("Comma-separated list of exported functions to keep. Default: _call")) - .get_matches(); - - let exports = matches - .value_of("exports") - .unwrap_or("_call") - .split(',') - .collect(); - - let input = matches.value_of("input").expect("is required; qed"); - let output = matches.value_of("output").expect("is required; qed"); - - let mut module = parity_wasm::deserialize_file(&input).unwrap(); - - // Invoke optimizer - // Contract is supposed to have only these functions as public api - // All other symbols not usable by this list is optimized away - wasm_utils::optimize(&mut module, exports).expect("Optimizer to finish without errors"); - - parity_wasm::serialize_to_file(&output, module).unwrap(); -} From 5095880843b70220036b88772622224a66117d38 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Fri, 15 Sep 2017 22:01:12 +0300 Subject: [PATCH 2/3] add prune actually --- prune/.gitignore | 2 ++ prune/Cargo.toml | 9 +++++++++ prune/src/main.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) create mode 100644 prune/.gitignore create mode 100644 prune/Cargo.toml create mode 100644 prune/src/main.rs diff --git a/prune/.gitignore b/prune/.gitignore new file mode 100644 index 0000000..f2f9e58 --- /dev/null +++ b/prune/.gitignore @@ -0,0 +1,2 @@ +target +Cargo.lock \ No newline at end of file diff --git a/prune/Cargo.toml b/prune/Cargo.toml new file mode 100644 index 0000000..5270544 --- /dev/null +++ b/prune/Cargo.toml @@ -0,0 +1,9 @@ +[package] +name = "wasm-opt" +version = "0.1.0" +authors = ["NikVolf "] + +[dependencies] +parity-wasm = "0.12" +wasm-utils = { path = "../" } +clap = "2.24" diff --git a/prune/src/main.rs b/prune/src/main.rs new file mode 100644 index 0000000..6175ad9 --- /dev/null +++ b/prune/src/main.rs @@ -0,0 +1,44 @@ +extern crate parity_wasm; +extern crate wasm_utils; +extern crate clap; + +use clap::{App, Arg}; + +fn main() { + wasm_utils::init_log(); + + let matches = App::new("wasm-opt") + .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")) + .arg(Arg::with_name("exports") + .long("exports") + .short("e") + .takes_value(true) + .value_name("functions") + .help("Comma-separated list of exported functions to keep. Default: _call")) + .get_matches(); + + let exports = matches + .value_of("exports") + .unwrap_or("_call") + .split(',') + .collect(); + + let input = matches.value_of("input").expect("is required; qed"); + let output = matches.value_of("output").expect("is required; qed"); + + let mut module = parity_wasm::deserialize_file(&input).unwrap(); + + // Invoke optimizer + // Contract is supposed to have only these functions as public api + // All other symbols not usable by this list is optimized away + wasm_utils::optimize(&mut module, exports).expect("Optimizer to finish without errors"); + + parity_wasm::serialize_to_file(&output, module).unwrap(); +} From 087399f6b59c9db4a7d1900f5ec85b8e9a2af473 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Fri, 15 Sep 2017 22:03:43 +0300 Subject: [PATCH 3/3] update also readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 636d48a..5d6c575 100644 --- a/README.md +++ b/README.md @@ -10,10 +10,10 @@ Easiest way to use is to install via `cargo install`: cargo install --git https://github.com/paritytech/wasm-utils wasm-build ``` -## Symbols optimizer (wasm-opt) +## Symbols pruning (wasm-prune) ``` -cargo run --release --bin wasm-opt -- +cargo run --release --bin wasm-prune -- ``` This will optimize WASM symbols tree to leave only those elements that are used by contract `_call` function entry.