Migrate to clap from structopt

This commit is contained in:
Wolfgang Silbermayr
2022-05-17 08:35:57 +02:00
parent ba543fc4f7
commit 2a385c7882
26 changed files with 224 additions and 223 deletions

62
Cargo.lock generated
View File

@@ -271,7 +271,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6358dedf60f4d9b8db43ad187391afe959746101346fe51bb978126bec61dfb" checksum = "a6358dedf60f4d9b8db43ad187391afe959746101346fe51bb978126bec61dfb"
dependencies = [ dependencies = [
"clap 3.2.15", "clap 3.2.15",
"heck 0.4.0", "heck",
"indexmap", "indexmap",
"log", "log",
"proc-macro2", "proc-macro2",
@@ -357,13 +357,28 @@ checksum = "44bbe24bbd31a185bc2c4f7c2abe80bea13a20d57ee4e55be70ac512bdc76417"
dependencies = [ dependencies = [
"atty", "atty",
"bitflags", "bitflags",
"clap_derive",
"clap_lex", "clap_lex",
"indexmap", "indexmap",
"once_cell",
"strsim 0.10.0", "strsim 0.10.0",
"termcolor", "termcolor",
"textwrap 0.15.0", "textwrap 0.15.0",
] ]
[[package]]
name = "clap_derive"
version = "3.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ba52acd3b0a5c33aeada5cdaa3267cdc7c594a98731d4268cdc1532f4264cb4"
dependencies = [
"heck",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "clap_lex" name = "clap_lex"
version = "0.2.4" version = "0.2.4"
@@ -1108,15 +1123,6 @@ dependencies = [
"ahash", "ahash",
] ]
[[package]]
name = "heck"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c"
dependencies = [
"unicode-segmentation",
]
[[package]] [[package]]
name = "heck" name = "heck"
version = "0.4.0" version = "0.4.0"
@@ -2377,30 +2383,6 @@ version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "structopt"
version = "0.3.26"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10"
dependencies = [
"clap 2.34.0",
"lazy_static",
"structopt-derive",
]
[[package]]
name = "structopt-derive"
version = "0.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0"
dependencies = [
"heck 0.3.3",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
]
[[package]] [[package]]
name = "subtle" name = "subtle"
version = "2.4.1" version = "2.4.1"
@@ -2728,12 +2710,6 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7" checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7"
[[package]]
name = "unicode-segmentation"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
version = "0.1.9" version = "0.1.9"
@@ -3019,6 +2995,7 @@ dependencies = [
"atty", "atty",
"bytesize", "bytesize",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"clap 3.2.15",
"colored 2.0.0", "colored 2.0.0",
"dirs", "dirs",
"distance", "distance",
@@ -3026,7 +3003,7 @@ dependencies = [
"http_req", "http_req",
"log", "log",
"serde_json", "serde_json",
"structopt", "target-lexicon 0.12.4",
"tempfile", "tempfile",
"unix_mode", "unix_mode",
"wasmer", "wasmer",
@@ -3079,11 +3056,12 @@ dependencies = [
"atty", "atty",
"bytesize", "bytesize",
"cfg-if 1.0.0", "cfg-if 1.0.0",
"clap 3.2.15",
"colored 2.0.0", "colored 2.0.0",
"distance", "distance",
"fern", "fern",
"log", "log",
"structopt", "target-lexicon 0.12.4",
"tempfile", "tempfile",
"unix_mode", "unix_mode",
"wasmer-compiler", "wasmer-compiler",

View File

@@ -23,7 +23,7 @@ wasmer-types = { version = "=3.0.0-alpha.4", path = "../types" }
atty = "0.2" atty = "0.2"
colored = "2.0" colored = "2.0"
anyhow = "1.0" anyhow = "1.0"
structopt = { version = "0.3", features = ["suggestions"] } clap = { version = "3.1", features = ["derive"] }
# For the function names autosuggestion # For the function names autosuggestion
distance = "0.4" distance = "0.4"
# For the inspect subcommand # For the inspect subcommand
@@ -32,6 +32,7 @@ cfg-if = "1.0"
# For debug feature # For debug feature
fern = { version = "0.6", features = ["colored"], optional = true } fern = { version = "0.6", features = ["colored"], optional = true }
log = { version = "0.4", optional = true } log = { version = "0.4", optional = true }
target-lexicon = { version = "0.12", features = ["std"] }
tempfile = "3" tempfile = "3"
[target.'cfg(not(target_arch = "wasm32"))'.dependencies] [target.'cfg(not(target_arch = "wasm32"))'.dependencies]

View File

@@ -5,10 +5,10 @@ use crate::commands::{Config, Validate};
use crate::error::PrettyError; use crate::error::PrettyError;
use anyhow::Result; use anyhow::Result;
use structopt::{clap::ErrorKind, StructOpt}; use clap::{ErrorKind, Parser};
#[derive(StructOpt)] #[derive(Parser)]
#[structopt( #[clap(
name = "wasmer-compiler", name = "wasmer-compiler",
about = "WebAssembly standalone Compiler.", about = "WebAssembly standalone Compiler.",
author author
@@ -16,16 +16,16 @@ use structopt::{clap::ErrorKind, StructOpt};
/// The options for the wasmer Command Line Interface /// The options for the wasmer Command Line Interface
enum WasmerCLIOptions { enum WasmerCLIOptions {
/// Validate a WebAssembly binary /// Validate a WebAssembly binary
#[structopt(name = "validate")] #[clap(name = "validate")]
Validate(Validate), Validate(Validate),
/// Compile a WebAssembly binary /// Compile a WebAssembly binary
#[structopt(name = "compile")] #[clap(name = "compile")]
Compile(Compile), Compile(Compile),
/// Get various configuration information needed /// Get various configuration information needed
/// to compile programs which use Wasmer /// to compile programs which use Wasmer
#[structopt(name = "config")] #[clap(name = "config")]
Config(Config), Config(Config),
} }
@@ -56,15 +56,15 @@ pub fn wasmer_main() {
let command = args.get(1); let command = args.get(1);
let options = { let options = {
match command.unwrap_or(&"".to_string()).as_ref() { 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| { WasmerCLIOptions::try_parse_from(args.iter()).unwrap_or_else(|e| {
match e.kind { match e.kind() {
// This fixes a issue that: // This fixes a issue that:
// 1. Shows the version twice when doing `wasmer -V` // 1. Shows the version twice when doing `wasmer -V`
// 2. Shows the run help (instead of normal help) when doing `wasmer --help` // 2. Shows the run help (instead of normal help) when doing `wasmer --help`
ErrorKind::VersionDisplayed | ErrorKind::HelpDisplayed => e.exit(), ErrorKind::DisplayVersion | ErrorKind::DisplayHelp => e.exit(),
_ => WasmerCLIOptions::Compile(Compile::from_args()), _ => WasmerCLIOptions::Compile(Compile::parse()),
} }
}) })
} }

View File

@@ -1,34 +1,36 @@
use crate::store::StoreOptions; use crate::store::StoreOptions;
use crate::warning; use crate::warning;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use structopt::StructOpt; use wasmer_compiler::{ArtifactBuild, ArtifactCreate, ModuleEnvironment};
use wasmer_compiler::ModuleEnvironment;
use wasmer_compiler::{ArtifactBuild, ArtifactCreate};
use wasmer_types::entity::PrimaryMap; use wasmer_types::entity::PrimaryMap;
use wasmer_types::{ use wasmer_types::{
CompileError, CpuFeature, MemoryIndex, MemoryStyle, TableIndex, TableStyle, Target, Triple, CompileError, CpuFeature, MemoryIndex, MemoryStyle, TableIndex, TableStyle, Target, Triple,
}; };
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer compile` subcommand /// The options for the `wasmer compile` subcommand
pub struct Compile { pub struct Compile {
/// Input file /// Input file
#[structopt(name = "FILE", parse(from_os_str))] #[clap(name = "FILE", parse(from_os_str))]
path: PathBuf, path: PathBuf,
/// Output file /// 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: PathBuf,
/// Compilation Target triple /// Compilation Target triple
#[structopt(long = "target")] #[clap(long = "target")]
target_triple: Option<Triple>, target_triple: Option<Triple>,
#[structopt(flatten)] #[clap(flatten)]
store: StoreOptions, 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<CpuFeature>, cpu_features: Vec<CpuFeature>,
} }

View File

@@ -1,39 +1,39 @@
use crate::VERSION; use crate::VERSION;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser;
use std::env; use std::env;
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer config` subcommand /// The options for the `wasmer config` subcommand
pub struct Config { pub struct Config {
/// Print the installation prefix. /// Print the installation prefix.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
prefix: bool, prefix: bool,
/// Directory containing Wasmer executables. /// Directory containing Wasmer executables.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
bindir: bool, bindir: bool,
/// Directory containing Wasmer headers. /// Directory containing Wasmer headers.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
includedir: bool, includedir: bool,
/// Directory containing Wasmer libraries. /// Directory containing Wasmer libraries.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
libdir: bool, libdir: bool,
/// Libraries needed to link against Wasmer components. /// Libraries needed to link against Wasmer components.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
libs: bool, libs: bool,
/// C compiler flags for files that include Wasmer headers. /// C compiler flags for files that include Wasmer headers.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
cflags: bool, cflags: bool,
/// It outputs the necessary details for compiling /// It outputs the necessary details for compiling
/// and linking a program to Wasmer, using the `pkg-config` format. /// and linking a program to Wasmer, using the `pkg-config` format.
#[structopt(long)] #[clap(long)]
pkg_config: bool, pkg_config: bool,
} }

View File

@@ -1,18 +1,18 @@
use crate::store::StoreOptions; use crate::store::StoreOptions;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use clap::Parser;
use std::path::PathBuf; use std::path::PathBuf;
use std::str::FromStr; use std::str::FromStr;
use structopt::StructOpt;
use wasmer_types::{is_wasm, CpuFeature, Target, Triple}; use wasmer_types::{is_wasm, CpuFeature, Target, Triple};
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer validate` subcommand /// The options for the `wasmer validate` subcommand
pub struct Validate { pub struct Validate {
/// File to validate as WebAssembly /// File to validate as WebAssembly
#[structopt(name = "FILE", parse(from_os_str))] #[clap(name = "FILE", parse(from_os_str))]
path: PathBuf, path: PathBuf,
#[structopt(flatten)] #[clap(flatten)]
store: StoreOptions, store: StoreOptions,
} }

View File

@@ -1,36 +1,36 @@
//! Common module with common used structures across different //! Common module with common used structures across different
//! commands. //! commands.
use crate::VERSION; use crate::VERSION;
use clap::Parser;
use std::env; use std::env;
use std::path::PathBuf; 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 /// The WebAssembly features that can be passed through the
/// Command Line args. /// Command Line args.
pub struct WasmFeatures { pub struct WasmFeatures {
/// Enable support for the SIMD proposal. /// Enable support for the SIMD proposal.
#[structopt(long = "enable-simd")] #[clap(long = "enable-simd")]
pub simd: bool, pub simd: bool,
/// Enable support for the threads proposal. /// Enable support for the threads proposal.
#[structopt(long = "enable-threads")] #[clap(long = "enable-threads")]
pub threads: bool, pub threads: bool,
/// Enable support for the reference types proposal. /// Enable support for the reference types proposal.
#[structopt(long = "enable-reference-types")] #[clap(long = "enable-reference-types")]
pub reference_types: bool, pub reference_types: bool,
/// Enable support for the multi value proposal. /// Enable support for the multi value proposal.
#[structopt(long = "enable-multi-value")] #[clap(long = "enable-multi-value")]
pub multi_value: bool, pub multi_value: bool,
/// Enable support for the bulk memory proposal. /// Enable support for the bulk memory proposal.
#[structopt(long = "enable-bulk-memory")] #[clap(long = "enable-bulk-memory")]
pub bulk_memory: bool, pub bulk_memory: bool,
/// Enable support for all pre-standard proposals. /// Enable support for all pre-standard proposals.
#[structopt(long = "enable-all")] #[clap(long = "enable-all")]
pub all: bool, pub all: bool,
} }

View File

@@ -3,10 +3,10 @@
use crate::common::WasmFeatures; use crate::common::WasmFeatures;
use anyhow::Result; use anyhow::Result;
use clap::Parser;
use std::string::ToString; use std::string::ToString;
#[allow(unused_imports)] #[allow(unused_imports)]
use std::sync::Arc; use std::sync::Arc;
use structopt::StructOpt;
use wasmer_compiler::EngineBuilder; use wasmer_compiler::EngineBuilder;
use wasmer_compiler::{CompilerConfig, Features}; use wasmer_compiler::{CompilerConfig, Features};
use wasmer_types::{MemoryStyle, MemoryType, Pages, PointerWidth, TableStyle, TableType, Target}; use wasmer_types::{MemoryStyle, MemoryType, Pages, PointerWidth, TableStyle, TableType, Target};
@@ -84,41 +84,41 @@ impl SubsetTunables {
} }
} }
#[derive(Debug, Clone, StructOpt, Default)] #[derive(Debug, Clone, Parser, Default)]
/// The compiler and engine options /// The compiler and engine options
pub struct StoreOptions { pub struct StoreOptions {
#[structopt(flatten)] #[clap(flatten)]
compiler: CompilerOptions, compiler: CompilerOptions,
} }
#[derive(Debug, Clone, StructOpt, Default)] #[derive(Debug, Clone, Parser, Default)]
/// The compiler options /// The compiler options
pub struct CompilerOptions { pub struct CompilerOptions {
/// Use Singlepass compiler. /// Use Singlepass compiler.
#[structopt(long, conflicts_with_all = &["cranelift", "llvm"])] #[clap(long, conflicts_with_all = &["cranelift", "llvm"])]
singlepass: bool, singlepass: bool,
/// Use Cranelift compiler. /// Use Cranelift compiler.
#[structopt(long, conflicts_with_all = &["singlepass", "llvm"])] #[clap(long, conflicts_with_all = &["singlepass", "llvm"])]
cranelift: bool, cranelift: bool,
/// Use LLVM compiler. /// Use LLVM compiler.
#[structopt(long, conflicts_with_all = &["singlepass", "cranelift"])] #[clap(long, conflicts_with_all = &["singlepass", "cranelift"])]
llvm: bool, llvm: bool,
/// Enable compiler internal verification. /// Enable compiler internal verification.
#[allow(unused)] #[allow(unused)]
#[structopt(long)] #[clap(long)]
#[allow(dead_code)] #[allow(dead_code)]
enable_verifier: bool, enable_verifier: bool,
/// LLVM debug directory, where IR and object files will be written to. /// LLVM debug directory, where IR and object files will be written to.
#[allow(unused)] #[allow(unused)]
#[cfg(feature = "llvm")] #[cfg(feature = "llvm")]
#[cfg_attr(feature = "llvm", structopt(long, parse(from_os_str)))] #[cfg_attr(feature = "llvm", clap(long, parse(from_os_str)))]
llvm_debug_dir: Option<PathBuf>, llvm_debug_dir: Option<PathBuf>,
#[structopt(flatten)] #[clap(flatten)]
features: WasmFeatures, features: WasmFeatures,
} }

View File

@@ -42,7 +42,7 @@ wasmer-vfs = { version = "=3.0.0-alpha.4", path = "../vfs", default-features =
atty = "0.2" atty = "0.2"
colored = "2.0" colored = "2.0"
anyhow = "1.0" anyhow = "1.0"
structopt = { version = "0.3", features = ["suggestions"] } clap = { version = "3.1", features = ["derive"] }
# For the function names autosuggestion # For the function names autosuggestion
distance = "0.4" distance = "0.4"
# For the inspect subcommand # For the inspect subcommand
@@ -55,6 +55,7 @@ tempfile = "3"
http_req = { version="^0.8", default-features = false, features = ["rust-tls"], optional = true } http_req = { version="^0.8", default-features = false, features = ["rust-tls"], optional = true }
dirs = { version = "4.0", optional = true } dirs = { version = "4.0", optional = true }
serde_json = { version = "1.0", optional = true } serde_json = { version = "1.0", optional = true }
target-lexicon = { version = "0.12", features = ["std"] }
[target.'cfg(target_os = "linux")'.dependencies] [target.'cfg(target_os = "linux")'.dependencies]
unix_mode = "0.1.3" unix_mode = "0.1.3"

View File

@@ -14,16 +14,16 @@ use crate::commands::{Cache, Config, Inspect, Run, SelfUpdate, Validate};
use crate::error::PrettyError; use crate::error::PrettyError;
use anyhow::Result; use anyhow::Result;
use structopt::{clap::ErrorKind, StructOpt}; use clap::{ErrorKind, Parser};
#[derive(StructOpt)] #[derive(Parser)]
#[cfg_attr( #[cfg_attr(
not(feature = "headless"), not(feature = "headless"),
structopt(name = "wasmer", about = "WebAssembly standalone runtime.", author) clap(name = "wasmer", about = "WebAssembly standalone runtime.", author)
)] )]
#[cfg_attr( #[cfg_attr(
feature = "headless", feature = "headless",
structopt( clap(
name = "wasmer-headless", name = "wasmer-headless",
about = "Headless WebAssembly standalone runtime.", about = "Headless WebAssembly standalone runtime.",
author author
@@ -32,20 +32,21 @@ use structopt::{clap::ErrorKind, StructOpt};
/// The options for the wasmer Command Line Interface /// The options for the wasmer Command Line Interface
enum WasmerCLIOptions { enum WasmerCLIOptions {
/// Run a WebAssembly file. Formats accepted: wasm, wat /// Run a WebAssembly file. Formats accepted: wasm, wat
#[structopt(name = "run")] #[clap(name = "run")]
Run(Run), Run(Run),
// TODO: check whether this should really be a subcommand.
/// Wasmer cache /// Wasmer cache
#[structopt(name = "cache")] #[clap(subcommand, name = "cache")]
Cache(Cache), Cache(Cache),
/// Validate a WebAssembly binary /// Validate a WebAssembly binary
#[structopt(name = "validate")] #[clap(name = "validate")]
Validate(Validate), Validate(Validate),
/// Compile a WebAssembly binary /// Compile a WebAssembly binary
#[cfg(feature = "compiler")] #[cfg(feature = "compiler")]
#[structopt(name = "compile")] #[clap(name = "compile")]
Compile(Compile), Compile(Compile),
/// Compile a WebAssembly binary into a native executable /// Compile a WebAssembly binary into a native executable
@@ -67,7 +68,7 @@ enum WasmerCLIOptions {
/// qjs.exe: ELF 64-bit LSB pie executable, x86-64 ... /// qjs.exe: ELF 64-bit LSB pie executable, x86-64 ...
/// ``` /// ```
#[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))] #[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))]
#[structopt(name = "create-exe", verbatim_doc_comment)] #[clap(name = "create-exe", verbatim_doc_comment)]
CreateExe(CreateExe), CreateExe(CreateExe),
/// Compile a WebAssembly binary into an object file /// Compile a WebAssembly binary into an object file
@@ -93,25 +94,25 @@ enum WasmerCLIOptions {
/// Get various configuration information needed /// Get various configuration information needed
/// to compile programs which use Wasmer /// to compile programs which use Wasmer
#[structopt(name = "config")] #[clap(name = "config")]
Config(Config), Config(Config),
/// Update wasmer to the latest version /// Update wasmer to the latest version
#[structopt(name = "self-update")] #[clap(name = "self-update")]
SelfUpdate(SelfUpdate), SelfUpdate(SelfUpdate),
/// Inspect a WebAssembly file /// Inspect a WebAssembly file
#[structopt(name = "inspect")] #[clap(name = "inspect")]
Inspect(Inspect), Inspect(Inspect),
/// Run spec testsuite /// Run spec testsuite
#[cfg(feature = "wast")] #[cfg(feature = "wast")]
#[structopt(name = "wast")] #[clap(name = "wast")]
Wast(Wast), Wast(Wast),
/// Unregister and/or register wasmer as binfmt interpreter /// Unregister and/or register wasmer as binfmt interpreter
#[cfg(target_os = "linux")] #[cfg(target_os = "linux")]
#[structopt(name = "binfmt")] #[clap(name = "binfmt")]
Binfmt(Binfmt), Binfmt(Binfmt),
} }
@@ -159,15 +160,15 @@ pub fn wasmer_main() {
} else { } else {
match command.unwrap_or(&"".to_string()).as_ref() { match command.unwrap_or(&"".to_string()).as_ref() {
"cache" | "compile" | "config" | "create-exe" | "help" | "inspect" | "run" "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| { WasmerCLIOptions::try_parse_from(args.iter()).unwrap_or_else(|e| {
match e.kind { match e.kind() {
// This fixes a issue that: // This fixes a issue that:
// 1. Shows the version twice when doing `wasmer -V` // 1. Shows the version twice when doing `wasmer -V`
// 2. Shows the run help (instead of normal help) when doing `wasmer --help` // 2. Shows the run help (instead of normal help) when doing `wasmer --help`
ErrorKind::VersionDisplayed | ErrorKind::HelpDisplayed => e.exit(), ErrorKind::DisplayVersion | ErrorKind::DisplayHelp => e.exit(),
_ => WasmerCLIOptions::Run(Run::from_args()), _ => WasmerCLIOptions::Run(Run::parse()),
} }
}) })
} }

View File

@@ -29,7 +29,7 @@ pub use wast::*;
pub use {cache::*, config::*, inspect::*, run::*, self_update::*, validate::*}; pub use {cache::*, config::*, inspect::*, run::*, self_update::*, validate::*};
/// The kind of object format to emit. /// The kind of object format to emit.
#[derive(Debug, Copy, Clone, structopt::StructOpt)] #[derive(Debug, Copy, Clone, clap::Parser)]
#[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))] #[cfg(any(feature = "static-artifact-create", feature = "wasmer-artifact-create"))]
pub enum ObjectFormat { pub enum ObjectFormat {
/// Serialize the entire module into an object file. /// Serialize the entire module into an object file.

View File

@@ -1,14 +1,14 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser;
use std::env; use std::env;
use std::fs; use std::fs;
use std::io::Write; use std::io::Write;
use std::os::unix::ffi::OsStrExt; use std::os::unix::ffi::OsStrExt;
use std::os::unix::fs::MetadataExt; use std::os::unix::fs::MetadataExt;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use structopt::StructOpt;
use Action::*; use Action::*;
#[derive(StructOpt, Clone, Copy)] #[derive(Parser, Clone, Copy)]
enum Action { enum Action {
/// Register wasmer as binfmt interpreter /// Register wasmer as binfmt interpreter
Register, Register,
@@ -22,14 +22,14 @@ enum Action {
/// ///
/// Check the wasmer repository for a systemd service definition example /// Check the wasmer repository for a systemd service definition example
/// to automate the process at start-up. /// to automate the process at start-up.
#[derive(StructOpt)] #[derive(Parser)]
pub struct Binfmt { pub struct Binfmt {
// Might be better to traverse the mount list // Might be better to traverse the mount list
/// Mount point of binfmt_misc fs /// 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, binfmt_misc: PathBuf,
#[structopt(subcommand)] #[clap(subcommand)]
action: Action, action: Action,
} }

View File

@@ -1,17 +1,17 @@
use crate::common::get_cache_dir; use crate::common::get_cache_dir;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser;
use std::fs; use std::fs;
use structopt::StructOpt;
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer cache` subcommand /// The options for the `wasmer cache` subcommand
pub enum Cache { pub enum Cache {
/// Clear the cache /// Clear the cache
#[structopt(name = "clean")] #[clap(name = "clean")]
Clean, Clean,
/// Display the location of the cache /// Display the location of the cache
#[structopt(name = "dir")] #[clap(name = "dir")]
Dir, Dir,
} }

View File

@@ -1,29 +1,32 @@
use crate::store::StoreOptions; use crate::store::StoreOptions;
use crate::warning; use crate::warning;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser;
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt;
use wasmer::*; use wasmer::*;
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer compile` subcommand /// The options for the `wasmer compile` subcommand
pub struct Compile { pub struct Compile {
/// Input file /// Input file
#[structopt(name = "FILE", parse(from_os_str))] #[clap(name = "FILE", parse(from_os_str))]
path: PathBuf, path: PathBuf,
/// Output file /// 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: PathBuf,
/// Compilation Target triple /// Compilation Target triple
#[structopt(long = "target")] #[clap(long = "target")]
target_triple: Option<Triple>, target_triple: Option<Triple>,
#[structopt(flatten)] #[clap(flatten)]
store: StoreOptions, 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<CpuFeature>, cpu_features: Vec<CpuFeature>,
} }

View File

@@ -1,39 +1,39 @@
use crate::VERSION; use crate::VERSION;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser;
use std::env; use std::env;
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt;
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer config` subcommand /// The options for the `wasmer config` subcommand
pub struct Config { pub struct Config {
/// Print the installation prefix. /// Print the installation prefix.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
prefix: bool, prefix: bool,
/// Directory containing Wasmer executables. /// Directory containing Wasmer executables.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
bindir: bool, bindir: bool,
/// Directory containing Wasmer headers. /// Directory containing Wasmer headers.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
includedir: bool, includedir: bool,
/// Directory containing Wasmer libraries. /// Directory containing Wasmer libraries.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
libdir: bool, libdir: bool,
/// Libraries needed to link against Wasmer components. /// Libraries needed to link against Wasmer components.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
libs: bool, libs: bool,
/// C compiler flags for files that include Wasmer headers. /// C compiler flags for files that include Wasmer headers.
#[structopt(long, conflicts_with = "pkg-config")] #[clap(long, conflicts_with = "pkg-config")]
cflags: bool, cflags: bool,
/// It outputs the necessary details for compiling /// It outputs the necessary details for compiling
/// and linking a program to Wasmer, using the `pkg-config` format. /// and linking a program to Wasmer, using the `pkg-config` format.
#[structopt(long)] #[clap(long)]
pkg_config: bool, pkg_config: bool,
} }

View File

@@ -3,6 +3,7 @@
use super::ObjectFormat; use super::ObjectFormat;
use crate::store::CompilerOptions; use crate::store::CompilerOptions;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser;
use std::env; use std::env;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
@@ -10,7 +11,6 @@ use std::io::prelude::*;
use std::io::BufWriter; use std::io::BufWriter;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; use std::process::Command;
use structopt::StructOpt;
use wasmer::*; use wasmer::*;
use wasmer_object::{emit_serialized, get_object_for_target}; use wasmer_object::{emit_serialized, get_object_for_target};
@@ -42,32 +42,32 @@ struct CrossCompileSetup {
library: PathBuf, library: PathBuf,
} }
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer create-exe` subcommand /// The options for the `wasmer create-exe` subcommand
pub struct CreateExe { pub struct CreateExe {
/// Input file /// Input file
#[structopt(name = "FILE", parse(from_os_str))] #[clap(name = "FILE", parse(from_os_str))]
path: PathBuf, path: PathBuf,
/// Output file /// 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: PathBuf,
/// Compilation Target triple /// Compilation Target triple
#[structopt(long = "target")] #[clap(long = "target")]
target_triple: Option<Triple>, target_triple: Option<Triple>,
// Cross-compile with `zig` // Cross-compile with `zig`
/// Cross-compilation library path. /// Cross-compilation library path.
#[structopt(long = "library-path")] #[clap(long = "library-path")]
library_path: Option<PathBuf>, library_path: Option<PathBuf>,
/// Cross-compilation tarball library path. /// Cross-compilation tarball library path.
#[structopt(long = "tarball")] #[clap(long = "tarball")]
tarball: Option<PathBuf>, tarball: Option<PathBuf>,
/// Specify `zig` binary path /// Specify `zig` binary path
#[structopt(long = "zig-binary-path")] #[clap(long = "zig-binary-path")]
zig_binary_path: Option<PathBuf>, zig_binary_path: Option<PathBuf>,
/// Object format options /// Object format options
@@ -76,25 +76,31 @@ pub struct CreateExe {
/// - (default) `symbols` creates an /// - (default) `symbols` creates an
/// executable where all functions and metadata of the module are regular object symbols /// executable where all functions and metadata of the module are regular object symbols
/// - `serialized` creates an executable where the module is zero-copy serialized as raw data /// - `serialized` creates an executable where the module is zero-copy serialized as raw data
#[structopt(name = "OBJECT_FORMAT", long = "object-format", verbatim_doc_comment)] #[clap(name = "OBJECT_FORMAT", long = "object-format", verbatim_doc_comment)]
object_format: Option<ObjectFormat>, object_format: Option<ObjectFormat>,
/// Header file for object input /// Header file for object input
/// ///
/// If given, the input `PATH` is assumed to be an object created with `wasmer create-obj` and /// If given, the input `PATH` is assumed to be an object created with `wasmer create-obj` and
/// this is its accompanying header file. /// this is its accompanying header file.
#[structopt(name = "HEADER", long = "header", verbatim_doc_comment)] #[clap(name = "HEADER", long = "header", verbatim_doc_comment)]
header: Option<PathBuf>, header: Option<PathBuf>,
#[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<CpuFeature>, cpu_features: Vec<CpuFeature>,
// 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. /// Additional libraries to link against.
/// This is useful for fixing linker errors that may occur on some systems. /// 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<String>, libraries: Vec<String>,
#[structopt(flatten)] #[clap(flatten)]
compiler: CompilerOptions, compiler: CompilerOptions,
} }

View File

@@ -4,6 +4,7 @@
use super::ObjectFormat; use super::ObjectFormat;
use crate::{commands::PrefixerFn, store::CompilerOptions}; use crate::{commands::PrefixerFn, store::CompilerOptions};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser;
use std::env; use std::env;
use std::fs; use std::fs;
use std::fs::File; use std::fs::File;
@@ -11,25 +12,24 @@ use std::io::prelude::*;
use std::io::BufWriter; use std::io::BufWriter;
use std::path::PathBuf; use std::path::PathBuf;
use std::process::Command; use std::process::Command;
use structopt::StructOpt;
use wasmer::*; use wasmer::*;
use wasmer_object::{emit_serialized, get_object_for_target}; use wasmer_object::{emit_serialized, get_object_for_target};
const WASMER_SERIALIZED_HEADER: &[u8] = include_bytes!("wasmer_create_exe.h"); const WASMER_SERIALIZED_HEADER: &[u8] = include_bytes!("wasmer_create_exe.h");
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer create-exe` subcommand /// The options for the `wasmer create-exe` subcommand
pub struct CreateObj { pub struct CreateObj {
/// Input file /// Input file
#[structopt(name = "FILE", parse(from_os_str))] #[clap(name = "FILE", parse(from_os_str))]
path: PathBuf, path: PathBuf,
/// Output file /// 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: PathBuf,
/// Header output file /// Header output file
#[structopt( #[clap(
name = "OUTPUT_HEADER_PATH", name = "OUTPUT_HEADER_PATH",
long = "output-header-path", long = "output-header-path",
parse(from_os_str) parse(from_os_str)
@@ -37,7 +37,7 @@ pub struct CreateObj {
header_output: Option<PathBuf>, header_output: Option<PathBuf>,
/// Compilation Target triple /// Compilation Target triple
#[structopt(long = "target")] #[clap(long = "target")]
target_triple: Option<Triple>, target_triple: Option<Triple>,
/// Object format options /// Object format options
@@ -45,13 +45,13 @@ pub struct CreateObj {
/// This flag accepts two options: `symbols` or `serialized`. /// This flag accepts two options: `symbols` or `serialized`.
/// - (default) `symbols` creates an object where all functions and metadata of the module are regular object symbols /// - (default) `symbols` creates an object where all functions and metadata of the module are regular object symbols
/// - `serialized` creates an object where the module is zero-copy serialized as raw data /// - `serialized` creates an object where the module is zero-copy serialized as raw data
#[structopt(name = "OBJECT_FORMAT", long = "object-format", verbatim_doc_comment)] #[clap(name = "OBJECT_FORMAT", long = "object-format", verbatim_doc_comment)]
object_format: Option<ObjectFormat>, object_format: Option<ObjectFormat>,
#[structopt(short = "m", multiple = true, number_of_values = 1)] #[clap(short = 'm', multiple = true, number_of_values = 1)]
cpu_features: Vec<CpuFeature>, cpu_features: Vec<CpuFeature>,
#[structopt(flatten)] #[clap(flatten)]
compiler: CompilerOptions, compiler: CompilerOptions,
} }

View File

@@ -1,18 +1,18 @@
use crate::store::StoreOptions; use crate::store::StoreOptions;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use bytesize::ByteSize; use bytesize::ByteSize;
use clap::Parser;
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt;
use wasmer::*; use wasmer::*;
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer validate` subcommand /// The options for the `wasmer validate` subcommand
pub struct Inspect { pub struct Inspect {
/// File to validate as WebAssembly /// File to validate as WebAssembly
#[structopt(name = "FILE", parse(from_os_str))] #[clap(name = "FILE", parse(from_os_str))]
path: PathBuf, path: PathBuf,
#[structopt(flatten)] #[clap(flatten)]
store: StoreOptions, store: StoreOptions,
} }

View File

@@ -13,7 +13,7 @@ use wasmer::*;
use wasmer_cache::{Cache, FileSystemCache, Hash}; use wasmer_cache::{Cache, FileSystemCache, Hash};
use wasmer_types::Type as ValueType; use wasmer_types::Type as ValueType;
use structopt::StructOpt; use clap::Parser;
#[cfg(feature = "wasi")] #[cfg(feature = "wasi")]
mod wasi; mod wasi;
@@ -21,59 +21,59 @@ mod wasi;
#[cfg(feature = "wasi")] #[cfg(feature = "wasi")]
use wasi::Wasi; use wasi::Wasi;
#[derive(Debug, StructOpt, Clone, Default)] #[derive(Debug, Parser, Clone, Default)]
/// The options for the `wasmer run` subcommand /// The options for the `wasmer run` subcommand
pub struct Run { pub struct Run {
/// Disable the cache /// Disable the cache
#[cfg(feature = "cache")] #[cfg(feature = "cache")]
#[structopt(long = "disable-cache")] #[clap(long = "disable-cache")]
disable_cache: bool, disable_cache: bool,
/// File to run /// File to run
#[structopt(name = "FILE", parse(from_os_str))] #[clap(name = "FILE", parse(from_os_str))]
path: PathBuf, path: PathBuf,
/// Invoke a specified function /// Invoke a specified function
#[structopt(long = "invoke", short = "i")] #[clap(long = "invoke", short = 'i')]
invoke: Option<String>, invoke: Option<String>,
/// The command name is a string that will override the first argument passed /// 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 /// to the wasm program. This is used in wapm to provide nicer output in
/// help commands and error messages of the running wasm program /// 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<String>, command_name: Option<String>,
/// A prehashed string, used to speed up start times by avoiding hashing the /// 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 /// wasm module. If the specified hash is not found, Wasmer will hash the module
/// as if no `cache-key` argument was passed. /// as if no `cache-key` argument was passed.
#[cfg(feature = "cache")] #[cfg(feature = "cache")]
#[structopt(long = "cache-key", hidden = true)] #[clap(long = "cache-key", hide = true)]
cache_key: Option<String>, cache_key: Option<String>,
#[structopt(flatten)] #[clap(flatten)]
store: StoreOptions, store: StoreOptions,
// TODO: refactor WASI structure to allow shared options with Emscripten // TODO: refactor WASI structure to allow shared options with Emscripten
#[cfg(feature = "wasi")] #[cfg(feature = "wasi")]
#[structopt(flatten)] #[clap(flatten)]
wasi: Wasi, wasi: Wasi,
/// Enable non-standard experimental IO devices /// Enable non-standard experimental IO devices
#[cfg(feature = "io-devices")] #[cfg(feature = "io-devices")]
#[structopt(long = "enable-io-devices")] #[clap(long = "enable-io-devices")]
enable_experimental_io_devices: bool, enable_experimental_io_devices: bool,
/// Enable debug output /// Enable debug output
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
#[structopt(long = "debug", short = "d")] #[clap(long = "debug", short = 'd')]
debug: bool, debug: bool,
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
#[structopt(short, long, parse(from_occurrences))] #[clap(short, long, parse(from_occurrences))]
verbose: u8, verbose: u8,
/// Application arguments /// Application arguments
#[structopt(value_name = "ARGS")] #[clap(value_name = "ARGS")]
args: Vec<String>, args: Vec<String>,
} }

View File

@@ -8,36 +8,45 @@ use wasmer_wasi::{
WasiState, WasiVersion, WasiState, WasiVersion,
}; };
use structopt::StructOpt; use clap::Parser;
#[derive(Debug, StructOpt, Clone, Default)] #[derive(Debug, Parser, Clone, Default)]
/// WASI Options /// WASI Options
pub struct Wasi { 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 /// WASI pre-opened directory
#[structopt( #[clap(
long = "dir", long = "dir",
name = "DIR", name = "DIR",
multiple = true, multiple_occurrences = true,
group = "wasi", group = "wasi",
number_of_values = 1 number_of_values = 1
)] )]
pre_opened_directories: Vec<PathBuf>, pre_opened_directories: Vec<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
/// Map a host directory to a different location for the Wasm module /// Map a host directory to a different location for the Wasm module
#[structopt( #[clap(
long = "mapdir", long = "mapdir",
name = "GUEST_DIR:HOST_DIR", name = "GUEST_DIR:HOST_DIR",
multiple = true, multiple_occurrences = true,
parse(try_from_str = parse_mapdir), parse(try_from_str = parse_mapdir),
number_of_values = 1, number_of_values = 1,
)] )]
mapped_dirs: Vec<(String, PathBuf)>, 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 /// Pass custom environment variables
#[structopt( #[clap(
long = "env", long = "env",
name = "KEY=VALUE", name = "KEY=VALUE",
multiple = true, multiple_occurrences = true,
parse(try_from_str = parse_envvar), parse(try_from_str = parse_envvar),
)] )]
env_vars: Vec<(String, String)>, env_vars: Vec<(String, String)>,
@@ -46,16 +55,16 @@ pub struct Wasi {
#[cfg(feature = "experimental-io-devices")] #[cfg(feature = "experimental-io-devices")]
#[cfg_attr( #[cfg_attr(
feature = "experimental-io-devices", feature = "experimental-io-devices",
structopt(long = "enable-experimental-io-devices") clap(long = "enable-experimental-io-devices")
)] )]
enable_experimental_io_devices: bool, enable_experimental_io_devices: bool,
/// Allow WASI modules to import multiple versions of WASI without a warning. /// 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, pub allow_multiple_wasi_versions: bool,
/// Require WASI modules to only import 1 version of WASI. /// 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, pub deny_multiple_wasi_versions: bool,
} }

View File

@@ -1,11 +1,11 @@
//! When wasmer self-update is executed, this is what gets executed //! When wasmer self-update is executed, this is what gets executed
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser;
#[cfg(not(target_os = "windows"))] #[cfg(not(target_os = "windows"))]
use std::process::{Command, Stdio}; use std::process::{Command, Stdio};
use structopt::StructOpt;
/// The options for the `wasmer self-update` subcommand /// The options for the `wasmer self-update` subcommand
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
pub struct SelfUpdate {} pub struct SelfUpdate {}
impl SelfUpdate { impl SelfUpdate {

View File

@@ -1,17 +1,17 @@
use crate::store::StoreOptions; use crate::store::StoreOptions;
use anyhow::{bail, Context, Result}; use anyhow::{bail, Context, Result};
use clap::Parser;
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt;
use wasmer::*; use wasmer::*;
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer validate` subcommand /// The options for the `wasmer validate` subcommand
pub struct Validate { pub struct Validate {
/// File to validate as WebAssembly /// File to validate as WebAssembly
#[structopt(name = "FILE", parse(from_os_str))] #[clap(name = "FILE", parse(from_os_str))]
path: PathBuf, path: PathBuf,
#[structopt(flatten)] #[clap(flatten)]
store: StoreOptions, store: StoreOptions,
} }

View File

@@ -1,21 +1,21 @@
//! Runs a .wast WebAssembly test suites //! Runs a .wast WebAssembly test suites
use crate::store::StoreOptions; use crate::store::StoreOptions;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser;
use std::path::PathBuf; use std::path::PathBuf;
use structopt::StructOpt;
use wasmer_wast::Wast as WastSpectest; use wasmer_wast::Wast as WastSpectest;
#[derive(Debug, StructOpt)] #[derive(Debug, Parser)]
/// The options for the `wasmer wast` subcommand /// The options for the `wasmer wast` subcommand
pub struct Wast { pub struct Wast {
/// Wast file to run /// Wast file to run
#[structopt(name = "FILE", parse(from_os_str))] #[clap(name = "FILE", parse(from_os_str))]
path: PathBuf, path: PathBuf,
#[structopt(flatten)] #[clap(flatten)]
store: StoreOptions, store: StoreOptions,
#[structopt(short, long)] #[clap(short, long)]
/// A flag to indicate wast stop at the first error or continue. /// A flag to indicate wast stop at the first error or continue.
fail_fast: bool, fail_fast: bool,
} }

View File

@@ -1,36 +1,36 @@
//! Common module with common used structures across different //! Common module with common used structures across different
//! commands. //! commands.
use crate::VERSION; use crate::VERSION;
use clap::Parser;
use std::env; use std::env;
use std::path::PathBuf; 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 /// The WebAssembly features that can be passed through the
/// Command Line args. /// Command Line args.
pub struct WasmFeatures { pub struct WasmFeatures {
/// Enable support for the SIMD proposal. /// Enable support for the SIMD proposal.
#[structopt(long = "enable-simd")] #[clap(long = "enable-simd")]
pub simd: bool, pub simd: bool,
/// Enable support for the threads proposal. /// Enable support for the threads proposal.
#[structopt(long = "enable-threads")] #[clap(long = "enable-threads")]
pub threads: bool, pub threads: bool,
/// Enable support for the reference types proposal. /// Enable support for the reference types proposal.
#[structopt(long = "enable-reference-types")] #[clap(long = "enable-reference-types")]
pub reference_types: bool, pub reference_types: bool,
/// Enable support for the multi value proposal. /// Enable support for the multi value proposal.
#[structopt(long = "enable-multi-value")] #[clap(long = "enable-multi-value")]
pub multi_value: bool, pub multi_value: bool,
/// Enable support for the bulk memory proposal. /// Enable support for the bulk memory proposal.
#[structopt(long = "enable-bulk-memory")] #[clap(long = "enable-bulk-memory")]
pub bulk_memory: bool, pub bulk_memory: bool,
/// Enable support for all pre-standard proposals. /// Enable support for all pre-standard proposals.
#[structopt(long = "enable-all")] #[clap(long = "enable-all")]
pub all: bool, pub all: bool,
} }

View File

@@ -1,16 +1,16 @@
#[derive(Debug, StructOpt, Clone)] #[derive(Debug, Parser, Clone)]
/// LLVM backend flags. /// LLVM backend flags.
pub struct LLVMCLIOptions { pub struct LLVMCLIOptions {
/// Emit LLVM IR before optimization pipeline. /// 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<PathBuf>, pre_opt_ir: Option<PathBuf>,
/// Emit LLVM IR after optimization pipeline. /// 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<PathBuf>, post_opt_ir: Option<PathBuf>,
/// Emit LLVM generated native code object file. /// 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<PathBuf>, obj_file: Option<PathBuf>,
} }

View File

@@ -5,52 +5,52 @@ use anyhow::Result;
#[allow(unused_imports)] #[allow(unused_imports)]
use crate::common::WasmFeatures; use crate::common::WasmFeatures;
use clap::Parser;
#[allow(unused_imports)] #[allow(unused_imports)]
use std::path::PathBuf; use std::path::PathBuf;
use std::string::ToString; use std::string::ToString;
#[allow(unused_imports)] #[allow(unused_imports)]
use std::sync::Arc; use std::sync::Arc;
use structopt::StructOpt;
use wasmer::*; use wasmer::*;
#[cfg(feature = "compiler")] #[cfg(feature = "compiler")]
use wasmer_compiler::CompilerConfig; use wasmer_compiler::CompilerConfig;
use wasmer_compiler::Engine; use wasmer_compiler::Engine;
#[derive(Debug, Clone, StructOpt, Default)] #[derive(Debug, Clone, Parser, Default)]
/// The compiler options /// The compiler options
pub struct StoreOptions { pub struct StoreOptions {
#[cfg(feature = "compiler")] #[cfg(feature = "compiler")]
#[structopt(flatten)] #[clap(flatten)]
compiler: CompilerOptions, compiler: CompilerOptions,
} }
#[cfg(feature = "compiler")] #[cfg(feature = "compiler")]
#[derive(Debug, Clone, StructOpt, Default)] #[derive(Debug, Clone, Parser, Default)]
/// The compiler options /// The compiler options
pub struct CompilerOptions { pub struct CompilerOptions {
/// Use Singlepass compiler. /// Use Singlepass compiler.
#[structopt(long, conflicts_with_all = &["cranelift", "llvm"])] #[clap(long, conflicts_with_all = &["cranelift", "llvm"])]
singlepass: bool, singlepass: bool,
/// Use Cranelift compiler. /// Use Cranelift compiler.
#[structopt(long, conflicts_with_all = &["singlepass", "llvm"])] #[clap(long, conflicts_with_all = &["singlepass", "llvm"])]
cranelift: bool, cranelift: bool,
/// Use LLVM compiler. /// Use LLVM compiler.
#[structopt(long, conflicts_with_all = &["singlepass", "cranelift"])] #[clap(long, conflicts_with_all = &["singlepass", "cranelift"])]
llvm: bool, llvm: bool,
/// Enable compiler internal verification. /// Enable compiler internal verification.
#[structopt(long)] #[clap(long)]
#[cfg(any(feature = "singlepass", feature = "cranelift", feature = "llvm"))] #[cfg(any(feature = "singlepass", feature = "cranelift", feature = "llvm"))]
enable_verifier: bool, enable_verifier: bool,
/// LLVM debug directory, where IR and object files will be written to. /// LLVM debug directory, where IR and object files will be written to.
#[cfg(feature = "llvm")] #[cfg(feature = "llvm")]
#[structopt(long, parse(from_os_str))] #[clap(long, parse(from_os_str))]
llvm_debug_dir: Option<PathBuf>, llvm_debug_dir: Option<PathBuf>,
#[structopt(flatten)] #[clap(flatten)]
features: WasmFeatures, features: WasmFeatures,
} }