Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to clap from structopt #3079

Merged
merged 3 commits into from
Aug 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Looking for changes that affect our C API? See the [C API Changelog](lib/c-api/C
### Added

### Changed
- #[3079](https://github.com/wasmerio/wasmer/pull/3079) Migrate CLI tools to `clap` from `structopt`
- [#3048](https://github.com/wasmerio/wasmer/pull/3048) Automatically publish wasmer as "cloudcompiler" package to wapm.dev on every release
- [#3075](https://github.com/wasmerio/wasmer/pull/3075) Remove __wbindgen_thread_id

- [#3072](https://github.com/wasmerio/wasmer/pull/3072) Add back `Function::*_with_env(…)` functions

### Fixed
Expand Down
62 changes: 20 additions & 42 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion lib/cli-compiler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ wasmer-types = { version = "=3.0.0-alpha.4", 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
Expand All @@ -32,6 +32,7 @@ cfg-if = "1.0"
# For debug feature
fern = { version = "0.6", features = ["colored"], optional = true }
log = { version = "0.4", optional = true }
target-lexicon = { version = "0.12", features = ["std"] }
tempfile = "3"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
Expand Down
22 changes: 11 additions & 11 deletions lib/cli-compiler/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ 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
)]
/// 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),
}

Expand Down Expand Up @@ -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()),
}
})
}
Expand Down
17 changes: 8 additions & 9 deletions lib/cli-compiler/src/commands/compile.rs
Original file line number Diff line number Diff line change
@@ -1,34 +1,33 @@
use crate::store::StoreOptions;
use crate::warning;
use anyhow::{Context, Result};
use clap::Parser;
use std::path::{Path, PathBuf};
use structopt::StructOpt;
use wasmer_compiler::ModuleEnvironment;
use wasmer_compiler::{ArtifactBuild, ArtifactCreate};
use wasmer_compiler::{ArtifactBuild, ArtifactCreate, ModuleEnvironment};
use wasmer_types::entity::PrimaryMap;
use wasmer_types::{
CompileError, CpuFeature, MemoryIndex, MemoryStyle, TableIndex, TableStyle, Target, Triple,
};

#[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<Triple>,

#[structopt(flatten)]
#[clap(flatten)]
store: StoreOptions,

#[structopt(short = "m", multiple = true, number_of_values = 1)]
#[clap(short = 'm')]
cpu_features: Vec<CpuFeature>,
}

Expand Down
18 changes: 9 additions & 9 deletions lib/cli-compiler/src/commands/config.rs
Original file line number Diff line number Diff line change
@@ -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,
}

Expand Down
8 changes: 4 additions & 4 deletions lib/cli-compiler/src/commands/validate.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
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_types::{is_wasm, CpuFeature, Target, Triple};

#[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,
}

Expand Down
16 changes: 8 additions & 8 deletions lib/cli-compiler/src/common.rs
Original file line number Diff line number Diff line change
@@ -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,
}

Expand Down
Loading