Skip to content

Commit

Permalink
Update dependencies. Use Clap 3.0.0-beta2 instead of StructOpt
Browse files Browse the repository at this point in the history
  • Loading branch information
syrusakbary committed Mar 4, 2021
1 parent 1ee7b4a commit 392f50a
Show file tree
Hide file tree
Showing 21 changed files with 299 additions and 328 deletions.
385 changes: 185 additions & 200 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 0 additions & 4 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,7 @@ skip = [
{ name = "semver", version = "=0.9.0" },
{ name = "semver-parser", version = "=0.7.0" },
{ name = "rustc_version", version = "=0.2.3" },
{ name = "gimli", version = "=0.22.0" },
{ name = "wasi", version = "=0.9.0" },
{ name = "redox_syscall", version = "=0.1.57" },
{ name = "itertools", version = "0.9.0" },
{ name = "getrandom", version = "0.1.16" },
{ name = "wast", version = "=24.0.0" },
]
# Similarly to `skip` allows you to skip certain crates during duplicate
Expand Down
2 changes: 1 addition & 1 deletion lib/c-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ cranelift-backend = ["cranelift"]
llvm-backend = ["llvm"]

[build-dependencies]
cbindgen = "0.15"
cbindgen = "0.18"
2 changes: 1 addition & 1 deletion lib/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ wasmer-types = { version = "1.0.2", path = "../wasmer-types" }
atty = "0.2"
colored = "2.0"
anyhow = "1.0"
structopt = { version = "0.3", features = ["suggestions"] }
clap = { version = "3.0.0-beta.2", features = ["suggestions", "derive", "cargo", "std", "color"], default-features = false }
# For the function names autosuggestion
distance = "0.4"
# For the inspect subcommand
Expand Down
34 changes: 17 additions & 17 deletions lib/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ use crate::commands::{Cache, Config, Inspect, Run, SelfUpdate, Validate};
use crate::error::PrettyError;
use anyhow::Result;

use structopt::{clap::ErrorKind, StructOpt};
use clap::{Clap, ErrorKind};

#[derive(Debug, StructOpt)]
#[derive(Clap)]
#[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
Expand All @@ -28,43 +28,43 @@ 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),

/// Wasmer cache
#[structopt(name = "cache")]
#[clap(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 = "object-file", 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),
}

Expand Down Expand Up @@ -101,15 +101,15 @@ pub fn wasmer_main() {
let command = args.get(1);
let options = match command.unwrap_or(&"".to_string()).as_ref() {
"cache" | "compile" | "config" | "create-exe" | "help" | "inspect" | "run"
| "self-update" | "validate" | "wast" => WasmerCLIOptions::from_args(),
| "self-update" | "validate" | "wast" => 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 {
// 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()),
}
})
}
Expand Down
8 changes: 4 additions & 4 deletions lib/cli/src/commands/cache.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
use crate::common::get_cache_dir;
use anyhow::{Context, Result};
use clap::Clap;
use std::fs;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[derive(Debug, Clap)]
/// 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,
}

Expand Down
16 changes: 8 additions & 8 deletions lib/cli/src/commands/compile.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
use crate::store::{EngineType, StoreOptions};
use crate::warning;
use anyhow::{Context, Result};
use clap::Clap;
use std::path::PathBuf;
use structopt::StructOpt;
use wasmer::*;

#[derive(Debug, StructOpt)]
#[derive(Debug, Clap)]
/// 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<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)]
#[clap(short = 'm', multiple = true)]
cpu_features: Vec<CpuFeature>,
}

Expand Down
18 changes: 9 additions & 9 deletions lib/cli/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::Clap;
use std::env;
use std::path::PathBuf;
use structopt::StructOpt;

#[derive(Debug, StructOpt)]
#[derive(Debug, Clap)]
/// 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
34 changes: 12 additions & 22 deletions lib/cli/src/commands/create_exe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@
use crate::store::{CompilerOptions, EngineType};
use anyhow::{Context, Result};
use clap::Clap;
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, Clap)]
/// 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<Triple>,

#[structopt(flatten)]
#[clap(flatten)]
compiler: CompilerOptions,

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

/// Additional libraries to link against.
/// This is useful for fixing linker errors that may occur on some systems.
#[structopt(short = "l", multiple = true)]
#[clap(short = 'l', multiple = true)]
libraries: Vec<String>,
}

Expand Down Expand Up @@ -148,20 +148,14 @@ fn generate_header(header_file_src: &[u8]) -> anyhow::Result<()> {
.open(&header_file_path)?;

use std::io::Write;
header.write_all(header_file_src)?;
header.write(header_file_src)?;

Ok(())
}

fn get_wasmer_dir() -> anyhow::Result<PathBuf> {
Ok(PathBuf::from(
env::var("WASMER_DIR")
.or_else(|e| {
option_env!("WASMER_INSTALL_PREFIX")
.map(str::to_string)
.ok_or(e)
})
.context("Trying to read env var `WASMER_DIR`")?,
env::var("WASMER_DIR").context("Trying to read env var `WASMER_DIR`")?,
))
}

Expand Down Expand Up @@ -285,13 +279,9 @@ impl LinkCode {
command
};
// Add libraries required per platform.
// We need userenv, sockets (Ws2_32), advapi32 for some system calls and bcrypt for random numbers.
// We need userenv, sockets (Ws2_32), and advapi32 to call a system call (for random numbers I think).
#[cfg(windows)]
let command = command
.arg("-luserenv")
.arg("-lWs2_32")
.arg("-ladvapi32")
.arg("-lbcrypt");
let command = command.arg("-luserenv").arg("-lWs2_32").arg("-ladvapi32");
// On unix we need dlopen-related symbols, libmath for a few things, and pthreads.
#[cfg(not(windows))]
let command = command.arg("-ldl").arg("-lm").arg("-pthread");
Expand Down
8 changes: 4 additions & 4 deletions lib/cli/src/commands/inspect.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use crate::store::StoreOptions;
use anyhow::{Context, Result};
use bytesize::ByteSize;
use clap::Clap;
use std::path::PathBuf;
use structopt::StructOpt;
use wasmer::*;

#[derive(Debug, StructOpt)]
#[derive(Debug, Clap)]
/// 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,
}

Expand Down
Loading

0 comments on commit 392f50a

Please sign in to comment.