From bb47c22618c6b9467f5731bef026e391dc808cd4 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 15 May 2018 08:05:00 +0800 Subject: [PATCH 1/8] Refactor executables to separate crates --- Cargo.toml | 42 ++++++++++++---------------------- build/Cargo.toml | 19 +++++++++++++++ build/{ => src}/main.rs | 3 ++- build/{ => src}/source.rs | 0 ext/Cargo.toml | 17 ++++++++++++++ ext/{ => src}/main.rs | 3 ++- gas/Cargo.toml | 17 ++++++++++++++ gas/{ => src}/main.rs | 4 ++-- logger/Cargo.toml | 16 +++++++++++++ logger/src/lib.rs | 27 ++++++++++++++++++++++ prune/Cargo.toml | 18 +++++++++++++++ prune/{ => src}/main.rs | 3 ++- src/lib.rs | 4 ---- src/logger.rs | 26 --------------------- stack_height/Cargo.toml | 17 ++++++++++++++ stack_height/{ => src}/main.rs | 3 ++- 16 files changed, 156 insertions(+), 63 deletions(-) create mode 100644 build/Cargo.toml rename build/{ => src}/main.rs (99%) rename build/{ => src}/source.rs (100%) create mode 100644 ext/Cargo.toml rename ext/{ => src}/main.rs (92%) create mode 100644 gas/Cargo.toml rename gas/{ => src}/main.rs (93%) create mode 100644 logger/Cargo.toml create mode 100644 logger/src/lib.rs create mode 100644 prune/Cargo.toml rename prune/{ => src}/main.rs (97%) delete mode 100644 src/logger.rs create mode 100644 stack_height/Cargo.toml rename stack_height/{ => src}/main.rs (93%) diff --git a/Cargo.toml b/Cargo.toml index 78e86b5..074bbfd 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,37 +8,25 @@ description = "Collection of command-line utilities and corresponding Rust api f keywords = ["wasm", "webassembly", "pwasm"] [dependencies] -parity-wasm = "0.27" -log = "0.3" -env_logger = "0.4" -lazy_static = "0.2" -clap = "2.24" -glob = "0.2" -byteorder = "1" +parity-wasm = { git = "https://github.com/paritytech/parity-wasm", default-features = false } +log = { version = "0.4", default-features = false } +byteorder = { version = "1", default-features = false } [dev-dependencies] tempdir = "0.3" wabt = "0.2" diff = "0.1.11" -[lib] +[features] +default = ["std"] +std = ["parity-wasm/std", "log/std", "byteorder/std"] -[[bin]] -name = "wasm-prune" -path = "prune/main.rs" - -[[bin]] -name = "wasm-ext" -path = "ext/main.rs" - -[[bin]] -name = "wasm-gas" -path = "gas/main.rs" - -[[bin]] -name = "wasm-build" -path = "build/main.rs" - -[[bin]] -name = "wasm-stack-height" -path = "stack_height/main.rs" +[workspace] +members = [ + "./logger", + "./build", + "./ext", + "./gas", + "./prune", + "./stack_height", +] diff --git a/build/Cargo.toml b/build/Cargo.toml new file mode 100644 index 0000000..2f40425 --- /dev/null +++ b/build/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "pwasm-utils-build" +version = "0.1.5" +authors = ["Nikolay Volf ", "Sergey Pepyakin "] +license = "MIT/Apache-2.0" +readme = "README.md" +description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" +keywords = ["wasm", "webassembly", "pwasm"] + +[[bin]] +name = "wasm-build" +path = "src/main.rs" + +[dependencies] +parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } +pwasm-utils = { path = ".." } +pwasm-utils-logger = { path = "../logger" } +glob = "0.2" +clap = "2.24" diff --git a/build/main.rs b/build/src/main.rs similarity index 99% rename from build/main.rs rename to build/src/main.rs index 5bf79d8..29342bc 100644 --- a/build/main.rs +++ b/build/src/main.rs @@ -4,6 +4,7 @@ extern crate glob; extern crate pwasm_utils as utils; extern crate clap; extern crate parity_wasm; +extern crate logger; mod source; @@ -95,7 +96,7 @@ fn has_ctor(module: &elements::Module) -> bool { } fn do_main() -> Result<(), Error> { - utils::init_log(); + logger::init_log(); let matches = App::new("wasm-build") .arg(Arg::with_name("target") diff --git a/build/source.rs b/build/src/source.rs similarity index 100% rename from build/source.rs rename to build/src/source.rs diff --git a/ext/Cargo.toml b/ext/Cargo.toml new file mode 100644 index 0000000..13dd2c8 --- /dev/null +++ b/ext/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "pwasm-utils-ext" +version = "0.1.5" +authors = ["Nikolay Volf ", "Sergey Pepyakin "] +license = "MIT/Apache-2.0" +readme = "README.md" +description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" +keywords = ["wasm", "webassembly", "pwasm"] + +[[bin]] +name = "wasm-ext" +path = "src/main.rs" + +[dependencies] +parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } +pwasm-utils = { path = ".." } +pwasm-utils-logger = { path = "../logger" } diff --git a/ext/main.rs b/ext/src/main.rs similarity index 92% rename from ext/main.rs rename to ext/src/main.rs index ee6796a..621162c 100644 --- a/ext/main.rs +++ b/ext/src/main.rs @@ -1,11 +1,12 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; +extern crate logger; use std::env; fn main() { - utils::init_log(); + logger::init_log(); let args = env::args().collect::>(); if args.len() != 3 { diff --git a/gas/Cargo.toml b/gas/Cargo.toml new file mode 100644 index 0000000..b932958 --- /dev/null +++ b/gas/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "pwasm-utils-gas" +version = "0.1.5" +authors = ["Nikolay Volf ", "Sergey Pepyakin "] +license = "MIT/Apache-2.0" +readme = "README.md" +description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" +keywords = ["wasm", "webassembly", "pwasm"] + +[[bin]] +name = "wasm-gas" +path = "src/main.rs" + +[dependencies] +parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } +pwasm-utils = { path = ".." } +pwasm-utils-logger = { path = "../logger" } diff --git a/gas/main.rs b/gas/src/main.rs similarity index 93% rename from gas/main.rs rename to gas/src/main.rs index 4c02bce..86f5f56 100644 --- a/gas/main.rs +++ b/gas/src/main.rs @@ -1,11 +1,11 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; +extern crate logger; use std::env; fn main() { - - utils::init_log(); + logger::init_log(); let args = env::args().collect::>(); if args.len() != 3 { diff --git a/logger/Cargo.toml b/logger/Cargo.toml new file mode 100644 index 0000000..20cbac4 --- /dev/null +++ b/logger/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "pwasm-utils-logger" +version = "0.1.5" +authors = ["Nikolay Volf ", "Sergey Pepyakin "] +license = "MIT/Apache-2.0" +readme = "README.md" +description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" +keywords = ["wasm", "webassembly", "pwasm"] + +[lib] +name = "logger" + +[dependencies] +log = "0.4" +env_logger = "0.5" +lazy_static = "1.0" diff --git a/logger/src/lib.rs b/logger/src/lib.rs new file mode 100644 index 0000000..eeaabb0 --- /dev/null +++ b/logger/src/lib.rs @@ -0,0 +1,27 @@ +#[macro_use] extern crate log; +#[macro_use] extern crate lazy_static; +extern crate env_logger; + +use std::env; +use log::LevelFilter; +use env_logger::Builder; + +lazy_static! { + static ref LOG_DUMMY: bool = { + let mut builder = Builder::new(); + builder.filter(None, LevelFilter::Info); + + if let Ok(log) = env::var("RUST_LOG") { + builder.parse(&log); + } + + builder.init(); + trace!("logger initialized"); + true + }; +} + +/// Intialize log with default settings +pub fn init_log() { + let _ = *LOG_DUMMY; +} diff --git a/prune/Cargo.toml b/prune/Cargo.toml new file mode 100644 index 0000000..f3d451e --- /dev/null +++ b/prune/Cargo.toml @@ -0,0 +1,18 @@ +[package] +name = "pwasm-utils-prune" +version = "0.1.5" +authors = ["Nikolay Volf ", "Sergey Pepyakin "] +license = "MIT/Apache-2.0" +readme = "README.md" +description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" +keywords = ["wasm", "webassembly", "pwasm"] + +[[bin]] +name = "wasm-prune" +path = "src/main.rs" + +[dependencies] +parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } +pwasm-utils = { path = ".." } +pwasm-utils-logger = { path = "../logger" } +clap = "2.24" diff --git a/prune/main.rs b/prune/src/main.rs similarity index 97% rename from prune/main.rs rename to prune/src/main.rs index 16f3b3c..f7e5dd9 100644 --- a/prune/main.rs +++ b/prune/src/main.rs @@ -1,11 +1,12 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; +extern crate logger; extern crate clap; use clap::{App, Arg}; fn main() { - utils::init_log(); + logger::init_log(); let matches = App::new("wasm-opt") .arg(Arg::with_name("input") diff --git a/src/lib.rs b/src/lib.rs index 8753ec7..50d6e79 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,6 @@ extern crate parity_wasm; -extern crate env_logger; extern crate byteorder; #[macro_use] extern crate log; -#[macro_use] extern crate lazy_static; pub static CREATE_SYMBOL: &'static str = "deploy"; pub static CALL_SYMBOL: &'static str = "call"; @@ -13,7 +11,6 @@ pub mod rules; mod optimizer; mod gas; mod symbols; -mod logger; mod ext; mod pack; mod runtime_type; @@ -22,7 +19,6 @@ pub mod stack_height; pub use optimizer::{optimize, Error as OptimizerError}; pub use gas::inject_gas_counter; -pub use logger::init_log; pub use ext::{externalize, externalize_mem, underscore_funcs, ununderscore_funcs, shrink_unknown_stack}; pub use pack::{pack_instance, Error as PackingError}; pub use runtime_type::inject_runtime_type; diff --git a/src/logger.rs b/src/logger.rs deleted file mode 100644 index b7e2af8..0000000 --- a/src/logger.rs +++ /dev/null @@ -1,26 +0,0 @@ -extern crate log; - -use std::env; -use log::LogLevelFilter; -use env_logger::LogBuilder; - -lazy_static! { - static ref LOG_DUMMY: bool = { - let mut builder = LogBuilder::new(); - builder.filter(None, LogLevelFilter::Info); - - if let Ok(log) = env::var("RUST_LOG") { - builder.parse(&log); - } - - if let Ok(_) = builder.init() { - trace!("logger initialized"); - } - true - }; -} - -/// Intialize log with default settings -pub fn init_log() { - let _ = *LOG_DUMMY; -} diff --git a/stack_height/Cargo.toml b/stack_height/Cargo.toml new file mode 100644 index 0000000..b1ec658 --- /dev/null +++ b/stack_height/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "pwasm-utils-stack-height" +version = "0.1.5" +authors = ["Nikolay Volf ", "Sergey Pepyakin "] +license = "MIT/Apache-2.0" +readme = "README.md" +description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" +keywords = ["wasm", "webassembly", "pwasm"] + +[[bin]] +name = "wasm-stack-height" +path = "src/main.rs" + +[dependencies] +parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } +pwasm-utils = { path = ".." } +pwasm-utils-logger = { path = "../logger" } diff --git a/stack_height/main.rs b/stack_height/src/main.rs similarity index 93% rename from stack_height/main.rs rename to stack_height/src/main.rs index 80b8122..762b2ba 100644 --- a/stack_height/main.rs +++ b/stack_height/src/main.rs @@ -1,11 +1,12 @@ extern crate pwasm_utils as utils; extern crate parity_wasm; +extern crate logger; use std::env; use utils::stack_height; fn main() { - utils::init_log(); + logger::init_log(); let args = env::args().collect::>(); if args.len() != 3 { From a30afec0cdbadbe395ac743e371b3f33b9f952e4 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 15 May 2018 08:22:29 +0800 Subject: [PATCH 2/8] Port core util lib to support no_std --- src/ext.rs | 6 +++++- src/gas.rs | 2 ++ src/lib.rs | 17 +++++++++++++++++ src/optimizer.rs | 11 ++++++++--- src/pack.rs | 3 +++ src/rules.rs | 14 +++++++++----- src/stack_height/max_height.rs | 2 ++ src/stack_height/mod.rs | 3 +++ src/stack_height/thunk.rs | 12 ++++++++---- src/symbols.rs | 31 ++++++++++++++++++------------- 10 files changed, 75 insertions(+), 26 deletions(-) diff --git a/src/ext.rs b/src/ext.rs index 24eec02..5983785 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -1,3 +1,7 @@ +use std::string::String; +use std::vec::Vec; +use std::borrow::ToOwned; + use parity_wasm::{elements, builder}; use optimizer::{import_section, export_section}; use byteorder::{LittleEndian, ByteOrder}; @@ -200,4 +204,4 @@ pub fn externalize( module -} \ No newline at end of file +} diff --git a/src/gas.rs b/src/gas.rs index 99bcc6b..730e703 100644 --- a/src/gas.rs +++ b/src/gas.rs @@ -1,3 +1,5 @@ +use std::vec::Vec; + use parity_wasm::{elements, builder}; use rules; diff --git a/src/lib.rs b/src/lib.rs index 50d6e79..f1dc516 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,3 +1,10 @@ +#![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(not(feature = "std"), feature(alloc))] + +#[cfg(not(feature = "std"))] +#[macro_use] +extern crate alloc; + extern crate parity_wasm; extern crate byteorder; #[macro_use] extern crate log; @@ -22,3 +29,13 @@ pub use gas::inject_gas_counter; pub use ext::{externalize, externalize_mem, underscore_funcs, ununderscore_funcs, shrink_unknown_stack}; pub use pack::{pack_instance, Error as PackingError}; pub use runtime_type::inject_runtime_type; + +#[cfg(not(feature = "std"))] +mod std { + pub use core::*; + pub use alloc::{vec, string, boxed, borrow}; + + pub mod collections { + pub use alloc::{BTreeMap, BTreeSet}; + } +} diff --git a/src/optimizer.rs b/src/optimizer.rs index 9d2f6bb..890aab0 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -1,4 +1,9 @@ -use std::collections::HashSet; +#[cfg(features = "std")] +use std::collections::{HashSet as Set}; +#[cfg(not(features = "std"))] +use std::collections::{BTreeSet as Set}; +use std::vec::Vec; + use parity_wasm::elements; use symbols::{Symbol, expand_symbols, push_code_symbols, resolve_function}; @@ -19,7 +24,7 @@ pub fn optimize( // which in turn compile in unused imports and leaves unused functions // Algo starts from the top, listing all items that should stay - let mut stay = HashSet::new(); + let mut stay = Set::new(); for (index, entry) in module.export_section().ok_or(Error::NoExportSection)?.entries().iter().enumerate() { if used_exports.iter().find(|e| **e == entry.field()).is_some() { stay.insert(Symbol::Export(index)); @@ -615,4 +620,4 @@ mod tests { } } -} \ No newline at end of file +} diff --git a/src/pack.rs b/src/pack.rs index 96e6746..79dd52e 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -1,4 +1,7 @@ use std::fmt; +use std::vec::Vec; +use std::borrow::ToOwned; + use parity_wasm::elements::{ self, Section, DataSection, Opcode, DataSegment, InitExpr, Internal, External, ImportCountType, diff --git a/src/rules.rs b/src/rules.rs index 50d85cd..f5a254c 100644 --- a/src/rules.rs +++ b/src/rules.rs @@ -1,4 +1,8 @@ -use std::collections::HashMap; +#[cfg(features = "std")] +use std::collections::{HashMap as Map}; +#[cfg(not(features = "std"))] +use std::collections::{BTreeMap as Map}; + use parity_wasm::elements; pub struct UnknownInstruction; @@ -10,7 +14,7 @@ pub enum Metering { Fixed(u32), } -#[derive(Debug, Hash, PartialEq, Eq, Copy, Clone)] +#[derive(Debug, Hash, PartialEq, Eq, PartialOrd, Ord, Copy, Clone)] pub enum InstructionType { Bit, Add, @@ -265,7 +269,7 @@ impl InstructionType { #[derive(Debug)] pub struct Set { regular: u32, - entries: HashMap, + entries: Map, grow: u32, } @@ -273,14 +277,14 @@ impl Default for Set { fn default() -> Self { Set { regular: 1, - entries: HashMap::new(), + entries: Map::new(), grow: 0, } } } impl Set { - pub fn new(regular: u32, entries: HashMap) -> Self { + pub fn new(regular: u32, entries: Map) -> Self { Set { regular: regular, entries: entries, grow: 0 } } diff --git a/src/stack_height/max_height.rs b/src/stack_height/max_height.rs index fc4ca50..3d55e69 100644 --- a/src/stack_height/max_height.rs +++ b/src/stack_height/max_height.rs @@ -1,3 +1,5 @@ +use std::vec::Vec; + use parity_wasm::elements::{self, BlockType, Type}; use super::{resolve_func_type, Error}; diff --git a/src/stack_height/mod.rs b/src/stack_height/mod.rs index 9502ff5..119dedc 100644 --- a/src/stack_height/mod.rs +++ b/src/stack_height/mod.rs @@ -48,6 +48,9 @@ //! between the frames. //! - upon entry into the function entire stack frame is allocated. +use std::string::String; +use std::vec::Vec; + use parity_wasm::elements::{self, Type}; use parity_wasm::builder; diff --git a/src/stack_height/thunk.rs b/src/stack_height/thunk.rs index be1d626..ea1354b 100644 --- a/src/stack_height/thunk.rs +++ b/src/stack_height/thunk.rs @@ -1,8 +1,12 @@ +#[cfg(features = "std")] +use std::collections::{HashMap as Map}; +#[cfg(not(features = "std"))] +use std::collections::{BTreeMap as Map}; +use std::vec::Vec; + use parity_wasm::elements::{self, FunctionType, Internal}; use parity_wasm::builder; -use std::collections::HashMap; - use super::{resolve_func_type, Context, Error}; struct Thunk { @@ -22,7 +26,7 @@ pub(crate) fn generate_thunks( // Function indicies which needs to generate thunks. let mut need_thunks: Vec = Vec::new(); - let mut replacement_map: HashMap = { + let mut replacement_map: Map = { let exports = module .export_section() .map(|es| es.entries()) @@ -42,7 +46,7 @@ pub(crate) fn generate_thunks( .cloned(); // Replacement map is at least export section size. - let mut replacement_map: HashMap = HashMap::new(); + let mut replacement_map: Map = Map::new(); for func_idx in exported_func_indicies.chain(table_func_indicies) { let callee_stack_cost = ctx.stack_cost(func_idx).ok_or_else(|| { diff --git a/src/symbols.rs b/src/symbols.rs index 3348f1e..4e778a8 100644 --- a/src/symbols.rs +++ b/src/symbols.rs @@ -1,7 +1,12 @@ -use parity_wasm::elements; -use std::collections::HashSet; +#[cfg(features = "std")] +use std::collections::{HashSet as Set}; +#[cfg(not(features = "std"))] +use std::collections::{BTreeSet as Set}; +use std::vec::Vec; -#[derive(PartialEq, Eq, Hash, Copy, Clone, Debug)] +use parity_wasm::elements; + +#[derive(PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Clone, Debug)] pub enum Symbol { Type(usize), Import(usize), @@ -63,19 +68,19 @@ pub fn push_code_symbols(module: &elements::Module, opcodes: &[elements::Opcode] dest.push(resolve_global(module, idx)) }, _ => { }, - } + } } } -pub fn expand_symbols(module: &elements::Module, set: &mut HashSet) { +pub fn expand_symbols(module: &elements::Module, set: &mut Set) { use self::Symbol::*; // symbols that were already processed - let mut stop: HashSet = HashSet::new(); + let mut stop: Set = Set::new(); let mut fringe = set.iter().cloned().collect::>(); loop { let next = match fringe.pop() { - Some(s) if stop.contains(&s) => { continue; } + Some(s) if stop.contains(&s) => { continue; } Some(s) => s, _ => { break; } }; @@ -86,7 +91,7 @@ pub fn expand_symbols(module: &elements::Module, set: &mut HashSet) { let entry = &module.export_section().expect("Export section to exist").entries()[idx]; match entry.internal() { &elements::Internal::Function(func_idx) => { - let symbol = resolve_function(module, func_idx); + let symbol = resolve_function(module, func_idx); if !stop.contains(&symbol) { fringe.push(symbol); } @@ -97,7 +102,7 @@ pub fn expand_symbols(module: &elements::Module, set: &mut HashSet) { if !stop.contains(&symbol) { fringe.push(symbol); } - set.insert(symbol); + set.insert(symbol); }, _ => {} } @@ -110,9 +115,9 @@ pub fn expand_symbols(module: &elements::Module, set: &mut HashSet) { if !stop.contains(&type_symbol) { fringe.push(type_symbol); } - set.insert(type_symbol); + set.insert(type_symbol); }, - _ => {} + _ => {} } }, Function(idx) => { @@ -142,11 +147,11 @@ pub fn expand_symbols(module: &elements::Module, set: &mut HashSet) { fringe.push(symbol); } set.insert(symbol); - } + } } _ => {} } stop.insert(next); } -} \ No newline at end of file +} From 605c99974b52e554c33abf6b92f5793f8fd4f24b Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 15 May 2018 08:25:35 +0800 Subject: [PATCH 3/8] Fix tests --- build/Cargo.toml | 3 +++ src/pack.rs | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/build/Cargo.toml b/build/Cargo.toml index 2f40425..70e2c85 100644 --- a/build/Cargo.toml +++ b/build/Cargo.toml @@ -17,3 +17,6 @@ pwasm-utils = { path = ".." } pwasm-utils-logger = { path = "../logger" } glob = "0.2" clap = "2.24" + +[dev-dependencies] +tempdir = "0.3" diff --git a/src/pack.rs b/src/pack.rs index 79dd52e..e8a1096 100644 --- a/src/pack.rs +++ b/src/pack.rs @@ -227,7 +227,6 @@ mod test { use parity_wasm::builder; use super::*; use super::super::optimize; - use byteorder::{ByteOrder, LittleEndian}; fn test_packer(mut module: elements::Module) { let mut ctor_module = module.clone(); From b4a1fd88b3e2ec913d2079d9d351d934af5f4dc8 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 15 May 2018 08:26:52 +0800 Subject: [PATCH 4/8] Test no_std build in CI --- .travis.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 6227873..86d7a85 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,9 @@ -language: - - rust +language: rust +rust: + - nightly + - stable script: - - cargo build --release --verbose - - cargo test --verbose \ No newline at end of file + - cargo build --all --release --verbose + - cargo test --all --verbose + - if [ "$TRAVIS_RUST_VERSION" == "nightly" ]; then cargo build --no-default-features; fi From d36a8cbacc9d630672f0433dd0bd111f337f3662 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 15 May 2018 19:16:31 +0800 Subject: [PATCH 5/8] Move all executables to wasm-utils-tools crate --- Cargo.toml | 7 +---- ext/Cargo.toml | 17 ------------ gas/Cargo.toml | 17 ------------ logger/Cargo.toml | 16 ------------ prune/Cargo.toml | 18 ------------- stack_height/Cargo.toml | 17 ------------ {build => tools}/Cargo.toml | 26 ++++++++++++++++--- {build/src => tools/build}/main.rs | 2 +- {build/src => tools/build}/source.rs | 0 {ext/src => tools/ext}/main.rs | 2 +- {gas/src => tools/gas}/main.rs | 2 +- {prune/src => tools/prune}/main.rs | 2 +- {logger => tools}/src/lib.rs | 0 .../src => tools/stack_height}/main.rs | 2 +- 14 files changed, 29 insertions(+), 99 deletions(-) delete mode 100644 ext/Cargo.toml delete mode 100644 gas/Cargo.toml delete mode 100644 logger/Cargo.toml delete mode 100644 prune/Cargo.toml delete mode 100644 stack_height/Cargo.toml rename {build => tools}/Cargo.toml (62%) rename {build/src => tools/build}/main.rs (99%) rename {build/src => tools/build}/source.rs (100%) rename {ext/src => tools/ext}/main.rs (92%) rename {gas/src => tools/gas}/main.rs (93%) rename {prune/src => tools/prune}/main.rs (97%) rename {logger => tools}/src/lib.rs (100%) rename {stack_height/src => tools/stack_height}/main.rs (94%) diff --git a/Cargo.toml b/Cargo.toml index 074bbfd..21e8679 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,10 +23,5 @@ std = ["parity-wasm/std", "log/std", "byteorder/std"] [workspace] members = [ - "./logger", - "./build", - "./ext", - "./gas", - "./prune", - "./stack_height", + "./tools", ] diff --git a/ext/Cargo.toml b/ext/Cargo.toml deleted file mode 100644 index 13dd2c8..0000000 --- a/ext/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "pwasm-utils-ext" -version = "0.1.5" -authors = ["Nikolay Volf ", "Sergey Pepyakin "] -license = "MIT/Apache-2.0" -readme = "README.md" -description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" -keywords = ["wasm", "webassembly", "pwasm"] - -[[bin]] -name = "wasm-ext" -path = "src/main.rs" - -[dependencies] -parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } -pwasm-utils = { path = ".." } -pwasm-utils-logger = { path = "../logger" } diff --git a/gas/Cargo.toml b/gas/Cargo.toml deleted file mode 100644 index b932958..0000000 --- a/gas/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "pwasm-utils-gas" -version = "0.1.5" -authors = ["Nikolay Volf ", "Sergey Pepyakin "] -license = "MIT/Apache-2.0" -readme = "README.md" -description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" -keywords = ["wasm", "webassembly", "pwasm"] - -[[bin]] -name = "wasm-gas" -path = "src/main.rs" - -[dependencies] -parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } -pwasm-utils = { path = ".." } -pwasm-utils-logger = { path = "../logger" } diff --git a/logger/Cargo.toml b/logger/Cargo.toml deleted file mode 100644 index 20cbac4..0000000 --- a/logger/Cargo.toml +++ /dev/null @@ -1,16 +0,0 @@ -[package] -name = "pwasm-utils-logger" -version = "0.1.5" -authors = ["Nikolay Volf ", "Sergey Pepyakin "] -license = "MIT/Apache-2.0" -readme = "README.md" -description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" -keywords = ["wasm", "webassembly", "pwasm"] - -[lib] -name = "logger" - -[dependencies] -log = "0.4" -env_logger = "0.5" -lazy_static = "1.0" diff --git a/prune/Cargo.toml b/prune/Cargo.toml deleted file mode 100644 index f3d451e..0000000 --- a/prune/Cargo.toml +++ /dev/null @@ -1,18 +0,0 @@ -[package] -name = "pwasm-utils-prune" -version = "0.1.5" -authors = ["Nikolay Volf ", "Sergey Pepyakin "] -license = "MIT/Apache-2.0" -readme = "README.md" -description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" -keywords = ["wasm", "webassembly", "pwasm"] - -[[bin]] -name = "wasm-prune" -path = "src/main.rs" - -[dependencies] -parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } -pwasm-utils = { path = ".." } -pwasm-utils-logger = { path = "../logger" } -clap = "2.24" diff --git a/stack_height/Cargo.toml b/stack_height/Cargo.toml deleted file mode 100644 index b1ec658..0000000 --- a/stack_height/Cargo.toml +++ /dev/null @@ -1,17 +0,0 @@ -[package] -name = "pwasm-utils-stack-height" -version = "0.1.5" -authors = ["Nikolay Volf ", "Sergey Pepyakin "] -license = "MIT/Apache-2.0" -readme = "README.md" -description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" -keywords = ["wasm", "webassembly", "pwasm"] - -[[bin]] -name = "wasm-stack-height" -path = "src/main.rs" - -[dependencies] -parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } -pwasm-utils = { path = ".." } -pwasm-utils-logger = { path = "../logger" } diff --git a/build/Cargo.toml b/tools/Cargo.toml similarity index 62% rename from build/Cargo.toml rename to tools/Cargo.toml index 70e2c85..6f8c7bb 100644 --- a/build/Cargo.toml +++ b/tools/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pwasm-utils-build" +name = "pwasm-utils-tools" version = "0.1.5" authors = ["Nikolay Volf ", "Sergey Pepyakin "] license = "MIT/Apache-2.0" @@ -7,16 +7,36 @@ readme = "README.md" description = "Collection of command-line utilities and corresponding Rust api for producing pwasm-compatible executables" keywords = ["wasm", "webassembly", "pwasm"] +[lib] + +[[bin]] +name = "wasm-prune" +path = "prune/main.rs" + +[[bin]] +name = "wasm-ext" +path = "ext/main.rs" + +[[bin]] +name = "wasm-gas" +path = "gas/main.rs" + [[bin]] name = "wasm-build" -path = "src/main.rs" +path = "build/main.rs" + +[[bin]] +name = "wasm-stack-height" +path = "stack_height/main.rs" [dependencies] parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } pwasm-utils = { path = ".." } -pwasm-utils-logger = { path = "../logger" } glob = "0.2" clap = "2.24" +log = "0.4" +env_logger = "0.5" +lazy_static = "1.0" [dev-dependencies] tempdir = "0.3" diff --git a/build/src/main.rs b/tools/build/main.rs similarity index 99% rename from build/src/main.rs rename to tools/build/main.rs index 29342bc..4a1461b 100644 --- a/build/src/main.rs +++ b/tools/build/main.rs @@ -4,7 +4,7 @@ extern crate glob; extern crate pwasm_utils as utils; extern crate clap; extern crate parity_wasm; -extern crate logger; +extern crate pwasm_utils_tools as logger; mod source; diff --git a/build/src/source.rs b/tools/build/source.rs similarity index 100% rename from build/src/source.rs rename to tools/build/source.rs diff --git a/ext/src/main.rs b/tools/ext/main.rs similarity index 92% rename from ext/src/main.rs rename to tools/ext/main.rs index 621162c..7aa9eb1 100644 --- a/ext/src/main.rs +++ b/tools/ext/main.rs @@ -1,6 +1,6 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate logger; +extern crate pwasm_utils_tools as logger; use std::env; diff --git a/gas/src/main.rs b/tools/gas/main.rs similarity index 93% rename from gas/src/main.rs rename to tools/gas/main.rs index 86f5f56..c19bba4 100644 --- a/gas/src/main.rs +++ b/tools/gas/main.rs @@ -1,6 +1,6 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate logger; +extern crate pwasm_utils_tools as logger; use std::env; diff --git a/prune/src/main.rs b/tools/prune/main.rs similarity index 97% rename from prune/src/main.rs rename to tools/prune/main.rs index f7e5dd9..550efb3 100644 --- a/prune/src/main.rs +++ b/tools/prune/main.rs @@ -1,6 +1,6 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate logger; +extern crate pwasm_utils_tools as logger; extern crate clap; use clap::{App, Arg}; diff --git a/logger/src/lib.rs b/tools/src/lib.rs similarity index 100% rename from logger/src/lib.rs rename to tools/src/lib.rs diff --git a/stack_height/src/main.rs b/tools/stack_height/main.rs similarity index 94% rename from stack_height/src/main.rs rename to tools/stack_height/main.rs index 762b2ba..3d3e100 100644 --- a/stack_height/src/main.rs +++ b/tools/stack_height/main.rs @@ -1,6 +1,6 @@ extern crate pwasm_utils as utils; extern crate parity_wasm; -extern crate logger; +extern crate pwasm_utils_tools as logger; use std::env; use utils::stack_height; From c79681aa5b0e137f054c35a1c29af4dd6137e230 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 15 May 2018 19:17:59 +0800 Subject: [PATCH 6/8] Rename wasm-utils-tools to wasm-utils-cli --- tools/Cargo.toml | 2 +- tools/build/main.rs | 2 +- tools/ext/main.rs | 2 +- tools/gas/main.rs | 2 +- tools/prune/main.rs | 2 +- tools/stack_height/main.rs | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tools/Cargo.toml b/tools/Cargo.toml index 6f8c7bb..5fdbfab 100644 --- a/tools/Cargo.toml +++ b/tools/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "pwasm-utils-tools" +name = "pwasm-utils-cli" version = "0.1.5" authors = ["Nikolay Volf ", "Sergey Pepyakin "] license = "MIT/Apache-2.0" diff --git a/tools/build/main.rs b/tools/build/main.rs index 4a1461b..ee78c2a 100644 --- a/tools/build/main.rs +++ b/tools/build/main.rs @@ -4,7 +4,7 @@ extern crate glob; extern crate pwasm_utils as utils; extern crate clap; extern crate parity_wasm; -extern crate pwasm_utils_tools as logger; +extern crate pwasm_utils_cli as logger; mod source; diff --git a/tools/ext/main.rs b/tools/ext/main.rs index 7aa9eb1..02d8ba3 100644 --- a/tools/ext/main.rs +++ b/tools/ext/main.rs @@ -1,6 +1,6 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate pwasm_utils_tools as logger; +extern crate pwasm_utils_cli as logger; use std::env; diff --git a/tools/gas/main.rs b/tools/gas/main.rs index c19bba4..0e9139f 100644 --- a/tools/gas/main.rs +++ b/tools/gas/main.rs @@ -1,6 +1,6 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate pwasm_utils_tools as logger; +extern crate pwasm_utils_cli as logger; use std::env; diff --git a/tools/prune/main.rs b/tools/prune/main.rs index 550efb3..658e249 100644 --- a/tools/prune/main.rs +++ b/tools/prune/main.rs @@ -1,6 +1,6 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate pwasm_utils_tools as logger; +extern crate pwasm_utils_cli as logger; extern crate clap; use clap::{App, Arg}; diff --git a/tools/stack_height/main.rs b/tools/stack_height/main.rs index 3d3e100..774baee 100644 --- a/tools/stack_height/main.rs +++ b/tools/stack_height/main.rs @@ -1,6 +1,6 @@ extern crate pwasm_utils as utils; extern crate parity_wasm; -extern crate pwasm_utils_tools as logger; +extern crate pwasm_utils_cli as logger; use std::env; use utils::stack_height; From 245ac89f2d4fc7da2257051198d868ccb15c2754 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 15 May 2018 20:44:18 +0800 Subject: [PATCH 7/8] Rename folder tools to cli to keep it consistent with crate naming --- Cargo.toml | 2 +- {tools => cli}/Cargo.toml | 0 {tools => cli}/build/main.rs | 0 {tools => cli}/build/source.rs | 0 {tools => cli}/ext/main.rs | 0 {tools => cli}/gas/main.rs | 0 {tools => cli}/prune/main.rs | 0 {tools => cli}/src/lib.rs | 0 {tools => cli}/stack_height/main.rs | 0 9 files changed, 1 insertion(+), 1 deletion(-) rename {tools => cli}/Cargo.toml (100%) rename {tools => cli}/build/main.rs (100%) rename {tools => cli}/build/source.rs (100%) rename {tools => cli}/ext/main.rs (100%) rename {tools => cli}/gas/main.rs (100%) rename {tools => cli}/prune/main.rs (100%) rename {tools => cli}/src/lib.rs (100%) rename {tools => cli}/stack_height/main.rs (100%) diff --git a/Cargo.toml b/Cargo.toml index 21e8679..6e86495 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,5 +23,5 @@ std = ["parity-wasm/std", "log/std", "byteorder/std"] [workspace] members = [ - "./tools", + "./cli", ] diff --git a/tools/Cargo.toml b/cli/Cargo.toml similarity index 100% rename from tools/Cargo.toml rename to cli/Cargo.toml diff --git a/tools/build/main.rs b/cli/build/main.rs similarity index 100% rename from tools/build/main.rs rename to cli/build/main.rs diff --git a/tools/build/source.rs b/cli/build/source.rs similarity index 100% rename from tools/build/source.rs rename to cli/build/source.rs diff --git a/tools/ext/main.rs b/cli/ext/main.rs similarity index 100% rename from tools/ext/main.rs rename to cli/ext/main.rs diff --git a/tools/gas/main.rs b/cli/gas/main.rs similarity index 100% rename from tools/gas/main.rs rename to cli/gas/main.rs diff --git a/tools/prune/main.rs b/cli/prune/main.rs similarity index 100% rename from tools/prune/main.rs rename to cli/prune/main.rs diff --git a/tools/src/lib.rs b/cli/src/lib.rs similarity index 100% rename from tools/src/lib.rs rename to cli/src/lib.rs diff --git a/tools/stack_height/main.rs b/cli/stack_height/main.rs similarity index 100% rename from tools/stack_height/main.rs rename to cli/stack_height/main.rs From 867a6a185dd22115c69371317a871ffcbeb7c1cb Mon Sep 17 00:00:00 2001 From: Sergey Pepyakin Date: Tue, 15 May 2018 16:54:02 +0300 Subject: [PATCH 8/8] Use parity-wasm 0.30 instead of git --- Cargo.toml | 2 +- cli/Cargo.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6e86495..77847a5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ description = "Collection of command-line utilities and corresponding Rust api f keywords = ["wasm", "webassembly", "pwasm"] [dependencies] -parity-wasm = { git = "https://github.com/paritytech/parity-wasm", default-features = false } +parity-wasm = { version = "0.30", default-features = false } log = { version = "0.4", default-features = false } byteorder = { version = "1", default-features = false } diff --git a/cli/Cargo.toml b/cli/Cargo.toml index 5fdbfab..89ba7ee 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -30,7 +30,7 @@ name = "wasm-stack-height" path = "stack_height/main.rs" [dependencies] -parity-wasm = { git = "https://github.com/paritytech/parity-wasm" } +parity-wasm = "0.30" pwasm-utils = { path = ".." } glob = "0.2" clap = "2.24"