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:
Alex Crichton
2020-02-07 04:06:59 -06:00
committed by GitHub
parent 344bf2d6f3
commit a6adf52429
4 changed files with 60 additions and 46 deletions

View File

@@ -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,
@@ -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)
}
}