From 046453c7f1c22b5b132db40c68ae43ae36bd4adc Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 26 Dec 2017 13:38:07 +0300 Subject: [PATCH 01/12] refactor to well-defined source input --- build/src/main.rs | 29 ++++++++++++++++++----------- build/src/source.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 build/src/source.rs diff --git a/build/src/main.rs b/build/src/main.rs index 0c6c406..f57dd50 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -5,6 +5,8 @@ extern crate wasm_utils; extern crate clap; extern crate parity_wasm; +mod source; + use std::{fs, io}; use std::io::Write; use std::path::PathBuf; @@ -28,21 +30,21 @@ 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)); +pub fn wasm_path(input: &source::SourceInput) -> String { + let mut path = PathBuf::from(input.target_dir()); + path.push(format!("{}.wasm", input.bin_name())); path.to_string_lossy().to_string() } -pub fn process_output(target_dir: &str, bin_name: &str) -> Result<(), Error> { - let mut cargo_path = PathBuf::from(target_dir); - let wasm_name = bin_name.to_string().replace("-", "_"); +pub fn process_output(input: &source::SourceInput) -> Result<(), Error> { + let mut cargo_path = PathBuf::from(input.target_dir()); + let wasm_name = input.bin_name().to_string().replace("-", "_"); cargo_path.push("wasm32-unknown-emscripten"); cargo_path.push("release"); cargo_path.push(format!("{}.wasm", wasm_name)); - let mut target_path = PathBuf::from(target_dir); - target_path.push(format!("{}.wasm", bin_name)); + let mut target_path = PathBuf::from(input.target_dir()); + target_path.push(format!("{}.wasm", input.bin_name())); fs::copy(cargo_path, target_path)?; Ok(()) @@ -83,10 +85,11 @@ fn main() { let target_dir = matches.value_of("target").expect("is required; qed"); let wasm_binary = matches.value_of("wasm").expect("is required; qed"); + let source_input = source::SourceInput::new(target_dir, wasm_binary); - process_output(target_dir, wasm_binary).expect("Failed to process cargo target directory"); + process_output(&source_input).expect("Failed to process cargo target directory"); - let path = wasm_path(target_dir, wasm_binary); + let path = wasm_path(&source_input); let mut module = parity_wasm::deserialize_file(&path).unwrap(); @@ -132,6 +135,7 @@ mod tests { use std::fs; use super::process_output; + use super::source::SourceInput; #[test] fn processes_cargo_output() { @@ -148,7 +152,10 @@ mod tests { f.write(b"\0asm").expect("write file failed"); } - process_output(&tmp_dir.path().to_string_lossy(), "example-wasm").expect("process output failed"); + let path = tmp_dir.path().to_string_lossy(); + let input = SourceInput::new(&path, "example-wasm"); + + process_output(&input).expect("process output failed"); assert!( fs::metadata(tmp_dir.path().join("example-wasm.wasm")).expect("metadata failed").is_file() diff --git a/build/src/source.rs b/build/src/source.rs new file mode 100644 index 0000000..f933aac --- /dev/null +++ b/build/src/source.rs @@ -0,0 +1,44 @@ +//! Configuration of source binaries + +/// Target configiration of previous build step +#[derive(Debug)] +pub enum SourceTarget { + Emscripten, + Unknown, +} + +/// Configuration of previous build step (cargo compilation) +#[derive(Debug)] +pub struct SourceInput<'a> { + target_dir: &'a str, + bin_name: &'a str, + target: SourceTarget, +} + +impl<'a> SourceInput<'a> { + pub fn new<'b>(target_dir: &'b str, bin_name: &'b str) -> SourceInput<'b> { + SourceInput { + target_dir: target_dir, + bin_name: bin_name, + target: SourceTarget::Emscripten, + } + } + + pub fn unknown(mut self) -> Self { + self.target = SourceTarget::Unknown; + self + } + + pub fn emscripten(mut self) -> Self { + self.target = SourceTarget::Emscripten; + self + } + + pub fn target_dir(&self) -> &str { + &self.target_dir + } + + pub fn bin_name(&self) -> &str { + &self.bin_name + } +} \ No newline at end of file From 2fd7d50586fec54c4253d582f94fd05d77a2c802 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 26 Dec 2017 13:38:33 +0300 Subject: [PATCH 02/12] remove redundant line --- build/src/main.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/build/src/main.rs b/build/src/main.rs index f57dd50..7d6b2e0 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -161,5 +161,4 @@ mod tests { fs::metadata(tmp_dir.path().join("example-wasm.wasm")).expect("metadata failed").is_file() ) } - } From fceb0ce7f1af010d63439f5c1c71f2553c7446cf Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 26 Dec 2017 14:03:08 +0300 Subject: [PATCH 03/12] argument parsing, mem ext stub --- build/src/main.rs | 16 +++++++++++++++- src/ext.rs | 22 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/build/src/main.rs b/build/src/main.rs index 7d6b2e0..6401f97 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -81,11 +81,25 @@ fn main() { .help("Injects RUNTIME_VERSION global export") .takes_value(true) .long("runtime-version")) + .arg(Arg::with_name("source_target") + .help("Skip symbol optimization step producing final wasm") + .takes_value(true) + .long("target")) .get_matches(); let target_dir = matches.value_of("target").expect("is required; qed"); let wasm_binary = matches.value_of("wasm").expect("is required; qed"); - let source_input = source::SourceInput::new(target_dir, wasm_binary); + let mut source_input = source::SourceInput::new(target_dir, wasm_binary); + + let source_target_val = matches.value_of("source_target").unwrap_or_else(|| "wasm32-unknown-emscripten"); + if source_target_val == "wasm32-unknown-unknown" { + source_input = source_input.unknown() + } else if source_target_val == "wasm32-unknown-emscripten" { + source_input = source_input.emscripten() + } else { + println!("--target can be: 'wasm32-unknown-emscripten' or 'wasm32-unknown-unknown'"); + ::std::process::exit(1); + } process_output(&source_input).expect("Failed to process cargo target directory"); diff --git a/src/ext.rs b/src/ext.rs index c38aebf..bba1777 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -18,6 +18,28 @@ pub fn update_call_index(opcodes: &mut elements::Opcodes, original_imports: usiz } } +pub fn memory_section<'a>(module: &'a mut elements::Module) -> Option<&'a mut elements::MemorySection> { + for section in module.sections_mut() { + match section { + &mut elements::Section::Memory(ref mut sect) => { + return Some(sect); + }, + _ => { } + } + } + None +} + +pub fn externalize_mem(mut module: elements::Module) -> elements::Module { + let entry = memory_section(&mut module) + .expect("Memory section to exist") + .entries_mut() + .pop() + .expect("Own memory entry to exist in memory section"); + + module +} + pub fn externalize( module: elements::Module, replaced_funcs: Vec<&str>, From 759021616156cf4c0e5a21c3df27c54754063ec0 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 26 Dec 2017 15:58:04 +0300 Subject: [PATCH 04/12] arrange consts --- build/src/main.rs | 11 +++++------ build/src/source.rs | 3 +++ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/build/src/main.rs b/build/src/main.rs index 6401f97..eaf1b5d 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -39,7 +39,7 @@ pub fn wasm_path(input: &source::SourceInput) -> String { pub fn process_output(input: &source::SourceInput) -> Result<(), Error> { let mut cargo_path = PathBuf::from(input.target_dir()); let wasm_name = input.bin_name().to_string().replace("-", "_"); - cargo_path.push("wasm32-unknown-emscripten"); + cargo_path.push(source::EMSCRIPTEN_PATH); cargo_path.push("release"); cargo_path.push(format!("{}.wasm", wasm_name)); @@ -91,13 +91,13 @@ fn main() { let wasm_binary = matches.value_of("wasm").expect("is required; qed"); let mut source_input = source::SourceInput::new(target_dir, wasm_binary); - let source_target_val = matches.value_of("source_target").unwrap_or_else(|| "wasm32-unknown-emscripten"); - if source_target_val == "wasm32-unknown-unknown" { + let source_target_val = matches.value_of("source_target").unwrap_or_else(|| source::EMSCRIPTEN_PATH); + if source_target_val == source::UNKNOWN_PATH { source_input = source_input.unknown() - } else if source_target_val == "wasm32-unknown-emscripten" { + } else if source_target_val == source::EMSCRIPTEN_PATH { source_input = source_input.emscripten() } else { - println!("--target can be: 'wasm32-unknown-emscripten' or 'wasm32-unknown-unknown'"); + println!("--target can be: '{}' or '{}'", source::EMSCRIPTEN_PATH, source::UNKNOWN_PATH); ::std::process::exit(1); } @@ -138,7 +138,6 @@ fn main() { let mut file = fs::File::create(&path).expect("Failed to create file"); file.write_all(&raw_module).expect("Failed to write module to file"); } - } #[cfg(test)] diff --git a/build/src/source.rs b/build/src/source.rs index f933aac..ff01083 100644 --- a/build/src/source.rs +++ b/build/src/source.rs @@ -1,5 +1,8 @@ //! Configuration of source binaries +pub const UNKNOWN_PATH: &str = "wasm32-unknown-unknown"; +pub const EMSCRIPTEN_PATH: &str = "wasm32-unknown-emscripten"; + /// Target configiration of previous build step #[derive(Debug)] pub enum SourceTarget { From 06219aa6e2d722b575ca303537a0f1f5fdef11cb Mon Sep 17 00:00:00 2001 From: NikVolf Date: Tue, 26 Dec 2017 16:03:59 +0300 Subject: [PATCH 05/12] externalize mem --- src/ext.rs | 9 +++++++++ src/lib.rs | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/ext.rs b/src/ext.rs index bba1777..479d770 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -1,4 +1,5 @@ use parity_wasm::{elements, builder}; +use optimizer::import_section; type Insertion = (usize, u32, u32, String); @@ -37,6 +38,14 @@ pub fn externalize_mem(mut module: elements::Module) -> elements::Module { .pop() .expect("Own memory entry to exist in memory section"); + import_section(&mut module).expect("Import section to exist").entries_mut().push( + elements::ImportEntry::new( + "env".to_owned(), + "memory".to_owned(), + elements::External::Memory(entry), + ) + ); + module } diff --git a/src/lib.rs b/src/lib.rs index 1e994a3..6fe4b75 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ mod runtime_type; pub use optimizer::{optimize, Error as OptimizerError}; pub use gas::inject_gas_counter; pub use logger::init_log; -pub use ext::externalize; +pub use ext::{externalize, externalize_mem}; pub use pack::pack_instance; pub use nondeterminism_check::is_deterministic; pub use runtime_type::inject_runtime_type; From f146187e00f489c88c5e3968634d4f014f6de9a4 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 27 Dec 2017 12:12:09 +0300 Subject: [PATCH 06/12] finalize tool --- Cargo.toml | 2 +- build/Cargo.lock | 8 ++++---- build/Cargo.toml | 2 +- build/src/main.rs | 25 +++++++++++++++++++++---- build/src/source.rs | 21 ++++++++++++++++++--- src/ext.rs | 16 +++++++++++++++- src/lib.rs | 2 +- 7 files changed, 61 insertions(+), 15 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1564f03..1b52325 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["NikVolf "] [dependencies] -parity-wasm = "0.15" +parity-wasm = "0.18" log = "0.3" env_logger = "0.4" lazy_static = "0.2" diff --git a/build/Cargo.lock b/build/Cargo.lock index d5dcbf5..3f9003c 100644 --- a/build/Cargo.lock +++ b/build/Cargo.lock @@ -123,7 +123,7 @@ dependencies = [ [[package]] name = "parity-wasm" -version = "0.15.4" +version = "0.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -275,7 +275,7 @@ version = "0.1.0" dependencies = [ "clap 2.27.1 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-wasm 0.15.4 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-wasm 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-utils 0.1.0", ] @@ -290,7 +290,7 @@ dependencies = [ "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-wasm 0.15.4 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-wasm 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -321,7 +321,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "880f77541efa6e5cc74e76910c9884d9859683118839d6a1dc3b11e63512565b" "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" -"checksum parity-wasm 0.15.4 (registry+https://github.com/rust-lang/crates.io-index)" = "235801e9531998c4bb307f4ea6833c9f40a4cf132895219ac8c2cd25a9b310f7" +"checksum parity-wasm 0.18.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f02e35fda913b8873799b817dcab145d1f935a900722ab7274027949d9947a56" "checksum parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "149d8f5b97f3c1133e3cfcd8886449959e856b557ff281e292b733d7c69e005e" "checksum parking_lot_core 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "4f610cb9664da38e417ea3225f23051f589851999535290e077939838ab7a595" "checksum rand 0.3.18 (registry+https://github.com/rust-lang/crates.io-index)" = "6475140dfd8655aeb72e1fd4b7a1cc1c202be65d71669476e392fe62532b9edd" diff --git a/build/Cargo.toml b/build/Cargo.toml index 00febda..6871035 100644 --- a/build/Cargo.toml +++ b/build/Cargo.toml @@ -7,7 +7,7 @@ authors = ["NikVolf "] glob = "0.2" wasm-utils = { path = "../" } clap = "2.24" -parity-wasm = "0.15" +parity-wasm = "0.18" [dev-dependencies] tempdir = "0.3" diff --git a/build/src/main.rs b/build/src/main.rs index eaf1b5d..a3355a9 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -14,7 +14,7 @@ use std::path::PathBuf; use clap::{App, Arg}; use parity_wasm::elements; -use wasm_utils::{CREATE_SYMBOL, CALL_SYMBOL}; +use wasm_utils::{CREATE_SYMBOL, CALL_SYMBOL, underscore_funcs}; #[derive(Debug)] pub enum Error { @@ -32,19 +32,24 @@ impl From for Error { pub fn wasm_path(input: &source::SourceInput) -> String { let mut path = PathBuf::from(input.target_dir()); - path.push(format!("{}.wasm", input.bin_name())); + path.push(format!("{}.wasm", input.final_name())); path.to_string_lossy().to_string() } pub fn process_output(input: &source::SourceInput) -> Result<(), Error> { let mut cargo_path = PathBuf::from(input.target_dir()); let wasm_name = input.bin_name().to_string().replace("-", "_"); - cargo_path.push(source::EMSCRIPTEN_PATH); + cargo_path.push( + match input.target() { + source::SourceTarget::Emscripten => source::EMSCRIPTEN_PATH, + source::SourceTarget::Unknown => source::UNKNOWN_PATH, + } + ); cargo_path.push("release"); cargo_path.push(format!("{}.wasm", wasm_name)); let mut target_path = PathBuf::from(input.target_dir()); - target_path.push(format!("{}.wasm", input.bin_name())); + target_path.push(format!("{}.wasm", input.final_name())); fs::copy(cargo_path, target_path)?; Ok(()) @@ -85,6 +90,10 @@ fn main() { .help("Skip symbol optimization step producing final wasm") .takes_value(true) .long("target")) + .arg(Arg::with_name("final_name") + .help("Final wasm binary name") + .takes_value(true) + .long("final")) .get_matches(); let target_dir = matches.value_of("target").expect("is required; qed"); @@ -101,12 +110,20 @@ fn main() { ::std::process::exit(1); } + if let Some(final_name) = matches.value_of("final_name") { + source_input = source_input.with_final(final_name); + } + process_output(&source_input).expect("Failed to process cargo target directory"); let path = wasm_path(&source_input); let mut module = parity_wasm::deserialize_file(&path).unwrap(); + if let source::SourceTarget::Unknown = source_input.target() { + module = underscore_funcs(module) + } + if let Some(runtime_type) = matches.value_of("runtime_type") { let runtime_type: &[u8] = runtime_type.as_bytes(); if runtime_type.len() != 4 { diff --git a/build/src/source.rs b/build/src/source.rs index ff01083..bdeb230 100644 --- a/build/src/source.rs +++ b/build/src/source.rs @@ -4,7 +4,7 @@ pub const UNKNOWN_PATH: &str = "wasm32-unknown-unknown"; pub const EMSCRIPTEN_PATH: &str = "wasm32-unknown-emscripten"; /// Target configiration of previous build step -#[derive(Debug)] +#[derive(Debug, Clone, Copy)] pub enum SourceTarget { Emscripten, Unknown, @@ -15,6 +15,7 @@ pub enum SourceTarget { pub struct SourceInput<'a> { target_dir: &'a str, bin_name: &'a str, + final_name: &'a str, target: SourceTarget, } @@ -23,6 +24,7 @@ impl<'a> SourceInput<'a> { SourceInput { target_dir: target_dir, bin_name: bin_name, + final_name: bin_name, target: SourceTarget::Emscripten, } } @@ -37,11 +39,24 @@ impl<'a> SourceInput<'a> { self } + pub fn with_final(mut self, final_name: &'a str) -> Self { + self.final_name = final_name; + self + } + pub fn target_dir(&self) -> &str { - &self.target_dir + self.target_dir } pub fn bin_name(&self) -> &str { - &self.bin_name + self.bin_name + } + + pub fn final_name(&self) -> &str { + self.final_name + } + + pub fn target(&self) -> SourceTarget { + self.target } } \ No newline at end of file diff --git a/src/ext.rs b/src/ext.rs index 479d770..10572e7 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -1,5 +1,5 @@ use parity_wasm::{elements, builder}; -use optimizer::import_section; +use optimizer::{import_section, export_section}; type Insertion = (usize, u32, u32, String); @@ -49,6 +49,20 @@ pub fn externalize_mem(mut module: elements::Module) -> elements::Module { module } +pub fn underscore_funcs(mut module: elements::Module) -> elements::Module { + for entry in import_section(&mut module).expect("Import section to exist").entries_mut() { + if let elements::External::Function(_) = *entry.external() { + entry.field_mut().insert(0, '_'); + } + } + for entry in export_section(&mut module).expect("Import section to exist").entries_mut() { + if let elements::Internal::Function(_) = *entry.internal() { + entry.field_mut().insert(0, '_'); + } + } + module +} + pub fn externalize( module: elements::Module, replaced_funcs: Vec<&str>, diff --git a/src/lib.rs b/src/lib.rs index 6fe4b75..afdb5e1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -21,7 +21,7 @@ mod runtime_type; pub use optimizer::{optimize, Error as OptimizerError}; pub use gas::inject_gas_counter; pub use logger::init_log; -pub use ext::{externalize, externalize_mem}; +pub use ext::{externalize, externalize_mem, underscore_funcs}; pub use pack::pack_instance; pub use nondeterminism_check::is_deterministic; pub use runtime_type::inject_runtime_type; From bf90913055240bf290ca59274707ad9894e558d2 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 27 Dec 2017 12:35:31 +0300 Subject: [PATCH 07/12] save-raw option --- build/src/main.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/build/src/main.rs b/build/src/main.rs index a3355a9..2fe9770 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -94,6 +94,10 @@ fn main() { .help("Final wasm binary name") .takes_value(true) .long("final")) + .arg(Arg::with_name("save_raw") + .help("Save intermediate raw bytecode to path") + .takes_value(true) + .long("save-raw")) .get_matches(); let target_dir = matches.value_of("target").expect("is required; qed"); @@ -140,6 +144,11 @@ fn main() { wasm_utils::optimize(&mut module, vec![CALL_SYMBOL]).expect("Optimizer to finish without errors"); } + if let Some(save_raw_path) = matches.value_of("save_raw") { + parity_wasm::serialize_to_file(save_raw_path, module.clone()) + .expect("Failed to write intermediate module"); + } + let raw_module = parity_wasm::serialize(module).expect("Failed to serialize module"); // If module has an exported function with name=CREATE_SYMBOL From c5ced73d5512e93adb40ddfc0e3786b227184ef1 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 27 Dec 2017 12:38:27 +0300 Subject: [PATCH 08/12] fix help text --- build/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/src/main.rs b/build/src/main.rs index 2fe9770..64c9195 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -87,7 +87,7 @@ fn main() { .takes_value(true) .long("runtime-version")) .arg(Arg::with_name("source_target") - .help("Skip symbol optimization step producing final wasm") + .help("Cargo target type kind (wasm32-unknown-unknown/emscripten)") .takes_value(true) .long("target")) .arg(Arg::with_name("final_name") From 1da5e9f64f54cd32bc360c2f8c1ee254cff0e77f Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 27 Dec 2017 13:02:24 +0300 Subject: [PATCH 09/12] fix version --- ext/Cargo.toml | 2 +- gas/Cargo.toml | 2 +- prune/Cargo.toml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ext/Cargo.toml b/ext/Cargo.toml index 63bf8c5..2e7f8da 100644 --- a/ext/Cargo.toml +++ b/ext/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" authors = ["NikVolf "] [dependencies] -parity-wasm = "0.15" +parity-wasm = "0.18" wasm-utils = { path = "../" } \ No newline at end of file diff --git a/gas/Cargo.toml b/gas/Cargo.toml index 0cd6b75..2fe122b 100644 --- a/gas/Cargo.toml +++ b/gas/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" authors = ["NikVolf "] [dependencies] -parity-wasm = "0.15" +parity-wasm = "0.18" wasm-utils = { path = "../" } \ No newline at end of file diff --git a/prune/Cargo.toml b/prune/Cargo.toml index 3832b1e..b04bed8 100644 --- a/prune/Cargo.toml +++ b/prune/Cargo.toml @@ -4,6 +4,6 @@ version = "0.1.0" authors = ["NikVolf "] [dependencies] -parity-wasm = "0.15" +parity-wasm = "0.18" wasm-utils = { path = "../" } clap = "2.24" From ce2d2c57ae9db9898afd5abe67574f68bbdde7ea Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 27 Dec 2017 16:29:26 +0300 Subject: [PATCH 10/12] fix & update packing test --- Cargo.toml | 1 + src/pack.rs | 13 ++++++------- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1b52325..771705e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,6 +14,7 @@ byteorder = "1" [dev-dependencies] tempdir = "0.3" +pwasm-emscripten = { git = "https://github.com/paritytech/parity-wasm", path = "pwasm-emscripten" } [lib] diff --git a/src/pack.rs b/src/pack.rs index 6bc64e8..8e0b4a1 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -129,8 +129,8 @@ pub fn pack_instance(raw_module: Vec, mut ctor_module: elements::Module) -> #[cfg(test)] mod test { + extern crate pwasm_emscripten; extern crate parity_wasm; - extern crate byteorder; use parity_wasm::builder; use parity_wasm::interpreter; @@ -139,6 +139,7 @@ mod test { use super::*; use super::super::optimize; use byteorder::{ByteOrder, LittleEndian}; + use self::pwasm_emscripten::program_with_emscripten_env; #[test] fn call_returns_code() { @@ -194,14 +195,13 @@ mod test { let raw_module = parity_wasm::serialize(module).unwrap(); let ctor_module = pack_instance(raw_module.clone(), ctor_module).expect("Packing failed"); - let program = parity_wasm::DefaultProgramInstance::new().expect("Program instance failed to load"); + let program = program_with_emscripten_env(Default::default()).expect("Wasm program to be created"); let env_instance = program.module("env").expect("Wasm program to contain env module"); let env_memory = env_instance.memory(interpreter::ItemIndex::Internal(0)).expect("Linear memory to exist in wasm runtime"); - let execution_params = interpreter::ExecutionParams::default(); let constructor_module = program.add_module("contract", ctor_module, None).expect("Failed to initialize module"); - let _ = constructor_module.execute_export(CALL_SYMBOL, execution_params.add_argument(RuntimeValue::I32(1024))); + let _ = constructor_module.execute_export(CALL_SYMBOL, vec![RuntimeValue::I32(1024)].into()); let pointer = LittleEndian::read_u32(&env_memory.get(1024 + 8, 4).unwrap()); let len = LittleEndian::read_u32(&env_memory.get(1024 + 12, 4).unwrap()); @@ -212,10 +212,9 @@ mod test { let contract_module: elements::Module = parity_wasm::deserialize_buffer(contract_code).expect("Constructed contract module is not valid"); - let program = parity_wasm::DefaultProgramInstance::new().expect("Program2 instance failed to load"); + let program = program_with_emscripten_env(Default::default()).expect("Wasm program to be created"); let contract_module_instance = program.add_module("contract", contract_module, None).expect("Failed to initialize constructed contract module"); - let execution_params = interpreter::ExecutionParams::default(); - contract_module_instance.execute_export(CALL_SYMBOL, execution_params).expect("Constructed contract failed to execute"); + contract_module_instance.execute_export(CALL_SYMBOL, Default::default()).expect("Constructed contract failed to execute"); } } From 3cf1ee5c577bd5de378e1b0d606482717c9591f5 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 27 Dec 2017 17:03:51 +0300 Subject: [PATCH 11/12] fix help message --- build/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build/src/main.rs b/build/src/main.rs index 64c9195..762c48c 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -87,7 +87,7 @@ fn main() { .takes_value(true) .long("runtime-version")) .arg(Arg::with_name("source_target") - .help("Cargo target type kind (wasm32-unknown-unknown/emscripten)") + .help("Cargo target type kind ('wasm32-unknown-unknown' or 'wasm32-unknown-emscripten'") .takes_value(true) .long("target")) .arg(Arg::with_name("final_name") From 236d590a87210e9f3c01ec51519324224ec37f99 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 27 Dec 2017 17:50:31 +0300 Subject: [PATCH 12/12] path -> triplet --- build/src/main.rs | 12 ++++++------ build/src/source.rs | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/build/src/main.rs b/build/src/main.rs index 762c48c..dfdb7d8 100644 --- a/build/src/main.rs +++ b/build/src/main.rs @@ -41,8 +41,8 @@ pub fn process_output(input: &source::SourceInput) -> Result<(), Error> { let wasm_name = input.bin_name().to_string().replace("-", "_"); cargo_path.push( match input.target() { - source::SourceTarget::Emscripten => source::EMSCRIPTEN_PATH, - source::SourceTarget::Unknown => source::UNKNOWN_PATH, + source::SourceTarget::Emscripten => source::EMSCRIPTEN_TRIPLET, + source::SourceTarget::Unknown => source::UNKNOWN_TRIPLET, } ); cargo_path.push("release"); @@ -104,13 +104,13 @@ fn main() { let wasm_binary = matches.value_of("wasm").expect("is required; qed"); let mut source_input = source::SourceInput::new(target_dir, wasm_binary); - let source_target_val = matches.value_of("source_target").unwrap_or_else(|| source::EMSCRIPTEN_PATH); - if source_target_val == source::UNKNOWN_PATH { + let source_target_val = matches.value_of("source_target").unwrap_or_else(|| source::EMSCRIPTEN_TRIPLET); + if source_target_val == source::UNKNOWN_TRIPLET { source_input = source_input.unknown() - } else if source_target_val == source::EMSCRIPTEN_PATH { + } else if source_target_val == source::EMSCRIPTEN_TRIPLET { source_input = source_input.emscripten() } else { - println!("--target can be: '{}' or '{}'", source::EMSCRIPTEN_PATH, source::UNKNOWN_PATH); + println!("--target can be: '{}' or '{}'", source::EMSCRIPTEN_TRIPLET, source::UNKNOWN_TRIPLET); ::std::process::exit(1); } diff --git a/build/src/source.rs b/build/src/source.rs index bdeb230..627bed6 100644 --- a/build/src/source.rs +++ b/build/src/source.rs @@ -1,7 +1,7 @@ //! Configuration of source binaries -pub const UNKNOWN_PATH: &str = "wasm32-unknown-unknown"; -pub const EMSCRIPTEN_PATH: &str = "wasm32-unknown-emscripten"; +pub const UNKNOWN_TRIPLET: &str = "wasm32-unknown-unknown"; +pub const EMSCRIPTEN_TRIPLET: &str = "wasm32-unknown-emscripten"; /// Target configiration of previous build step #[derive(Debug, Clone, Copy)]