Skip to content

Commit

Permalink
Replace WebAssembly feature CLI options with --wasm-features.
Browse files Browse the repository at this point in the history
This commit hides the existing WebAssembly feature CLI options (e.g.
`--enable-simd`) and adds a `--wasm-features` flag that enables multiple
(or all) WebAssembly features.

Features can be disabled by prefixing the value with `-`, e.g.
`--wasm-features=-simd`.
  • Loading branch information
peterhuene committed Mar 31, 2021
1 parent 52bbe00 commit a097950
Show file tree
Hide file tree
Showing 9 changed files with 356 additions and 58 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ log = "0.4.8"
rayon = "1.2.1"
humantime = "2.0.0"
wasmparser = "0.77.0"
lazy_static = "1.4.0"

[dev-dependencies]
env_logger = "0.8.1"
Expand Down
10 changes: 7 additions & 3 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@

### Changed

* Wasmtime CLI options to enable WebAssembly features have been replaced with a
singular `--wasm-features` option. The previous options are still supported, but
are not displayed in help text.

* Breaking: the CLI option `--cranelift-flags` was changed to `--cranelift-flag`.

* Breaking: the CLI option `--enable-reference-types=false` has been changed to
`--disable-reference-types` as it is enabled by default.
`--wasm-features=-reference-types`.

* Breaking: the CLI option `--enable-multi-value=false` has been changed to
`--disable-multi-value` as it is enabled by default.
`--wasm-features=-multi-value`.

* Breaking: the CLI option `--enable-bulk-memory=false` has been changed to
`--disable-bulk-memory` as it is enabled by default.
`--wasm-features=-bulk-memory`.

* Modules serialized with `Module::serialize` can now be deserialized with
`Module::deserialize` on a compatible host that does not have to match the
Expand Down
4 changes: 2 additions & 2 deletions src/bin/wasmtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use anyhow::Result;
use structopt::{clap::AppSettings, clap::ErrorKind, StructOpt};
use wasmtime_cli::commands::{
CompileCommand, ConfigCommand, RunCommand, WasmToObjCommand, WastCommand, WASM2OBJ_AFTER_HELP,
CompileCommand, ConfigCommand, RunCommand, WasmToObjCommand, WastCommand,
};

/// Wasmtime WebAssembly Runtime
Expand Down Expand Up @@ -43,7 +43,7 @@ enum WasmtimeApp {
/// Runs a WebAssembly module
Run(RunCommand),
/// Translates a WebAssembly module to native object file
#[structopt(name = "wasm2obj", after_help = WASM2OBJ_AFTER_HELP)]
#[structopt(name = "wasm2obj")]
WasmToObj(WasmToObjCommand),
/// Runs a WebAssembly test script file
Wast(WastCommand),
Expand Down
43 changes: 26 additions & 17 deletions src/commands/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,31 @@ use structopt::{
use target_lexicon::Triple;
use wasmtime::{Config, Engine, Module};

lazy_static::lazy_static! {
static ref AFTER_HELP: String = {
format!(
"By default, no CPU features or presets will be enabled for the compilation.\n\
\n\
{}\
\n\
Usage examples:\n\
\n\
Compiling a WebAssembly module for the current platform:\n\
\n \
wasmtime compile example.wasm
\n\
Specifying the output file:\n\
\n \
wasmtime compile -o output.cwasm input.wasm\n\
\n\
Compiling for a specific platform (Linux) and CPU preset (Skylake):\n\
\n \
wasmtime compile --target x86_64-unknown-linux --skylake foo.wasm\n",
crate::WASM_FEATURES.as_str()
)
};
}

/// Compiles a WebAssembly module.
#[derive(StructOpt)]
#[structopt(
Expand All @@ -22,23 +47,7 @@ use wasmtime::{Config, Engine, Module};
group = ArgGroup::with_name("preset-x64"),
group = ArgGroup::with_name("aarch64").multiple(true).conflicts_with_all(&["x64", "preset-x64"]),
group = ArgGroup::with_name("preset-aarch64").conflicts_with_all(&["x64", "preset-x64"]),
after_help = "By default, no CPU flags will be enabled for the compilation.\n\
\n\
Use the various preset and CPU flag options for the environment being targeted.\n\
\n\
Usage examples:\n\
\n\
Compiling a WebAssembly module for the current platform:\n\
\n \
wasmtime compile example.wasm
\n\
Specifying the output file:\n\
\n \
wasmtime compile -o output.cwasm input.wasm\n\
\n\
Compiling for a specific platform (Linux) and CPU preset (Skylake):\n\
\n \
wasmtime compile --target x86_64-unknown-linux --skylake foo.wasm\n"
after_help = AFTER_HELP.as_str()
)]
pub struct CompileCommand {
#[structopt(flatten)]
Expand Down
8 changes: 7 additions & 1 deletion src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ fn parse_preloads(s: &str) -> Result<(String, PathBuf)> {
Ok((parts[0].into(), parts[1].into()))
}

lazy_static::lazy_static! {
static ref AFTER_HELP: String = {
crate::WASM_FEATURES.to_string()
};
}

/// Runs a WebAssembly module
#[derive(StructOpt)]
#[structopt(name = "run", setting = AppSettings::TrailingVarArg)]
#[structopt(name = "run", setting = AppSettings::TrailingVarArg, after_help = AFTER_HELP.as_str())]
pub struct RunCommand {
#[structopt(flatten)]
common: CommonOptions,
Expand Down
16 changes: 12 additions & 4 deletions src/commands/wasm2obj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,25 @@ use std::{
use structopt::{clap::AppSettings, StructOpt};
use target_lexicon::Triple;

/// The after help text for the `wasm2obj` command.
pub const WASM2OBJ_AFTER_HELP: &str = "The translation is dependent on the environment chosen.\n\
The default is a dummy environment that produces placeholder values.";
lazy_static::lazy_static! {
static ref AFTER_HELP: String = {
format!(
"The translation is dependent on the environment chosen.\n\
The default is a dummy environment that produces placeholder values.\n\
\n\
{}",
crate::WASM_FEATURES.as_str()
)
};
}

/// Translates a WebAssembly module to native object file
#[derive(StructOpt)]
#[structopt(
name = "wasm2obj",
version = env!("CARGO_PKG_VERSION"),
setting = AppSettings::ColoredHelp,
after_help = WASM2OBJ_AFTER_HELP,
after_help = AFTER_HELP.as_str(),
)]
pub struct WasmToObjCommand {
#[structopt(flatten)]
Expand Down
7 changes: 7 additions & 0 deletions src/commands/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@ use structopt::{clap::AppSettings, StructOpt};
use wasmtime::{Engine, Store};
use wasmtime_wast::WastContext;

lazy_static::lazy_static! {
static ref AFTER_HELP: String = {
crate::WASM_FEATURES.to_string()
};
}

/// Runs a WebAssembly test script file
#[derive(StructOpt)]
#[structopt(
name = "wast",
version = env!("CARGO_PKG_VERSION"),
setting = AppSettings::ColoredHelp,
after_help = AFTER_HELP.as_str(),
)]
pub struct WastCommand {
#[structopt(flatten)]
Expand Down
Loading

0 comments on commit a097950

Please sign in to comment.