From 0c52bcde1d6489220f217d0f8d6efd6c8410cb89 Mon Sep 17 00:00:00 2001 From: NikVolf Date: Wed, 9 Aug 2017 13:45:35 +0300 Subject: [PATCH] to executable --- Cargo.toml | 8 +++++-- build/Cargo.toml | 7 +++++- build/src/{lib.rs => main.rs} | 42 +++++++++++++++++++++++++++++++---- 3 files changed, 50 insertions(+), 7 deletions(-) rename build/src/{lib.rs => main.rs} (51%) diff --git a/Cargo.toml b/Cargo.toml index ea0aa50..710d2fa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,7 +9,7 @@ log = "0.3" env_logger = "0.4" lazy_static = "0.2" clap = "2.24" -wasm-build = { path = "build" } +glob = "0.2" [lib] @@ -27,4 +27,8 @@ path = "gas/src/main.rs" [[bin]] name = "wasm-pack" -path = "pack/src/main.rs" \ No newline at end of file +path = "pack/src/main.rs" + +[[bin]] +name = "wasm-build" +path = "build/src/main.rs" \ No newline at end of file diff --git a/build/Cargo.toml b/build/Cargo.toml index 5eba5e9..b97b031 100644 --- a/build/Cargo.toml +++ b/build/Cargo.toml @@ -4,4 +4,9 @@ version = "0.1.0" authors = ["NikVolf "] [dependencies] -glob = "*" \ No newline at end of file +glob = "0.2" +wasm-utils = { path = "../" } +clap = "2.24" + +[[bin]] +name = "wasm-build" \ No newline at end of file diff --git a/build/src/lib.rs b/build/src/main.rs similarity index 51% rename from build/src/lib.rs rename to build/src/main.rs index 464c6cd..e4d12c7 100644 --- a/build/src/lib.rs +++ b/build/src/main.rs @@ -1,10 +1,14 @@ -//! Tools library for building contracts via cargo +//! Experimental build tool for cargo extern crate glob; +extern crate wasm_utils; +extern crate clap; use std::{env, fs, io}; use std::path::PathBuf; +use clap::{App, Arg}; + #[derive(Debug)] pub enum Error { Io(io::Error), @@ -20,10 +24,14 @@ impl From for Error { } pub fn process_output(bin_name: &str) -> Result<(), Error> { - let out_dir = env::var("OUT").map_err(|_| Error::NoEnvVar)?; + let out_dir = env::var("OUT_DIR").map_err(|_| Error::NoEnvVar)?; let mut path = PathBuf::from(out_dir.clone()); + let wasm_name = bin_name.to_string().replace("-", "_"); + path.push(".."); + path.push(".."); + path.push(".."); path.push("deps"); - path.push(format!("{}-*.wasm", bin_name)); + path.push(format!("{}-*.wasm", wasm_name)); let mut files = glob::glob(path.to_string_lossy().as_ref()).expect("glob err") .collect::>>(); @@ -37,8 +45,34 @@ pub fn process_output(bin_name: &str) -> Result<(), Error> { )) } else { let file = files.drain(..).nth(0).expect("0th element exists").expect("glob err"); - fs::copy(file, out_dir)?; + let mut path = PathBuf::from(out_dir.clone()); + path.push(format!("{}.wasm", bin_name)); + fs::copy(file, path)?; } Ok(()) +} + +fn main() { + wasm_utils::init_log(); + + let matches = App::new("wasm-opt") + .arg(Arg::with_name("input") + .index(1) + .required(true) + .help("Input WASM file")) + .arg(Arg::with_name("output") + .index(2) + .required(true) + .help("Output WASM file")) + .arg(Arg::with_name("exports") + .long("exports") + .short("e") + .takes_value(true) + .value_name("functions") + .help("Comma-separated list of exported functions to keep. Default: _call")) + .get_matches(); + + + } \ No newline at end of file