mirror of
https://github.com/fluencelabs/marine.git
synced 2025-03-30 21:01:02 +00:00
add embed option to fce-cli
This commit is contained in:
parent
daa25d1021
commit
94675d8e8f
@ -44,14 +44,14 @@ jobs:
|
|||||||
- checkout
|
- checkout
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
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: |
|
- run: |
|
||||||
rustup toolchain install nightly
|
rustup toolchain install nightly
|
||||||
rustup component add rustfmt
|
rustup component add rustfmt
|
||||||
rustup component add clippy
|
rustup component add clippy
|
||||||
cargo install cargo-wasi
|
cargo install cargo-wasi
|
||||||
|
|
||||||
cd examples/ipfs_node/effector
|
cd examples/ipfs-node/effector
|
||||||
cargo fmt --all -- --check --color always
|
cargo fmt --all -- --check --color always
|
||||||
cargo wasi build
|
cargo wasi build
|
||||||
cargo clippy -v --target wasm32-wasi
|
cargo clippy -v --target wasm32-wasi
|
||||||
|
@ -21,18 +21,41 @@ pub const AUTHORS: &str = env!("CARGO_PKG_AUTHORS");
|
|||||||
pub const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
|
pub const DESCRIPTION: &str = env!("CARGO_PKG_DESCRIPTION");
|
||||||
|
|
||||||
pub const IN_WASM_PATH: &str = "in-wasm-path";
|
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> {
|
pub fn build<'a, 'b>() -> App<'a, 'b> {
|
||||||
SubCommand::with_name("build")
|
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::TrailingVarArg)
|
||||||
.setting(clap::AppSettings::AllowLeadingHyphen)
|
.setting(clap::AppSettings::AllowLeadingHyphen)
|
||||||
.arg(Arg::from_usage("[optional]... 'cargo build arguments'").multiple(true))
|
.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> {
|
pub fn show_wit<'a, 'b>() -> App<'a, 'b> {
|
||||||
SubCommand::with_name("show")
|
SubCommand::with_name("show")
|
||||||
.about("show WIT in provided Wasm file")
|
.about("Show WIT in provided Wasm file")
|
||||||
.setting(clap::AppSettings::ArgRequiredElseHelp)
|
.setting(clap::AppSettings::ArgRequiredElseHelp)
|
||||||
.args(&[Arg::with_name(IN_WASM_PATH)
|
.args(&[Arg::with_name(IN_WASM_PATH)
|
||||||
.required(true)
|
.required(true)
|
||||||
|
@ -32,12 +32,12 @@ mod errors;
|
|||||||
pub(crate) type Result<T> = std::result::Result<T, crate::errors::CLIError>;
|
pub(crate) type Result<T> = std::result::Result<T, crate::errors::CLIError>;
|
||||||
|
|
||||||
pub fn main() -> std::result::Result<(), anyhow::Error> {
|
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)
|
.version(args::VERSION)
|
||||||
.author(args::AUTHORS)
|
.author(args::AUTHORS)
|
||||||
.about(args::DESCRIPTION)
|
|
||||||
.setting(clap::AppSettings::ArgRequiredElseHelp)
|
.setting(clap::AppSettings::ArgRequiredElseHelp)
|
||||||
.subcommand(args::build())
|
.subcommand(args::build())
|
||||||
|
.subcommand(args::embed_wit())
|
||||||
.subcommand(args::show_wit());
|
.subcommand(args::show_wit());
|
||||||
let arg_matches = app.get_matches();
|
let arg_matches = app.get_matches();
|
||||||
|
|
||||||
@ -49,6 +49,24 @@ pub fn main() -> std::result::Result<(), anyhow::Error> {
|
|||||||
|
|
||||||
Ok(())
|
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)) => {
|
("show", Some(arg)) => {
|
||||||
let wasm_path = arg.value_of(args::IN_WASM_PATH).unwrap();
|
let wasm_path = arg.value_of(args::IN_WASM_PATH).unwrap();
|
||||||
let wasm_path = std::path::PathBuf::from(wasm_path);
|
let wasm_path = std::path::PathBuf::from(wasm_path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user