add embed option to fce-cli

This commit is contained in:
vms 2020-08-08 23:29:16 +03:00
parent daa25d1021
commit 94675d8e8f
3 changed files with 47 additions and 6 deletions

View File

@ -44,14 +44,14 @@ jobs:
- checkout
- restore_cache:
keys:
- examples01-{{ checksum "examples/ipfs_node/effector/Cargo.toml" }}-{{ checksum "examples/ipfs_node/pure/Cargo.toml" }}
- examples01-{{ checksum "examples/ipfs-node/effector/Cargo.toml" }}-{{ checksum "examples/ipfs-node/pure/Cargo.toml" }}
- run: |
rustup toolchain install nightly
rustup component add rustfmt
rustup component add clippy
cargo install cargo-wasi
cd examples/ipfs_node/effector
cd examples/ipfs-node/effector
cargo fmt --all -- --check --color always
cargo wasi build
cargo clippy -v --target wasm32-wasi

View File

@ -21,18 +21,41 @@ pub const AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
pub const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
pub const IN_WASM_PATH: &str = "in-wasm-path";
pub const WIT_PATH: &str = "wit-path";
pub const OUT_WASM_PATH: &str = "out-wasm-path";
pub fn build<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("build")
.about("build provided Rust project to Wasm")
.about("Build provided Rust project to Wasm")
.setting(clap::AppSettings::TrailingVarArg)
.setting(clap::AppSettings::AllowLeadingHyphen)
.arg(Arg::from_usage("[optional]... 'cargo build arguments'").multiple(true))
}
pub fn embed_wit<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("embed")
.about("Embed WIT to a provided Wasm file")
.args(&[
Arg::with_name(IN_WASM_PATH)
.required(true)
.takes_value(true)
.short("i")
.help("path to the wasm file"),
Arg::with_name(WIT_PATH)
.required(true)
.takes_value(true)
.short("w")
.help("path to file with WIT"),
Arg::with_name(OUT_WASM_PATH)
.takes_value(true)
.short("o")
.help("path to result file with embedded WIT"),
])
}
pub fn show_wit<'a, 'b>() -> App<'a, 'b> {
SubCommand::with_name("show")
.about("show WIT in provided Wasm file")
.about("Show WIT in provided Wasm file")
.setting(clap::AppSettings::ArgRequiredElseHelp)
.args(&[Arg::with_name(IN_WASM_PATH)
.required(true)

View File

@ -32,12 +32,12 @@ mod errors;
pub(crate) type Result<T> = std::result::Result<T, crate::errors::CLIError>;
pub fn main() -> std::result::Result<(), anyhow::Error> {
let app = clap::App::new("CLI tool for dealing with Wasm modules for the Fluence network")
let app = clap::App::new(args::DESCRIPTION)
.version(args::VERSION)
.author(args::AUTHORS)
.about(args::DESCRIPTION)
.setting(clap::AppSettings::ArgRequiredElseHelp)
.subcommand(args::build())
.subcommand(args::embed_wit())
.subcommand(args::show_wit());
let arg_matches = app.get_matches();
@ -49,6 +49,24 @@ pub fn main() -> std::result::Result<(), anyhow::Error> {
Ok(())
}
("embed", Some(arg)) => {
let in_wasm_path = arg.value_of(args::IN_WASM_PATH).unwrap();
let wit_path = arg.value_of(args::WIT_PATH).unwrap();
let out_wasm_path = match arg.value_of(args::OUT_WASM_PATH) {
Some(path) => path,
None => in_wasm_path,
};
let wit = String::from_utf8(std::fs::read(wit_path)?).unwrap();
fce_wit_parser::embed_text_wit(
std::path::PathBuf::from(in_wasm_path),
std::path::PathBuf::from(out_wasm_path),
&wit,
)?;
Ok(())
}
("show", Some(arg)) => {
let wasm_path = arg.value_of(args::IN_WASM_PATH).unwrap();
let wasm_path = std::path::PathBuf::from(wasm_path);