Reduce number of crates needed for Config usage

This commit is an attempt to reduce the number of crates necessary to
link to when using `wasmtime::Config` in "default mode" or with only one
or two tweaks. The change moves to a builder-style pattern for `Config`
to only require importing crates as necessary if you configure a
particular setting. This then also propagates that change to `Context`
as well by taking a `Config` instead of requiring that all arguments are
passed alone.
This commit is contained in:
Alex Crichton
2019-11-13 08:00:30 -08:00
parent 98266498af
commit fb60a21930
8 changed files with 88 additions and 96 deletions

View File

@@ -3,7 +3,6 @@ use cranelift_codegen::settings::{self, Configurable};
use std::fs::File;
use std::{collections::HashMap, path::Path};
use wasmtime_api::{Config, Engine, HostRef, Instance, Module, Store};
use wasmtime_jit::{CompilationStrategy, Features};
pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> anyhow::Result<()> {
// Prepare runtime
@@ -14,13 +13,9 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
.enable("avoid_div_traps")
.context("error while enabling proper division trap")?;
let config = Config::new(
settings::Flags::new(flag_builder),
Features::default(),
false,
CompilationStrategy::Auto,
);
let engine = HostRef::new(Engine::new(config));
let mut config = Config::new();
config.flags(settings::Flags::new(flag_builder));
let engine = HostRef::new(Engine::new(&config));
let store = HostRef::new(Store::new(&engine));
let mut module_registry = HashMap::new();