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

Add more CLI flags for wasm features #917

Merged
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
14 changes: 12 additions & 2 deletions crates/api/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,18 @@ impl Config {
/// be enabled through this method for appropriate wasm modules.
///
/// 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.
///
/// [threads]: https://github.com/webassembly/threads
pub fn wasm_threads(&mut self, enable: bool) -> &mut Self {
self.features.threads = enable;
// The threads proposal depends on the bulk memory proposal
if enable {
self.features.bulk_memory = true;
}
self
}

Expand All @@ -90,13 +95,18 @@ impl Config {
/// modules.
///
/// 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.
///
/// [proposal]: https://github.com/webassembly/reference-types
pub fn wasm_reference_types(&mut self, enable: bool) -> &mut Self {
self.features.reference_types = enable;
// The reference types proposal depends on the bulk memory proposal
if enable {
self.features.bulk_memory = true;
}
self
}

Expand Down
20 changes: 3 additions & 17 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! 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 std::{
ffi::{OsStr, OsString},
Expand All @@ -9,7 +9,7 @@ use std::{
};
use structopt::{clap::AppSettings, StructOpt};
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_wasi::{old::snapshot_0::Wasi as WasiSnapshot0, Wasi};

Expand Down Expand Up @@ -96,21 +96,7 @@ impl RunCommand {
init_file_per_thread_logger(prefix);
}

let mut config = Config::new();
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 config = self.common.config()?;
let engine = Engine::new(&config);
let store = Store::new(&engine);

Expand Down
20 changes: 3 additions & 17 deletions src/commands/wast.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//! 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 std::path::PathBuf;
use structopt::{clap::AppSettings, StructOpt};
use wasmtime::{Config, Engine, Store};
use wasmtime::{Engine, Store};
use wasmtime_wast::WastContext;

/// Runs a WebAssembly test script file
Expand Down Expand Up @@ -33,21 +33,7 @@ impl WastCommand {
init_file_per_thread_logger(prefix);
}

let mut config = Config::new();
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 config = self.common.config()?;
let store = Store::new(&Engine::new(&config));
let mut wast_context = WastContext::new(store);

Expand Down
52 changes: 42 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ struct CommonOptions {
#[structopt(long)]
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
#[structopt(long, conflicts_with = "cranelift")]
lightbeam: bool,
Expand All @@ -103,18 +123,30 @@ struct CommonOptions {
}

impl CommonOptions {
fn configure_cache(&self, config: &mut Config) -> Result<()> {
if self.disable_cache {
return Ok(());
fn config(&self) -> Result<Config> {
let mut config = Config::new();
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 {
Some(path) => {
config.cache_config_load(path)?;
}
None => {
config.cache_config_load_default()?;
if !self.disable_cache {
match &self.config {
Some(path) => {
config.cache_config_load(path)?;
}
None => {
config.cache_config_load_default()?;
}
}
}
Ok(())
Ok(config)
}
}