mirror of
https://github.com/fluencelabs/wasm-utils
synced 2025-03-31 02:11:03 +00:00
build tools continued
This commit is contained in:
parent
0c52bcde1d
commit
71910405bc
@ -4,7 +4,7 @@ extern crate glob;
|
|||||||
extern crate wasm_utils;
|
extern crate wasm_utils;
|
||||||
extern crate clap;
|
extern crate clap;
|
||||||
|
|
||||||
use std::{env, fs, io};
|
use std::{fs, io};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::{App, Arg};
|
use clap::{App, Arg};
|
||||||
@ -23,13 +23,11 @@ impl From<io::Error> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn process_output(bin_name: &str) -> Result<(), Error> {
|
pub fn process_output(target_dir: &str, bin_name: &str) -> Result<(), Error> {
|
||||||
let out_dir = env::var("OUT_DIR").map_err(|_| Error::NoEnvVar)?;
|
let mut path = PathBuf::from(target_dir);
|
||||||
let mut path = PathBuf::from(out_dir.clone());
|
|
||||||
let wasm_name = bin_name.to_string().replace("-", "_");
|
let wasm_name = bin_name.to_string().replace("-", "_");
|
||||||
path.push("..");
|
path.push("wasm32-unknown-emscripten");
|
||||||
path.push("..");
|
path.push("release");
|
||||||
path.push("..");
|
|
||||||
path.push("deps");
|
path.push("deps");
|
||||||
path.push(format!("{}-*.wasm", wasm_name));
|
path.push(format!("{}-*.wasm", wasm_name));
|
||||||
|
|
||||||
@ -45,7 +43,7 @@ pub fn process_output(bin_name: &str) -> Result<(), Error> {
|
|||||||
))
|
))
|
||||||
} else {
|
} else {
|
||||||
let file = files.drain(..).nth(0).expect("0th element exists").expect("glob err");
|
let file = files.drain(..).nth(0).expect("0th element exists").expect("glob err");
|
||||||
let mut path = PathBuf::from(out_dir.clone());
|
let mut path = PathBuf::from(target_dir);
|
||||||
path.push(format!("{}.wasm", bin_name));
|
path.push(format!("{}.wasm", bin_name));
|
||||||
fs::copy(file, path)?;
|
fs::copy(file, path)?;
|
||||||
}
|
}
|
||||||
@ -57,22 +55,18 @@ fn main() {
|
|||||||
wasm_utils::init_log();
|
wasm_utils::init_log();
|
||||||
|
|
||||||
let matches = App::new("wasm-opt")
|
let matches = App::new("wasm-opt")
|
||||||
.arg(Arg::with_name("input")
|
.arg(Arg::with_name("target")
|
||||||
.index(1)
|
.index(1)
|
||||||
.required(true)
|
.required(true)
|
||||||
.help("Input WASM file"))
|
.help("Cargo target directory"))
|
||||||
.arg(Arg::with_name("output")
|
.arg(Arg::with_name("wasm")
|
||||||
.index(2)
|
.index(2)
|
||||||
.required(true)
|
.required(true)
|
||||||
.help("Output WASM file"))
|
.help("Wasm binary name"))
|
||||||
.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();
|
.get_matches();
|
||||||
|
|
||||||
|
let target_dir = matches.value_of("target").expect("is required; qed");
|
||||||
|
let wasm_binary = matches.value_of("wasm").expect("is required; qed");
|
||||||
|
|
||||||
|
process_output(target_dir, wasm_binary).expect("Failed to process cargo target directory");
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user