mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-16 03:20:50 +00:00
add steps to build util
This commit is contained in:
parent
71910405bc
commit
665b21e74f
@ -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<io::Error> 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();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user