From 8575fe1b27a6eb696c99eae2c6eb8a3a00deb728 Mon Sep 17 00:00:00 2001 From: Wolfgang Silbermayr Date: Tue, 17 May 2022 08:35:57 +0200 Subject: [PATCH] Migrate to clap from structopt --- Cargo.lock | 98 ++++++++++++++++------- lib/cli-compiler/Cargo.toml | 2 +- lib/cli-compiler/src/cli.rs | 22 ++--- lib/cli-compiler/src/commands/compile.rs | 17 ++-- lib/cli-compiler/src/commands/config.rs | 18 ++--- lib/cli-compiler/src/commands/validate.rs | 8 +- lib/cli-compiler/src/common.rs | 16 ++-- lib/cli-compiler/src/store.rs | 20 ++--- lib/cli/Cargo.toml | 3 +- lib/cli/src/cli.rs | 39 ++++----- lib/cli/src/commands/binfmt.rs | 10 +-- lib/cli/src/commands/cache.rs | 8 +- lib/cli/src/commands/compile.rs | 19 +++-- lib/cli/src/commands/config.rs | 18 ++--- lib/cli/src/commands/create_exe.rs | 22 +++-- lib/cli/src/commands/inspect.rs | 8 +- lib/cli/src/commands/run.rs | 26 +++--- lib/cli/src/commands/run/wasi.rs | 31 ++++--- lib/cli/src/commands/self_update.rs | 4 +- lib/cli/src/commands/validate.rs | 8 +- lib/cli/src/commands/wast.rs | 10 +-- lib/cli/src/common.rs | 16 ++-- lib/cli/src/compilers/llvm.rs | 8 +- lib/cli/src/store.rs | 32 ++++---- lib/compiler/Cargo.toml | 2 +- 25 files changed, 264 insertions(+), 201 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 1a11542bcb9..e4baa0fcf0c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -149,7 +149,7 @@ dependencies = [ "bitflags", "cexpr", "clang-sys", - "clap", + "clap 2.34.0", "env_logger", "lazy_static", "lazycell", @@ -267,8 +267,8 @@ version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "38728c31b994e4b849cf59feefb4a8bf26acd299ee0b92c9fb35bd14ad4b8dfa" dependencies = [ - "clap", - "heck", + "clap 2.34.0", + "heck 0.3.3", "indexmap", "log", "proc-macro2", @@ -327,12 +327,51 @@ dependencies = [ "ansi_term", "atty", "bitflags", - "strsim", - "textwrap", + "strsim 0.8.0", + "textwrap 0.11.0", "unicode-width", "vec_map", ] +[[package]] +name = "clap" +version = "3.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2dbdf4bdacb33466e854ce889eee8dfd5729abf7ccd7664d0a2d60cd384440b" +dependencies = [ + "atty", + "bitflags", + "clap_derive", + "clap_lex", + "indexmap", + "lazy_static", + "strsim 0.10.0", + "termcolor", + "textwrap 0.15.0", +] + +[[package]] +name = "clap_derive" +version = "3.1.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25320346e922cffe59c0bbc5410c8d8784509efb321488971081313cb1e1a33c" +dependencies = [ + "heck 0.4.0", + "proc-macro-error", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "clap_lex" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a37c35f1112dad5e6e0b1adaff798507497a18fceeb30cceb3bae7d1427b9213" +dependencies = [ + "os_str_bytes", +] + [[package]] name = "cmake" version = "0.1.48" @@ -510,7 +549,7 @@ checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" dependencies = [ "atty", "cast", - "clap", + "clap 2.34.0", "criterion-plot", "csv", "itertools", @@ -1039,6 +1078,12 @@ dependencies = [ "unicode-segmentation", ] +[[package]] +name = "heck" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2540771e65fc8cb83cd6e8a237f70c319bd5c29f78ed1084ba5d50eeac86f7f9" + [[package]] name = "hermit-abi" version = "0.1.19" @@ -1445,6 +1490,12 @@ dependencies = [ "web-sys", ] +[[package]] +name = "os_str_bytes" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "029d8d0b2f198229de29dca79676f2738ff952edf3fde542eb8bf94d8c21b435" + [[package]] name = "output_vt100" version = "0.1.3" @@ -2196,28 +2247,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" [[package]] -name = "structopt" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" -dependencies = [ - "clap", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" +name = "strsim" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck", - "proc-macro-error", - "proc-macro2", - "quote", - "syn", -] +checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" [[package]] name = "subtle" @@ -2329,6 +2362,12 @@ dependencies = [ "unicode-width", ] +[[package]] +name = "textwrap" +version = "0.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb" + [[package]] name = "thiserror" version = "1.0.31" @@ -2834,11 +2873,12 @@ dependencies = [ "atty", "bytesize", "cfg-if 1.0.0", + "clap 3.1.18", "colored 2.0.0", "distance", "fern", "log", - "structopt", + "target-lexicon 0.12.4", "tempfile", "unix_mode", "wasmer", @@ -2884,11 +2924,11 @@ dependencies = [ "atty", "bytesize", "cfg-if 1.0.0", + "clap 3.1.18", "colored 2.0.0", "distance", "fern", "log", - "structopt", "tempfile", "unix_mode", "wasmer-compiler", diff --git a/lib/cli-compiler/Cargo.toml b/lib/cli-compiler/Cargo.toml index e887ac55df8..71743f905b8 100644 --- a/lib/cli-compiler/Cargo.toml +++ b/lib/cli-compiler/Cargo.toml @@ -24,7 +24,7 @@ wasmer-types = { version = "=2.3.0", path = "../types" } atty = "0.2" colored = "2.0" anyhow = "1.0" -structopt = { version = "0.3", features = ["suggestions"] } +clap = { version = "3.1", features = ["derive"] } # For the function names autosuggestion distance = "0.4" # For the inspect subcommand diff --git a/lib/cli-compiler/src/cli.rs b/lib/cli-compiler/src/cli.rs index 177edea1c93..dde3493f939 100644 --- a/lib/cli-compiler/src/cli.rs +++ b/lib/cli-compiler/src/cli.rs @@ -5,10 +5,10 @@ use crate::commands::{Config, Validate}; use crate::error::PrettyError; use anyhow::Result; -use structopt::{clap::ErrorKind, StructOpt}; +use clap::{ErrorKind, Parser}; -#[derive(StructOpt)] -#[structopt( +#[derive(Parser)] +#[clap( name = "wasmer-compiler", about = "WebAssembly standalone Compiler.", author @@ -16,16 +16,16 @@ use structopt::{clap::ErrorKind, StructOpt}; /// The options for the wasmer Command Line Interface enum WasmerCLIOptions { /// Validate a WebAssembly binary - #[structopt(name = "validate")] + #[clap(name = "validate")] Validate(Validate), /// Compile a WebAssembly binary - #[structopt(name = "compile")] + #[clap(name = "compile")] Compile(Compile), /// Get various configuration information needed /// to compile programs which use Wasmer - #[structopt(name = "config")] + #[clap(name = "config")] Config(Config), } @@ -56,15 +56,15 @@ pub fn wasmer_main() { let command = args.get(1); let options = { match command.unwrap_or(&"".to_string()).as_ref() { - "compile" | "config" | "help" | "inspect" | "validate" => WasmerCLIOptions::from_args(), + "compile" | "config" | "help" | "inspect" | "validate" => WasmerCLIOptions::parse(), _ => { - WasmerCLIOptions::from_iter_safe(args.iter()).unwrap_or_else(|e| { - match e.kind { + WasmerCLIOptions::try_parse_from(args.iter()).unwrap_or_else(|e| { + match e.kind() { // This fixes a issue that: // 1. Shows the version twice when doing `wasmer -V` // 2. Shows the run help (instead of normal help) when doing `wasmer --help` - ErrorKind::VersionDisplayed | ErrorKind::HelpDisplayed => e.exit(), - _ => WasmerCLIOptions::Compile(Compile::from_args()), + ErrorKind::DisplayVersion | ErrorKind::DisplayHelp => e.exit(), + _ => WasmerCLIOptions::Compile(Compile::parse()), } }) } diff --git a/lib/cli-compiler/src/commands/compile.rs b/lib/cli-compiler/src/commands/compile.rs index b6570b51a25..f3c62855d7e 100644 --- a/lib/cli-compiler/src/commands/compile.rs +++ b/lib/cli-compiler/src/commands/compile.rs @@ -1,32 +1,35 @@ use crate::store::{EngineType, StoreOptions}; use crate::warning; use anyhow::{Context, Result}; +use clap::Parser; use std::path::{Path, PathBuf}; -use structopt::StructOpt; use wasmer_compiler::{CompileError, CpuFeature, ModuleEnvironment, Target, Triple}; use wasmer_engine_universal_artifact::{ArtifactCreate, UniversalArtifactBuild}; use wasmer_types::entity::PrimaryMap; use wasmer_types::{MemoryIndex, MemoryStyle, TableIndex, TableStyle}; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer compile` subcommand pub struct Compile { /// Input file - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, /// Output file - #[structopt(name = "OUTPUT PATH", short = "o", parse(from_os_str))] + #[clap(name = "OUTPUT PATH", short = 'o', parse(from_os_str))] output: PathBuf, /// Compilation Target triple - #[structopt(long = "target")] + #[clap(long = "target")] target_triple: Option, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, - #[structopt(short = "m", multiple = true, number_of_values = 1)] + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure + #[clap(short = 'm', multiple_occurrences = true, number_of_values = 1)] cpu_features: Vec, } diff --git a/lib/cli-compiler/src/commands/config.rs b/lib/cli-compiler/src/commands/config.rs index 0ded2bf4540..2137f6e0caa 100644 --- a/lib/cli-compiler/src/commands/config.rs +++ b/lib/cli-compiler/src/commands/config.rs @@ -1,39 +1,39 @@ use crate::VERSION; use anyhow::{Context, Result}; +use clap::Parser; use std::env; use std::path::PathBuf; -use structopt::StructOpt; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer config` subcommand pub struct Config { /// Print the installation prefix. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] prefix: bool, /// Directory containing Wasmer executables. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] bindir: bool, /// Directory containing Wasmer headers. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] includedir: bool, /// Directory containing Wasmer libraries. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] libdir: bool, /// Libraries needed to link against Wasmer components. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] libs: bool, /// C compiler flags for files that include Wasmer headers. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] cflags: bool, /// It outputs the necessary details for compiling /// and linking a program to Wasmer, using the `pkg-config` format. - #[structopt(long)] + #[clap(long)] pkg_config: bool, } diff --git a/lib/cli-compiler/src/commands/validate.rs b/lib/cli-compiler/src/commands/validate.rs index 497912f3ef6..d3061dba61d 100644 --- a/lib/cli-compiler/src/commands/validate.rs +++ b/lib/cli-compiler/src/commands/validate.rs @@ -1,19 +1,19 @@ use crate::store::StoreOptions; use anyhow::{bail, Context, Result}; +use clap::Parser; use std::path::PathBuf; use std::str::FromStr; -use structopt::StructOpt; use wasmer_compiler::{CpuFeature, Target, Triple}; use wasmer_types::is_wasm; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer validate` subcommand pub struct Validate { /// File to validate as WebAssembly - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, } diff --git a/lib/cli-compiler/src/common.rs b/lib/cli-compiler/src/common.rs index 863e154103f..81af03197cd 100644 --- a/lib/cli-compiler/src/common.rs +++ b/lib/cli-compiler/src/common.rs @@ -1,36 +1,36 @@ //! Common module with common used structures across different //! commands. use crate::VERSION; +use clap::Parser; use std::env; use std::path::PathBuf; -use structopt::StructOpt; -#[derive(Debug, StructOpt, Clone, Default)] +#[derive(Debug, Parser, Clone, Default)] /// The WebAssembly features that can be passed through the /// Command Line args. pub struct WasmFeatures { /// Enable support for the SIMD proposal. - #[structopt(long = "enable-simd")] + #[clap(long = "enable-simd")] pub simd: bool, /// Enable support for the threads proposal. - #[structopt(long = "enable-threads")] + #[clap(long = "enable-threads")] pub threads: bool, /// Enable support for the reference types proposal. - #[structopt(long = "enable-reference-types")] + #[clap(long = "enable-reference-types")] pub reference_types: bool, /// Enable support for the multi value proposal. - #[structopt(long = "enable-multi-value")] + #[clap(long = "enable-multi-value")] pub multi_value: bool, /// Enable support for the bulk memory proposal. - #[structopt(long = "enable-bulk-memory")] + #[clap(long = "enable-bulk-memory")] pub bulk_memory: bool, /// Enable support for all pre-standard proposals. - #[structopt(long = "enable-all")] + #[clap(long = "enable-all")] pub all: bool, } diff --git a/lib/cli-compiler/src/store.rs b/lib/cli-compiler/src/store.rs index 16f8691ca7c..2576a8721d1 100644 --- a/lib/cli-compiler/src/store.rs +++ b/lib/cli-compiler/src/store.rs @@ -3,10 +3,10 @@ use crate::common::WasmFeatures; use anyhow::Result; +use clap::Parser; use std::string::ToString; #[allow(unused_imports)] use std::sync::Arc; -use structopt::StructOpt; use wasmer_compiler::{CompilerConfig, Features, PointerWidth, Target}; use wasmer_engine_universal_artifact::UniversalEngineBuilder; use wasmer_types::{MemoryStyle, MemoryType, Pages, TableStyle, TableType}; @@ -84,39 +84,39 @@ impl SubsetTunables { } } -#[derive(Debug, Clone, StructOpt, Default)] +#[derive(Debug, Clone, Parser, Default)] /// The compiler and engine options pub struct StoreOptions { - #[structopt(flatten)] + #[clap(flatten)] compiler: CompilerOptions, } -#[derive(Debug, Clone, StructOpt, Default)] +#[derive(Debug, Clone, Parser, Default)] /// The compiler options pub struct CompilerOptions { /// Use Singlepass compiler. - #[structopt(long, conflicts_with_all = &["cranelift", "llvm"])] + #[clap(long, conflicts_with_all = &["cranelift", "llvm"])] singlepass: bool, /// Use Cranelift compiler. - #[structopt(long, conflicts_with_all = &["singlepass", "llvm"])] + #[clap(long, conflicts_with_all = &["singlepass", "llvm"])] cranelift: bool, /// Use LLVM compiler. - #[structopt(long, conflicts_with_all = &["singlepass", "cranelift"])] + #[clap(long, conflicts_with_all = &["singlepass", "cranelift"])] llvm: bool, /// Enable compiler internal verification. - #[structopt(long)] + #[clap(long)] #[allow(dead_code)] enable_verifier: bool, /// LLVM debug directory, where IR and object files will be written to. #[cfg(feature = "llvm")] - #[structopt(long, parse(from_os_str))] + #[clap(long, parse(from_os_str))] llvm_debug_dir: Option, - #[structopt(flatten)] + #[clap(flatten)] features: WasmFeatures, } diff --git a/lib/cli/Cargo.toml b/lib/cli/Cargo.toml index 777147e343d..aef669cf1bb 100644 --- a/lib/cli/Cargo.toml +++ b/lib/cli/Cargo.toml @@ -45,7 +45,7 @@ wasmer-vfs = { version = "=2.3.0", path = "../vfs", default-features = false, f atty = "0.2" colored = "2.0" anyhow = "1.0" -structopt = { version = "0.3", features = ["suggestions"] } +clap = { version = "3.1", features = ["derive"] } # For the function names autosuggestion distance = "0.4" # For the inspect subcommand @@ -55,6 +55,7 @@ cfg-if = "1.0" fern = { version = "0.6", features = ["colored"], optional = true } log = { version = "0.4", optional = true } tempfile = "3" +target-lexicon = { version = "0.12", features = ["std"] } [target.'cfg(target_os = "linux")'.dependencies] unix_mode = "0.1.3" diff --git a/lib/cli/src/cli.rs b/lib/cli/src/cli.rs index f7bbb5cdf88..e6e2ffc4cae 100644 --- a/lib/cli/src/cli.rs +++ b/lib/cli/src/cli.rs @@ -12,16 +12,16 @@ use crate::commands::{Cache, Config, Inspect, Run, SelfUpdate, Validate}; use crate::error::PrettyError; use anyhow::Result; -use structopt::{clap::ErrorKind, StructOpt}; +use clap::{ErrorKind, Parser}; -#[derive(StructOpt)] +#[derive(Parser)] #[cfg_attr( not(feature = "headless"), - structopt(name = "wasmer", about = "WebAssembly standalone runtime.", author) + clap(name = "wasmer", about = "WebAssembly standalone runtime.", author) )] #[cfg_attr( feature = "headless", - structopt( + clap( name = "wasmer-headless", about = "Headless WebAssembly standalone runtime.", author @@ -30,48 +30,49 @@ use structopt::{clap::ErrorKind, StructOpt}; /// The options for the wasmer Command Line Interface enum WasmerCLIOptions { /// Run a WebAssembly file. Formats accepted: wasm, wat - #[structopt(name = "run")] + #[clap(name = "run")] Run(Run), + // TODO: check whether this should really be a subcommand. /// Wasmer cache - #[structopt(name = "cache")] + #[clap(subcommand, name = "cache")] Cache(Cache), /// Validate a WebAssembly binary - #[structopt(name = "validate")] + #[clap(name = "validate")] Validate(Validate), /// Compile a WebAssembly binary #[cfg(feature = "compiler")] - #[structopt(name = "compile")] + #[clap(name = "compile")] Compile(Compile), /// Compile a WebAssembly binary into a native executable #[cfg(all(feature = "staticlib", feature = "compiler"))] - #[structopt(name = "create-exe")] + #[clap(name = "create-exe")] CreateExe(CreateExe), /// Get various configuration information needed /// to compile programs which use Wasmer - #[structopt(name = "config")] + #[clap(name = "config")] Config(Config), /// Update wasmer to the latest version - #[structopt(name = "self-update")] + #[clap(name = "self-update")] SelfUpdate(SelfUpdate), /// Inspect a WebAssembly file - #[structopt(name = "inspect")] + #[clap(name = "inspect")] Inspect(Inspect), /// Run spec testsuite #[cfg(feature = "wast")] - #[structopt(name = "wast")] + #[clap(name = "wast")] Wast(Wast), /// Unregister and/or register wasmer as binfmt interpreter #[cfg(target_os = "linux")] - #[structopt(name = "binfmt")] + #[clap(name = "binfmt")] Binfmt(Binfmt), } @@ -117,15 +118,15 @@ pub fn wasmer_main() { } else { match command.unwrap_or(&"".to_string()).as_ref() { "cache" | "compile" | "config" | "create-exe" | "help" | "inspect" | "run" - | "self-update" | "validate" | "wast" | "binfmt" => WasmerCLIOptions::from_args(), + | "self-update" | "validate" | "wast" | "binfmt" => WasmerCLIOptions::parse(), _ => { - WasmerCLIOptions::from_iter_safe(args.iter()).unwrap_or_else(|e| { - match e.kind { + WasmerCLIOptions::try_parse_from(args.iter()).unwrap_or_else(|e| { + match e.kind() { // This fixes a issue that: // 1. Shows the version twice when doing `wasmer -V` // 2. Shows the run help (instead of normal help) when doing `wasmer --help` - ErrorKind::VersionDisplayed | ErrorKind::HelpDisplayed => e.exit(), - _ => WasmerCLIOptions::Run(Run::from_args()), + ErrorKind::DisplayVersion | ErrorKind::DisplayHelp => e.exit(), + _ => WasmerCLIOptions::Run(Run::parse()), } }) } diff --git a/lib/cli/src/commands/binfmt.rs b/lib/cli/src/commands/binfmt.rs index dbbfa147f9e..e403b17be45 100644 --- a/lib/cli/src/commands/binfmt.rs +++ b/lib/cli/src/commands/binfmt.rs @@ -1,14 +1,14 @@ use anyhow::{Context, Result}; +use clap::Parser; use std::env; use std::fs; use std::io::Write; use std::os::unix::ffi::OsStrExt; use std::os::unix::fs::MetadataExt; use std::path::{Path, PathBuf}; -use structopt::StructOpt; use Action::*; -#[derive(StructOpt, Clone, Copy)] +#[derive(Parser, Clone, Copy)] enum Action { /// Register wasmer as binfmt interpreter Register, @@ -22,14 +22,14 @@ enum Action { /// /// Check the wasmer repository for a systemd service definition example /// to automate the process at start-up. -#[derive(StructOpt)] +#[derive(Parser)] pub struct Binfmt { // Might be better to traverse the mount list /// Mount point of binfmt_misc fs - #[structopt(long, default_value = "/proc/sys/fs/binfmt_misc/")] + #[clap(long, default_value = "/proc/sys/fs/binfmt_misc/")] binfmt_misc: PathBuf, - #[structopt(subcommand)] + #[clap(subcommand)] action: Action, } diff --git a/lib/cli/src/commands/cache.rs b/lib/cli/src/commands/cache.rs index f5aa21be8e2..9d9e5905114 100644 --- a/lib/cli/src/commands/cache.rs +++ b/lib/cli/src/commands/cache.rs @@ -1,17 +1,17 @@ use crate::common::get_cache_dir; use anyhow::{Context, Result}; +use clap::Parser; use std::fs; -use structopt::StructOpt; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer cache` subcommand pub enum Cache { /// Clear the cache - #[structopt(name = "clean")] + #[clap(name = "clean")] Clean, /// Display the location of the cache - #[structopt(name = "dir")] + #[clap(name = "dir")] Dir, } diff --git a/lib/cli/src/commands/compile.rs b/lib/cli/src/commands/compile.rs index 26b60ba8634..0202a112658 100644 --- a/lib/cli/src/commands/compile.rs +++ b/lib/cli/src/commands/compile.rs @@ -1,33 +1,36 @@ use crate::store::{EngineType, StoreOptions}; use crate::warning; use anyhow::{Context, Result}; +use clap::Parser; use std::path::PathBuf; -use structopt::StructOpt; use wasmer::*; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer compile` subcommand pub struct Compile { /// Input file - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, /// Output file - #[structopt(name = "OUTPUT PATH", short = "o", parse(from_os_str))] + #[clap(name = "OUTPUT PATH", short = 'o', parse(from_os_str))] output: PathBuf, /// Output path for generated header file - #[structopt(name = "HEADER PATH", long = "header", parse(from_os_str))] + #[clap(name = "HEADER PATH", long = "header", parse(from_os_str))] header_path: Option, /// Compilation Target triple - #[structopt(long = "target")] + #[clap(long = "target")] target_triple: Option, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, - #[structopt(short = "m", multiple = true, number_of_values = 1)] + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure + #[clap(short = 'm', multiple_occurrences = true, number_of_values = 1)] cpu_features: Vec, } diff --git a/lib/cli/src/commands/config.rs b/lib/cli/src/commands/config.rs index 0ded2bf4540..2137f6e0caa 100644 --- a/lib/cli/src/commands/config.rs +++ b/lib/cli/src/commands/config.rs @@ -1,39 +1,39 @@ use crate::VERSION; use anyhow::{Context, Result}; +use clap::Parser; use std::env; use std::path::PathBuf; -use structopt::StructOpt; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer config` subcommand pub struct Config { /// Print the installation prefix. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] prefix: bool, /// Directory containing Wasmer executables. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] bindir: bool, /// Directory containing Wasmer headers. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] includedir: bool, /// Directory containing Wasmer libraries. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] libdir: bool, /// Libraries needed to link against Wasmer components. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] libs: bool, /// C compiler flags for files that include Wasmer headers. - #[structopt(long, conflicts_with = "pkg-config")] + #[clap(long, conflicts_with = "pkg-config")] cflags: bool, /// It outputs the necessary details for compiling /// and linking a program to Wasmer, using the `pkg-config` format. - #[structopt(long)] + #[clap(long)] pkg_config: bool, } diff --git a/lib/cli/src/commands/create_exe.rs b/lib/cli/src/commands/create_exe.rs index 960f7310e7b..883847d781b 100644 --- a/lib/cli/src/commands/create_exe.rs +++ b/lib/cli/src/commands/create_exe.rs @@ -2,39 +2,45 @@ use crate::store::{CompilerOptions, EngineType}; use anyhow::{Context, Result}; +use clap::Parser; use std::env; use std::fs; use std::path::{Path, PathBuf}; use std::process::Command; -use structopt::StructOpt; use wasmer::*; const WASMER_MAIN_C_SOURCE: &[u8] = include_bytes!("wasmer_create_exe_main.c"); -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer create-exe` subcommand pub struct CreateExe { /// Input file - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, /// Output file - #[structopt(name = "OUTPUT PATH", short = "o", parse(from_os_str))] + #[clap(name = "OUTPUT PATH", short = 'o', parse(from_os_str))] output: PathBuf, /// Compilation Target triple - #[structopt(long = "target")] + #[clap(long = "target")] target_triple: Option, - #[structopt(flatten)] + #[clap(flatten)] compiler: CompilerOptions, - #[structopt(short = "m", multiple = true, number_of_values = 1)] + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure + #[clap(short = 'm', multiple_occurrences = true, number_of_values = 1)] cpu_features: Vec, + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure /// Additional libraries to link against. /// This is useful for fixing linker errors that may occur on some systems. - #[structopt(short = "l", multiple = true, number_of_values = 1)] + #[clap(short = 'l', multiple_occurrences = true, number_of_values = 1)] libraries: Vec, } diff --git a/lib/cli/src/commands/inspect.rs b/lib/cli/src/commands/inspect.rs index 4858c749ac8..a93c7c47546 100644 --- a/lib/cli/src/commands/inspect.rs +++ b/lib/cli/src/commands/inspect.rs @@ -1,18 +1,18 @@ use crate::store::StoreOptions; use anyhow::{Context, Result}; use bytesize::ByteSize; +use clap::Parser; use std::path::PathBuf; -use structopt::StructOpt; use wasmer::*; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer validate` subcommand pub struct Inspect { /// File to validate as WebAssembly - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, } diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index e2f799751bd..7aa7f7314c5 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -11,7 +11,7 @@ use wasmer::*; #[cfg(feature = "cache")] use wasmer_cache::{Cache, FileSystemCache, Hash}; -use structopt::StructOpt; +use clap::Parser; #[cfg(feature = "wasi")] mod wasi; @@ -19,59 +19,59 @@ mod wasi; #[cfg(feature = "wasi")] use wasi::Wasi; -#[derive(Debug, StructOpt, Clone, Default)] +#[derive(Debug, Parser, Clone, Default)] /// The options for the `wasmer run` subcommand pub struct Run { /// Disable the cache #[cfg(feature = "cache")] - #[structopt(long = "disable-cache")] + #[clap(long = "disable-cache")] disable_cache: bool, /// File to run - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, /// Invoke a specified function - #[structopt(long = "invoke", short = "i")] + #[clap(long = "invoke", short = 'i')] invoke: Option, /// The command name is a string that will override the first argument passed /// to the wasm program. This is used in wapm to provide nicer output in /// help commands and error messages of the running wasm program - #[structopt(long = "command-name", hidden = true)] + #[clap(long = "command-name", hide = true)] command_name: Option, /// A prehashed string, used to speed up start times by avoiding hashing the /// wasm module. If the specified hash is not found, Wasmer will hash the module /// as if no `cache-key` argument was passed. #[cfg(feature = "cache")] - #[structopt(long = "cache-key", hidden = true)] + #[clap(long = "cache-key", hide = true)] cache_key: Option, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, // TODO: refactor WASI structure to allow shared options with Emscripten #[cfg(feature = "wasi")] - #[structopt(flatten)] + #[clap(flatten)] wasi: Wasi, /// Enable non-standard experimental IO devices #[cfg(feature = "io-devices")] - #[structopt(long = "enable-io-devices")] + #[clap(long = "enable-io-devices")] enable_experimental_io_devices: bool, /// Enable debug output #[cfg(feature = "debug")] - #[structopt(long = "debug", short = "d")] + #[clap(long = "debug", short = 'd')] debug: bool, #[cfg(feature = "debug")] - #[structopt(short, long, parse(from_occurrences))] + #[clap(short, long, parse(from_occurrences))] verbose: u8, /// Application arguments - #[structopt(value_name = "ARGS")] + #[clap(value_name = "ARGS")] args: Vec, } diff --git a/lib/cli/src/commands/run/wasi.rs b/lib/cli/src/commands/run/wasi.rs index b7adf3a091f..29be4db6d19 100644 --- a/lib/cli/src/commands/run/wasi.rs +++ b/lib/cli/src/commands/run/wasi.rs @@ -5,51 +5,60 @@ use std::path::PathBuf; use wasmer::{Instance, Module, RuntimeError, Val}; use wasmer_wasi::{get_wasi_versions, WasiError, WasiState, WasiVersion}; -use structopt::StructOpt; +use clap::Parser; -#[derive(Debug, StructOpt, Clone, Default)] +#[derive(Debug, Parser, Clone, Default)] /// WASI Options pub struct Wasi { + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure /// WASI pre-opened directory - #[structopt( + #[clap( long = "dir", name = "DIR", - multiple = true, + multiple_occurrences = true, group = "wasi", number_of_values = 1 )] pre_opened_directories: Vec, + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure /// Map a host directory to a different location for the Wasm module - #[structopt( + #[clap( long = "mapdir", name = "GUEST_DIR:HOST_DIR", - multiple = true, + multiple_occurrences = true, parse(try_from_str = parse_mapdir), number_of_values = 1, )] mapped_dirs: Vec<(String, PathBuf)>, + // TODO: multiple_values or multiple_occurrences, or both? + // TODO: number_of_values = 1 required? need to read some more documentation + // before I can be sure /// Pass custom environment variables - #[structopt( + #[clap( long = "env", name = "KEY=VALUE", - multiple = true, + multiple_occurrences = true, parse(try_from_str = parse_envvar), )] env_vars: Vec<(String, String)>, /// Enable experimental IO devices #[cfg(feature = "experimental-io-devices")] - #[structopt(long = "enable-experimental-io-devices")] + #[clap(long = "enable-experimental-io-devices")] enable_experimental_io_devices: bool, /// Allow WASI modules to import multiple versions of WASI without a warning. - #[structopt(long = "allow-multiple-wasi-versions")] + #[clap(long = "allow-multiple-wasi-versions")] pub allow_multiple_wasi_versions: bool, /// Require WASI modules to only import 1 version of WASI. - #[structopt(long = "deny-multiple-wasi-versions")] + #[clap(long = "deny-multiple-wasi-versions")] pub deny_multiple_wasi_versions: bool, } diff --git a/lib/cli/src/commands/self_update.rs b/lib/cli/src/commands/self_update.rs index 2218107c3f2..70897430857 100644 --- a/lib/cli/src/commands/self_update.rs +++ b/lib/cli/src/commands/self_update.rs @@ -1,11 +1,11 @@ //! When wasmer self-update is executed, this is what gets executed use anyhow::{Context, Result}; +use clap::Parser; #[cfg(not(target_os = "windows"))] use std::process::{Command, Stdio}; -use structopt::StructOpt; /// The options for the `wasmer self-update` subcommand -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] pub struct SelfUpdate {} impl SelfUpdate { diff --git a/lib/cli/src/commands/validate.rs b/lib/cli/src/commands/validate.rs index fb9554d684e..6e5e07294fa 100644 --- a/lib/cli/src/commands/validate.rs +++ b/lib/cli/src/commands/validate.rs @@ -1,17 +1,17 @@ use crate::store::StoreOptions; use anyhow::{bail, Context, Result}; +use clap::Parser; use std::path::PathBuf; -use structopt::StructOpt; use wasmer::*; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer validate` subcommand pub struct Validate { /// File to validate as WebAssembly - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, } diff --git a/lib/cli/src/commands/wast.rs b/lib/cli/src/commands/wast.rs index 2837069f21f..b42e15ff62c 100644 --- a/lib/cli/src/commands/wast.rs +++ b/lib/cli/src/commands/wast.rs @@ -1,21 +1,21 @@ //! Runs a .wast WebAssembly test suites use crate::store::StoreOptions; use anyhow::{Context, Result}; +use clap::Parser; use std::path::PathBuf; -use structopt::StructOpt; use wasmer_wast::Wast as WastSpectest; -#[derive(Debug, StructOpt)] +#[derive(Debug, Parser)] /// The options for the `wasmer wast` subcommand pub struct Wast { /// Wast file to run - #[structopt(name = "FILE", parse(from_os_str))] + #[clap(name = "FILE", parse(from_os_str))] path: PathBuf, - #[structopt(flatten)] + #[clap(flatten)] store: StoreOptions, - #[structopt(short, long)] + #[clap(short, long)] /// A flag to indicate wast stop at the first error or continue. fail_fast: bool, } diff --git a/lib/cli/src/common.rs b/lib/cli/src/common.rs index 863e154103f..81af03197cd 100644 --- a/lib/cli/src/common.rs +++ b/lib/cli/src/common.rs @@ -1,36 +1,36 @@ //! Common module with common used structures across different //! commands. use crate::VERSION; +use clap::Parser; use std::env; use std::path::PathBuf; -use structopt::StructOpt; -#[derive(Debug, StructOpt, Clone, Default)] +#[derive(Debug, Parser, Clone, Default)] /// The WebAssembly features that can be passed through the /// Command Line args. pub struct WasmFeatures { /// Enable support for the SIMD proposal. - #[structopt(long = "enable-simd")] + #[clap(long = "enable-simd")] pub simd: bool, /// Enable support for the threads proposal. - #[structopt(long = "enable-threads")] + #[clap(long = "enable-threads")] pub threads: bool, /// Enable support for the reference types proposal. - #[structopt(long = "enable-reference-types")] + #[clap(long = "enable-reference-types")] pub reference_types: bool, /// Enable support for the multi value proposal. - #[structopt(long = "enable-multi-value")] + #[clap(long = "enable-multi-value")] pub multi_value: bool, /// Enable support for the bulk memory proposal. - #[structopt(long = "enable-bulk-memory")] + #[clap(long = "enable-bulk-memory")] pub bulk_memory: bool, /// Enable support for all pre-standard proposals. - #[structopt(long = "enable-all")] + #[clap(long = "enable-all")] pub all: bool, } diff --git a/lib/cli/src/compilers/llvm.rs b/lib/cli/src/compilers/llvm.rs index b3c8c8fe6ff..b7a7a95e42d 100644 --- a/lib/cli/src/compilers/llvm.rs +++ b/lib/cli/src/compilers/llvm.rs @@ -1,16 +1,16 @@ -#[derive(Debug, StructOpt, Clone)] +#[derive(Debug, Parser, Clone)] /// LLVM backend flags. pub struct LLVMCLIOptions { /// Emit LLVM IR before optimization pipeline. - #[structopt(long = "llvm-pre-opt-ir", parse(from_os_str))] + #[clap(long = "llvm-pre-opt-ir", parse(from_os_str))] pre_opt_ir: Option, /// Emit LLVM IR after optimization pipeline. - #[structopt(long = "llvm-post-opt-ir", parse(from_os_str))] + #[clap(long = "llvm-post-opt-ir", parse(from_os_str))] post_opt_ir: Option, /// Emit LLVM generated native code object file. - #[structopt(long = "llvm-object-file", parse(from_os_str))] + #[clap(long = "llvm-object-file", parse(from_os_str))] obj_file: Option, } diff --git a/lib/cli/src/store.rs b/lib/cli/src/store.rs index a2044c1925c..25e90320e73 100644 --- a/lib/cli/src/store.rs +++ b/lib/cli/src/store.rs @@ -5,74 +5,74 @@ use anyhow::Result; #[allow(unused_imports)] use crate::common::WasmFeatures; +use clap::Parser; #[allow(unused_imports)] use std::path::PathBuf; use std::string::ToString; #[allow(unused_imports)] use std::sync::Arc; -use structopt::StructOpt; use wasmer::*; #[cfg(feature = "compiler")] use wasmer_compiler::CompilerConfig; -#[derive(Debug, Clone, StructOpt, Default)] +#[derive(Debug, Clone, Parser, Default)] /// The compiler and engine options pub struct StoreOptions { #[cfg(feature = "compiler")] - #[structopt(flatten)] + #[clap(flatten)] compiler: CompilerOptions, /// Use the Universal Engine. - #[structopt(long, conflicts_with_all = &["dylib", "staticlib", "jit", "native", "object_file"])] + #[clap(long, conflicts_with_all = &["dylib", "staticlib", "jit", "native", "object_file"])] universal: bool, /// Use the Dylib Engine. - #[structopt(long, conflicts_with_all = &["universal", "staticlib", "jit", "native", "object_file"])] + #[clap(long, conflicts_with_all = &["universal", "staticlib", "jit", "native", "object_file"])] dylib: bool, /// Use the Staticlib Engine. - #[structopt(long, conflicts_with_all = &["universal", "dylib", "jit", "native", "object_file"])] + #[clap(long, conflicts_with_all = &["universal", "dylib", "jit", "native", "object_file"])] staticlib: bool, /// Use the JIT (Universal) Engine. - #[structopt(long, hidden = true, conflicts_with_all = &["universal", "dylib", "staticlib", "native", "object_file"])] + #[clap(long, hide = true, conflicts_with_all = &["universal", "dylib", "staticlib", "native", "object_file"])] jit: bool, /// Use the Native (Dylib) Engine. - #[structopt(long, hidden = true, conflicts_with_all = &["universal", "dylib", "staticlib", "jit", "object_file"])] + #[clap(long, hide = true, conflicts_with_all = &["universal", "dylib", "staticlib", "jit", "object_file"])] native: bool, /// Use the ObjectFile (Staticlib) Engine. - #[structopt(long, hidden = true, conflicts_with_all = &["universal", "dylib", "staticlib", "jit", "native"])] + #[clap(long, hide = true, conflicts_with_all = &["universal", "dylib", "staticlib", "jit", "native"])] object_file: bool, } #[cfg(feature = "compiler")] -#[derive(Debug, Clone, StructOpt, Default)] +#[derive(Debug, Clone, Parser, Default)] /// The compiler options pub struct CompilerOptions { /// Use Singlepass compiler. - #[structopt(long, conflicts_with_all = &["cranelift", "llvm"])] + #[clap(long, conflicts_with_all = &["cranelift", "llvm"])] singlepass: bool, /// Use Cranelift compiler. - #[structopt(long, conflicts_with_all = &["singlepass", "llvm"])] + #[clap(long, conflicts_with_all = &["singlepass", "llvm"])] cranelift: bool, /// Use LLVM compiler. - #[structopt(long, conflicts_with_all = &["singlepass", "cranelift"])] + #[clap(long, conflicts_with_all = &["singlepass", "cranelift"])] llvm: bool, /// Enable compiler internal verification. - #[structopt(long)] + #[clap(long)] enable_verifier: bool, /// LLVM debug directory, where IR and object files will be written to. #[cfg(feature = "llvm")] - #[structopt(long, parse(from_os_str))] + #[clap(long, parse(from_os_str))] llvm_debug_dir: Option, - #[structopt(flatten)] + #[clap(flatten)] features: WasmFeatures, } diff --git a/lib/compiler/Cargo.toml b/lib/compiler/Cargo.toml index 9251f1967b6..40a73ee23d2 100644 --- a/lib/compiler/Cargo.toml +++ b/lib/compiler/Cargo.toml @@ -28,7 +28,7 @@ default = ["std", "enable-serde", "enable-rkyv"] # `CompilerConfig`, as well as the included wasmparser. # Disable this feature if you just want a headless engine. translator = ["wasmparser"] -std = ["wasmer-types/std"] +std = ["wasmer-types/std", "target-lexicon/std"] core = ["hashbrown", "wasmer-types/core"] enable-serde = ["serde", "serde_bytes", "wasmer-types/enable-serde"] enable-rkyv = ["rkyv", "wasmer-types/enable-rkyv"]