Add more CLI flags for wasm features (#917)
* Add more CLI flags for wasm features This commit adds a few more flags to enable wasm features via the CLI, mirroring the existing `--enable-simd` flag: * `--enable-reference-types` * `--enable-multi-value` * `--enable-threads` * `--enable-bulk-memory` Additionally the bulk memory feature is now automatically enabled if `reference-types` or `threads` are enabled since those two proposals largely depend on `bulk-memory`. * Add --enable-all to enable all wasm features * Update src/lib.rs Co-Authored-By: Peter Huene <peterhuene@protonmail.com> * Apply suggestions from code review Co-Authored-By: Peter Huene <peterhuene@protonmail.com> Co-authored-by: Peter Huene <peterhuene@protonmail.com>
This commit is contained in:
@@ -70,13 +70,18 @@ impl Config {
|
|||||||
/// be enabled through this method for appropriate wasm modules.
|
/// be enabled through this method for appropriate wasm modules.
|
||||||
///
|
///
|
||||||
/// This feature gates items such as shared memories and atomic
|
/// This feature gates items such as shared memories and atomic
|
||||||
/// instructions.
|
/// instructions. Note that enabling the threads feature will
|
||||||
|
/// also enable the bulk memory feature.
|
||||||
///
|
///
|
||||||
/// This is `false` by default.
|
/// This is `false` by default.
|
||||||
///
|
///
|
||||||
/// [threads]: https://github.com/webassembly/threads
|
/// [threads]: https://github.com/webassembly/threads
|
||||||
pub fn wasm_threads(&mut self, enable: bool) -> &mut Self {
|
pub fn wasm_threads(&mut self, enable: bool) -> &mut Self {
|
||||||
self.features.threads = enable;
|
self.features.threads = enable;
|
||||||
|
// The threads proposal depends on the bulk memory proposal
|
||||||
|
if enable {
|
||||||
|
self.features.bulk_memory = true;
|
||||||
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,13 +95,18 @@ impl Config {
|
|||||||
/// modules.
|
/// modules.
|
||||||
///
|
///
|
||||||
/// This feature gates items such as the `anyref` type and multiple tables
|
/// This feature gates items such as the `anyref` type and multiple tables
|
||||||
/// being in a module.
|
/// being in a module. Note that enabling the reference types feature will
|
||||||
|
/// also enable the bulk memory feature.
|
||||||
///
|
///
|
||||||
/// This is `false` by default.
|
/// This is `false` by default.
|
||||||
///
|
///
|
||||||
/// [proposal]: https://github.com/webassembly/reference-types
|
/// [proposal]: https://github.com/webassembly/reference-types
|
||||||
pub fn wasm_reference_types(&mut self, enable: bool) -> &mut Self {
|
pub fn wasm_reference_types(&mut self, enable: bool) -> &mut Self {
|
||||||
self.features.reference_types = enable;
|
self.features.reference_types = enable;
|
||||||
|
// The reference types proposal depends on the bulk memory proposal
|
||||||
|
if enable {
|
||||||
|
self.features.bulk_memory = true;
|
||||||
|
}
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! The module that implements the `wasmtime run` command.
|
//! The module that implements the `wasmtime run` command.
|
||||||
|
|
||||||
use crate::{init_file_per_thread_logger, pick_compilation_strategy, CommonOptions};
|
use crate::{init_file_per_thread_logger, CommonOptions};
|
||||||
use anyhow::{bail, Context as _, Result};
|
use anyhow::{bail, Context as _, Result};
|
||||||
use std::{
|
use std::{
|
||||||
ffi::{OsStr, OsString},
|
ffi::{OsStr, OsString},
|
||||||
@@ -9,7 +9,7 @@ use std::{
|
|||||||
};
|
};
|
||||||
use structopt::{clap::AppSettings, StructOpt};
|
use structopt::{clap::AppSettings, StructOpt};
|
||||||
use wasi_common::preopen_dir;
|
use wasi_common::preopen_dir;
|
||||||
use wasmtime::{Config, Engine, Instance, Module, Store};
|
use wasmtime::{Engine, Instance, Module, Store};
|
||||||
use wasmtime_interface_types::ModuleData;
|
use wasmtime_interface_types::ModuleData;
|
||||||
use wasmtime_wasi::{old::snapshot_0::Wasi as WasiSnapshot0, Wasi};
|
use wasmtime_wasi::{old::snapshot_0::Wasi as WasiSnapshot0, Wasi};
|
||||||
|
|
||||||
@@ -96,21 +96,7 @@ impl RunCommand {
|
|||||||
init_file_per_thread_logger(prefix);
|
init_file_per_thread_logger(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut config = Config::new();
|
let config = self.common.config()?;
|
||||||
config
|
|
||||||
.cranelift_debug_verifier(cfg!(debug_assertions))
|
|
||||||
.debug_info(self.common.debug_info)
|
|
||||||
.wasm_simd(self.common.enable_simd)
|
|
||||||
.strategy(pick_compilation_strategy(
|
|
||||||
self.common.cranelift,
|
|
||||||
self.common.lightbeam,
|
|
||||||
)?)?;
|
|
||||||
self.common.configure_cache(&mut config)?;
|
|
||||||
|
|
||||||
if self.common.optimize {
|
|
||||||
config.cranelift_opt_level(wasmtime::OptLevel::Speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
let engine = Engine::new(&config);
|
let engine = Engine::new(&config);
|
||||||
let store = Store::new(&engine);
|
let store = Store::new(&engine);
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
//! The module that implements the `wasmtime wast` command.
|
//! The module that implements the `wasmtime wast` command.
|
||||||
|
|
||||||
use crate::{init_file_per_thread_logger, pick_compilation_strategy, CommonOptions};
|
use crate::{init_file_per_thread_logger, CommonOptions};
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use structopt::{clap::AppSettings, StructOpt};
|
use structopt::{clap::AppSettings, StructOpt};
|
||||||
use wasmtime::{Config, Engine, Store};
|
use wasmtime::{Engine, Store};
|
||||||
use wasmtime_wast::WastContext;
|
use wasmtime_wast::WastContext;
|
||||||
|
|
||||||
/// Runs a WebAssembly test script file
|
/// Runs a WebAssembly test script file
|
||||||
@@ -33,21 +33,7 @@ impl WastCommand {
|
|||||||
init_file_per_thread_logger(prefix);
|
init_file_per_thread_logger(prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut config = Config::new();
|
let config = self.common.config()?;
|
||||||
config
|
|
||||||
.cranelift_debug_verifier(cfg!(debug_assertions))
|
|
||||||
.debug_info(self.common.debug_info)
|
|
||||||
.wasm_simd(self.common.enable_simd)
|
|
||||||
.strategy(pick_compilation_strategy(
|
|
||||||
self.common.cranelift,
|
|
||||||
self.common.lightbeam,
|
|
||||||
)?)?;
|
|
||||||
self.common.configure_cache(&mut config)?;
|
|
||||||
|
|
||||||
if self.common.optimize {
|
|
||||||
config.cranelift_opt_level(wasmtime::OptLevel::Speed);
|
|
||||||
}
|
|
||||||
|
|
||||||
let store = Store::new(&Engine::new(&config));
|
let store = Store::new(&Engine::new(&config));
|
||||||
let mut wast_context = WastContext::new(store);
|
let mut wast_context = WastContext::new(store);
|
||||||
|
|
||||||
|
|||||||
52
src/lib.rs
52
src/lib.rs
@@ -93,6 +93,26 @@ struct CommonOptions {
|
|||||||
#[structopt(long)]
|
#[structopt(long)]
|
||||||
enable_simd: bool,
|
enable_simd: bool,
|
||||||
|
|
||||||
|
/// Enable support for reference types
|
||||||
|
#[structopt(long)]
|
||||||
|
enable_reference_types: bool,
|
||||||
|
|
||||||
|
/// Enable support for multi-value functions
|
||||||
|
#[structopt(long)]
|
||||||
|
enable_multi_value: bool,
|
||||||
|
|
||||||
|
/// Enable support for Wasm threads
|
||||||
|
#[structopt(long)]
|
||||||
|
enable_threads: bool,
|
||||||
|
|
||||||
|
/// Enable support for bulk memory instructions
|
||||||
|
#[structopt(long)]
|
||||||
|
enable_bulk_memory: bool,
|
||||||
|
|
||||||
|
/// Enable all experimental Wasm features
|
||||||
|
#[structopt(long)]
|
||||||
|
enable_all: bool,
|
||||||
|
|
||||||
/// Use Lightbeam for all compilation
|
/// Use Lightbeam for all compilation
|
||||||
#[structopt(long, conflicts_with = "cranelift")]
|
#[structopt(long, conflicts_with = "cranelift")]
|
||||||
lightbeam: bool,
|
lightbeam: bool,
|
||||||
@@ -103,18 +123,30 @@ struct CommonOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl CommonOptions {
|
impl CommonOptions {
|
||||||
fn configure_cache(&self, config: &mut Config) -> Result<()> {
|
fn config(&self) -> Result<Config> {
|
||||||
if self.disable_cache {
|
let mut config = Config::new();
|
||||||
return Ok(());
|
config
|
||||||
|
.cranelift_debug_verifier(cfg!(debug_assertions))
|
||||||
|
.debug_info(self.debug_info)
|
||||||
|
.wasm_bulk_memory(self.enable_bulk_memory || self.enable_all)
|
||||||
|
.wasm_simd(self.enable_simd || self.enable_all)
|
||||||
|
.wasm_reference_types(self.enable_reference_types || self.enable_all)
|
||||||
|
.wasm_multi_value(self.enable_multi_value || self.enable_all)
|
||||||
|
.wasm_threads(self.enable_threads || self.enable_all)
|
||||||
|
.strategy(pick_compilation_strategy(self.cranelift, self.lightbeam)?)?;
|
||||||
|
if self.optimize {
|
||||||
|
config.cranelift_opt_level(wasmtime::OptLevel::Speed);
|
||||||
}
|
}
|
||||||
match &self.config {
|
if !self.disable_cache {
|
||||||
Some(path) => {
|
match &self.config {
|
||||||
config.cache_config_load(path)?;
|
Some(path) => {
|
||||||
}
|
config.cache_config_load(path)?;
|
||||||
None => {
|
}
|
||||||
config.cache_config_load_default()?;
|
None => {
|
||||||
|
config.cache_config_load_default()?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user