diff --git a/Cargo.toml b/Cargo.toml index b77aa0e..0346577 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,7 @@ [package] name = "pwasm-utils" version = "0.15.0" +edition = "2018" authors = ["Nikolay Volf ", "Sergey Pepyakin "] license = "MIT/Apache-2.0" readme = "README.md" @@ -8,6 +9,41 @@ description = "Collection of command-line utilities and corresponding Rust api f keywords = ["wasm", "webassembly", "pwasm"] repository = "https://github.com/paritytech/wasm-utils" +[[bin]] +name = "wasm-prune" +path = "cli/prune/main.rs" +required-features = ["cli"] + +[[bin]] +name = "wasm-ext" +path = "cli/ext/main.rs" +required-features = ["cli"] + +[[bin]] +name = "wasm-gas" +path = "cli/gas/main.rs" +required-features = ["cli"] + +[[bin]] +name = "wasm-build" +path = "cli/build/main.rs" +required-features = ["cli"] + +[[bin]] +name = "wasm-stack-height" +path = "cli/stack_height/main.rs" +required-features = ["cli"] + +[[bin]] +name = "wasm-pack" +path = "cli/pack/main.rs" +required-features = ["cli"] + +[[bin]] +name = "wasm-check" +path = "cli/check/main.rs" +required-features = ["cli"] + [dependencies] # If you add the feature "bulk", make sure you fixed all expects that say # "parity-wasm is compiled without bulk-memory operations" @@ -15,6 +51,12 @@ parity-wasm = { version = "0.41.0", default-features = false } log = { version = "0.4", default-features = false } byteorder = { version = "1", default-features = false } +# Dependencies only used by the binaries +glob = { version = "0.2", optional = true } +clap = { version = "2.24", optional = true } +env_logger = { version = "0.5", optional = true } +lazy_static = { version = "1.0", optional = true } + [dev-dependencies] tempdir = "0.3" wabt = "0.10" @@ -26,8 +68,9 @@ binaryen = "0.8" [features] default = ["std"] std = ["parity-wasm/std", "log/std", "byteorder/std"] - -[workspace] -members = [ - "./cli", +cli = [ + "glob", + "clap", + "env_logger", + "lazy_static", ] diff --git a/cli/Cargo.toml b/cli/Cargo.toml deleted file mode 100644 index 0aa1508..0000000 --- a/cli/Cargo.toml +++ /dev/null @@ -1,51 +0,0 @@ -[package] -name = "pwasm-utils-cli" -version = "0.15.0" -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"] -repository = "https://github.com/paritytech/wasm-utils" - -[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 = "build/main.rs" - -[[bin]] -name = "wasm-stack-height" -path = "stack_height/main.rs" - -[[bin]] -name = "wasm-pack" -path = "pack/main.rs" - -[[bin]] -name = "wasm-check" -path = "check/main.rs" - -[dependencies] -parity-wasm = "0.41.0" -pwasm-utils = { path = "..", version = "0.15" } -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/cli/README.md b/cli/README.md deleted file mode 100644 index 7604c69..0000000 --- a/cli/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# pwasm-utils-cli - -Collection of WASM utilities used in Parity and WASM contract devepment - -## Install - -Easiest way to use is to install via `cargo install`: - -``` -cargo install pwasm-utils-cli -``` diff --git a/cli/build/main.rs b/cli/build/main.rs index a03229a..f374d15 100644 --- a/cli/build/main.rs +++ b/cli/build/main.rs @@ -5,7 +5,7 @@ extern crate clap; extern crate glob; extern crate pwasm_utils as utils; extern crate parity_wasm; -extern crate pwasm_utils_cli as logger; +use pwasm_utils::logger; mod source; @@ -67,7 +67,7 @@ pub fn process_output(input: &source::SourceInput) -> Result<(), Error> { } fn do_main() -> Result<(), Error> { - logger::init_log(); + logger::init(); let matches = App::new("wasm-build") .version(crate_version!()) diff --git a/cli/check/main.rs b/cli/check/main.rs index d3d7a3b..7c95c7b 100644 --- a/cli/check/main.rs +++ b/cli/check/main.rs @@ -1,6 +1,6 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate pwasm_utils_cli as logger; +use pwasm_utils::logger; extern crate clap; use clap::{App, Arg}; @@ -40,7 +40,7 @@ const ALLOWED_IMPORTS: &[&str] = &[ ]; fn main() { - logger::init_log(); + logger::init(); let matches = App::new("wasm-check") .arg(Arg::with_name("input") diff --git a/cli/ext/main.rs b/cli/ext/main.rs index 02d8ba3..aabb13c 100644 --- a/cli/ext/main.rs +++ b/cli/ext/main.rs @@ -1,12 +1,12 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate pwasm_utils_cli as logger; +use pwasm_utils::logger; use std::env; fn main() { - logger::init_log(); + logger::init(); let args = env::args().collect::>(); if args.len() != 3 { diff --git a/cli/gas/main.rs b/cli/gas/main.rs index 6eec5b6..6ec45ee 100644 --- a/cli/gas/main.rs +++ b/cli/gas/main.rs @@ -1,11 +1,11 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate pwasm_utils_cli as logger; +use pwasm_utils::logger; use std::env; fn main() { - logger::init_log(); + logger::init(); let args = env::args().collect::>(); if args.len() != 3 { diff --git a/cli/pack/main.rs b/cli/pack/main.rs index 5f163e2..f96219b 100644 --- a/cli/pack/main.rs +++ b/cli/pack/main.rs @@ -1,12 +1,12 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate pwasm_utils_cli as logger; +use pwasm_utils::logger; extern crate clap; use clap::{App, Arg}; fn main() { - logger::init_log(); + logger::init(); let target_runtime = utils::TargetRuntime::pwasm(); diff --git a/cli/prune/main.rs b/cli/prune/main.rs index c23ba58..d4fcd41 100644 --- a/cli/prune/main.rs +++ b/cli/prune/main.rs @@ -1,12 +1,12 @@ extern crate parity_wasm; extern crate pwasm_utils as utils; -extern crate pwasm_utils_cli as logger; +use pwasm_utils::logger; extern crate clap; use clap::{App, Arg}; fn main() { - logger::init_log(); + logger::init(); let target_runtime = utils::TargetRuntime::pwasm(); diff --git a/cli/stack_height/main.rs b/cli/stack_height/main.rs index 774baee..1b6842a 100644 --- a/cli/stack_height/main.rs +++ b/cli/stack_height/main.rs @@ -1,12 +1,12 @@ extern crate pwasm_utils as utils; extern crate parity_wasm; -extern crate pwasm_utils_cli as logger; +use pwasm_utils::logger; use std::env; use utils::stack_height; fn main() { - logger::init_log(); + logger::init(); let args = env::args().collect::>(); if args.len() != 3 { diff --git a/src/build.rs b/src/build.rs index e79b72d..5370563 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1,4 +1,3 @@ -use std; use super::{ optimize, pack_instance, @@ -10,7 +9,6 @@ use super::{ OptimizerError, TargetRuntime, }; -use parity_wasm; use parity_wasm::elements; #[derive(Debug)] diff --git a/src/ext.rs b/src/ext.rs index 5dc1489..11c5f18 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -3,9 +3,10 @@ use std::vec::Vec; use std::borrow::ToOwned; use parity_wasm::{elements, builder}; -use optimizer::{import_section, export_section}; use byteorder::{LittleEndian, ByteOrder}; +use crate::optimizer::{import_section, export_section}; + type Insertion = (usize, u32, u32, String); pub fn update_call_index(instructions: &mut elements::Instructions, original_imports: usize, inserts: &[Insertion]) { diff --git a/src/gas/mod.rs b/src/gas/mod.rs index 779029c..860b1c3 100644 --- a/src/gas/mod.rs +++ b/src/gas/mod.rs @@ -12,7 +12,7 @@ use std::mem; use std::vec::Vec; use parity_wasm::{elements, builder}; -use rules::Rules; +use crate::rules::Rules; pub fn update_call_index(instructions: &mut elements::Instructions, inserted_index: u32) { use parity_wasm::elements::Instruction::*; @@ -518,7 +518,7 @@ mod tests { use parity_wasm::{serialize, builder, elements}; use parity_wasm::elements::Instruction::*; use super::*; - use rules; + use crate::rules; pub fn get_function_body(module: &elements::Module, index: usize) -> Option<&[elements::Instruction]> diff --git a/src/gas/validation.rs b/src/gas/validation.rs index d0b1c22..604906c 100644 --- a/src/gas/validation.rs +++ b/src/gas/validation.rs @@ -9,8 +9,8 @@ //! the worst case. use super::MeteredBlock; -use rules::Set as RuleSet; -use rules::Rules; +use crate::rules::Set as RuleSet; +use crate::rules::Rules; use parity_wasm::elements::{FuncBody, Instruction}; use std::collections::HashMap; diff --git a/src/lib.rs b/src/lib.rs index feae73d..081d99f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,6 +25,8 @@ mod ref_list; mod symbols; #[cfg(feature = "std")] mod export_globals; +#[cfg(feature = "cli")] +pub mod logger; pub mod stack_height; diff --git a/cli/src/lib.rs b/src/logger.rs similarity index 76% rename from cli/src/lib.rs rename to src/logger.rs index eeaabb0..222ad50 100644 --- a/cli/src/lib.rs +++ b/src/logger.rs @@ -1,10 +1,7 @@ -#[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; +use lazy_static::lazy_static; lazy_static! { static ref LOG_DUMMY: bool = { @@ -22,6 +19,6 @@ lazy_static! { } /// Intialize log with default settings -pub fn init_log() { +pub fn init() { let _ = *LOG_DUMMY; } diff --git a/src/optimizer.rs b/src/optimizer.rs index 1497544..a123cd6 100644 --- a/src/optimizer.rs +++ b/src/optimizer.rs @@ -7,7 +7,7 @@ use std::mem; use parity_wasm::elements; -use symbols::{Symbol, expand_symbols, push_code_symbols, resolve_function}; +use crate::symbols::{Symbol, expand_symbols, push_code_symbols, resolve_function}; #[derive(Debug)] pub enum Error {