From bb47c22618c6b9467f5731bef026e391dc808cd4 Mon Sep 17 00:00:00 2001 From: Wei Tang Date: Tue, 15 May 2018 08:05:00 +0800 Subject: [PATCH] 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 {