From 665b21e74f76b8e9494830dd34d0dc829dc95c15 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 9 Aug 2017 14:30:37 +0300 Subject: [PATCH] add steps to build util --- build/src/main.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/build/src/main.rs b/build/src/main.rs index baf1729..083266f 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -3,6 +3,7 @@ extern crate glob; extern crate wasm_utils; extern crate clap; +extern crate parity_wasm; use std::{fs, io}; use std::path::PathBuf; @@ -23,6 +24,12 @@ impl From for Error { } } +pub fn wasm_path(target_dir: &str, bin_name: &str) -> String { + let mut path = PathBuf::from(target_dir); + path.push(format!("{}.wasm", bin_name)); + path.to_string_lossy().to_string() +} + pub fn process_output(target_dir: &str, bin_name: &str) -> Result<(), Error> { let mut path = PathBuf::from(target_dir); let wasm_name = bin_name.to_string().replace("-", "_"); @@ -69,4 +76,15 @@ fn main() { let wasm_binary = matches.value_of("wasm").expect("is required; qed"); process_output(target_dir, wasm_binary).expect("Failed to process cargo target directory"); + + let path = wasm_path(target_dir, wasm_binary); + + let mut module = wasm_utils::externalize( + parity_wasm::deserialize_file(&path).unwrap(), + vec!["_free", "_malloc"], + ); + + wasm_utils::optimize(&mut module, vec!["_call"]).expect("Optimizer to finish without errors"); + + parity_wasm::serialize_to_file(&path, module).unwrap(); } \ No newline at end of file