mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-16 03:20:50 +00:00
to executable
This commit is contained in:
parent
cac0501eec
commit
0c52bcde1d
@ -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"
|
||||
path = "pack/src/main.rs"
|
||||
|
||||
[[bin]]
|
||||
name = "wasm-build"
|
||||
path = "build/src/main.rs"
|
@ -4,4 +4,9 @@ version = "0.1.0"
|
||||
authors = ["NikVolf <nikvolf@gmail.com>"]
|
||||
|
||||
[dependencies]
|
||||
glob = "*"
|
||||
glob = "0.2"
|
||||
wasm-utils = { path = "../" }
|
||||
clap = "2.24"
|
||||
|
||||
[[bin]]
|
||||
name = "wasm-build"
|
@ -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<io::Error> 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::<Vec<Result<PathBuf, glob::GlobError>>>();
|
||||
@ -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();
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user