Set compiler config to be owned (following wasm-c-api)

This commit is contained in:
Syrus
2020-12-04 02:39:19 -08:00
parent 7a4ad45c9d
commit 13e6f29c29
48 changed files with 87 additions and 95 deletions

View File

@@ -150,19 +150,19 @@ pub fn run_basic_dynamic_function(store: &Store, compiler_name: &str, c: &mut Cr
fn run_static_benchmarks(c: &mut Criterion) {
#[cfg(feature = "llvm")]
{
let store = Store::new(&JIT::new(&wasmer_compiler_llvm::LLVM::new()).engine());
let store = Store::new(&JIT::new(wasmer_compiler_llvm::LLVM::new()).engine());
run_basic_static_function(&store, "llvm", c);
}
#[cfg(feature = "cranelift")]
{
let store = Store::new(&JIT::new(&wasmer_compiler_cranelift::Cranelift::new()).engine());
let store = Store::new(&JIT::new(wasmer_compiler_cranelift::Cranelift::new()).engine());
run_basic_static_function(&store, "cranelift", c);
}
#[cfg(feature = "singlepass")]
{
let store = Store::new(&JIT::new(&wasmer_compiler_singlepass::Singlepass::new()).engine());
let store = Store::new(&JIT::new(wasmer_compiler_singlepass::Singlepass::new()).engine());
run_basic_static_function(&store, "singlepass", c);
}
}
@@ -170,19 +170,19 @@ fn run_static_benchmarks(c: &mut Criterion) {
fn run_dynamic_benchmarks(c: &mut Criterion) {
#[cfg(feature = "llvm")]
{
let store = Store::new(&JIT::new(&wasmer_compiler_llvm::LLVM::new()).engine());
let store = Store::new(&JIT::new(wasmer_compiler_llvm::LLVM::new()).engine());
run_basic_dynamic_function(&store, "llvm", c);
}
#[cfg(feature = "cranelift")]
{
let store = Store::new(&JIT::new(&wasmer_compiler_cranelift::Cranelift::new()).engine());
let store = Store::new(&JIT::new(wasmer_compiler_cranelift::Cranelift::new()).engine());
run_basic_dynamic_function(&store, "cranelift", c);
}
#[cfg(feature = "singlepass")]
{
let store = Store::new(&JIT::new(&wasmer_compiler_singlepass::Singlepass::new()).engine());
let store = Store::new(&JIT::new(wasmer_compiler_singlepass::Singlepass::new()).engine());
run_basic_dynamic_function(&store, "singlepass", c);
}
}

View File

@@ -101,7 +101,7 @@ control:
```diff
- let module = compile(&wasm_bytes[..])?;
+ let engine = JIT::new(&Cranelift::default()).engine();
+ let engine = JIT::new(Cranelift::default()).engine();
+ let store = Store::new(&engine);
+ let module = Module::new(&store, wasm_bytes)?;
- let instance = module.instantiate(&imports)?;

View File

@@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let compiler = Cranelift::default();
// Create the store
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let compiler = LLVM::default();
// Create the store
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -33,7 +33,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let compiler = Singlepass::default();
// Create the store
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -55,7 +55,7 @@ fn main() -> anyhow::Result<()> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -43,7 +43,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// In this situation, the compiler is
// `wasmer_compiler_cranelift`. The compiler is responsible to
// compile the Wasm module into executable code.
let mut compiler_config = Cranelift::default();
let compiler_config = Cranelift::default();
// Here we go.
//
@@ -72,7 +72,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
//
// That's where we specify the target for the compiler.
// Use the native engine.
let engine = Native::new(&mut compiler_config)
let engine = Native::new(compiler_config)
// Here we go.
// Pass the target to the engine! The engine will share
// this information with the compiler.

View File

@@ -88,7 +88,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// are going to store it in a file with the `.so` extension
// for example (or `.dylib`, or `.dll` depending of the
// platform).
let engine = Native::new(&mut compiler_config).engine();
let engine = Native::new(compiler_config).engine();
// Create a store, that holds the engine.
let store = Store::new(&engine);

View File

@@ -42,14 +42,14 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// In this situation, the compiler is
// `wasmer_compiler_cranelift`. The compiler is responsible to
// compile the Wasm module into executable code.
let mut compiler_config = Cranelift::default();
let compiler_config = Cranelift::default();
println!("Creating JIT engine...");
// Define the engine that will drive everything.
//
// In this case, the engine is `wasmer_engine_jit` which roughly
// means that the executable code will live in memory.
let engine = JIT::new(&mut compiler_config).engine();
let engine = JIT::new(compiler_config).engine();
// Create a store, that holds the engine.
let store = Store::new(&engine);

View File

@@ -50,7 +50,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
//
// In this case, the engine is `wasmer_engine_native` which means
// that a native object is going to be generated.
let engine = Native::new(&mut compiler_config).engine();
let engine = Native::new(compiler_config).engine();
// Create a store, that holds the engine.
let store = Store::new(&engine);

View File

@@ -39,7 +39,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -40,7 +40,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -37,7 +37,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -44,7 +44,7 @@ fn main() -> anyhow::Result<()> {
// However for the purposes of showing what's happening, we create a compiler
// (`Cranelift`) and pass it to an engine (`JIT`). We then pass the engine to
// the store and are now ready to compile and run WebAssembly!
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
// We then use our store and Wasm bytes to compile a `Module`.
// A `Module` is a compiled WebAssembly module that isn't ready to execute yet.
let module = Module::new(&store, wasm_bytes)?;

View File

@@ -42,7 +42,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -50,7 +50,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -38,7 +38,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -39,7 +39,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -57,7 +57,7 @@ fn main() -> anyhow::Result<()> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -51,7 +51,7 @@ fn main() -> anyhow::Result<()> {
)?;
// We set up our store with an engine and a compiler.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
// Then compile our Wasm.
let module = Module::new(&store, wasm_bytes)?;
let import_object = imports! {};

View File

@@ -143,7 +143,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Any compiler and any engine do the job here
let compiler = Cranelift::default();
let engine = JIT::new(&compiler).engine();
let engine = JIT::new(compiler).engine();
// Here is where the fun begins

View File

@@ -32,7 +32,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
// Note that we don't need to specify the engine/compiler if we want to use
// the default provided by Wasmer.
// You can use `Store::default()` for that.
let store = Store::new(&JIT::new(&Cranelift::default()).engine());
let store = Store::new(&JIT::new(Cranelift::default()).engine());
println!("Compiling module...");
// Let's compile the Wasm module.

View File

@@ -9,7 +9,7 @@ use wasmer_engine_native::Native;
fuzz_target!(|wasm_bytes: &[u8]| {
let serialized = {
let mut compiler = Cranelift::default();
let store = Store::new(&Native::new(&mut compiler).engine());
let store = Store::new(&Native::new(compiler).engine());
match Module::validate(&store, wasm_bytes) {
Err(_) => return,
Ok(_) => {}

View File

@@ -10,7 +10,7 @@ fuzz_target!(|wasm_bytes: &[u8]| {
let mut compiler = Cranelift::default();
compiler.canonicalize_nans(true);
compiler.enable_verifier();
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
match Module::validate(&store, wasm_bytes) {
Ok(_) => {
let module = Module::new(&store, wasm_bytes).unwrap();

View File

@@ -10,7 +10,7 @@ fuzz_target!(|wasm_bytes: &[u8]| {
let mut compiler = LLVM::default();
compiler.canonicalize_nans(true);
compiler.enable_verifier();
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
match Module::validate(&store, wasm_bytes) {
Ok(_) => {
let module = Module::new(&store, wasm_bytes).unwrap();

View File

@@ -8,7 +8,7 @@ use wasmer_engine_jit::JIT;
fuzz_target!(|wasm_bytes: &[u8]| {
let compiler = Singlepass::default();
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
match Module::validate(&store, wasm_bytes) {
Ok(_) => {
let module = Module::new(&store, wasm_bytes).unwrap();

View File

@@ -9,7 +9,7 @@ use wasmer_engine_native::Native;
fuzz_target!(|wasm_bytes: &[u8]| {
let serialized = {
let mut compiler = Cranelift::default();
let store = Store::new(&Native::new(&mut compiler).engine());
let store = Store::new(&Native::new(compiler).engine());
match Module::validate(&store, wasm_bytes) {
Err(_) => return,
Ok(_) => {}

View File

@@ -8,6 +8,6 @@ use wasmer_engine_jit::JIT;
fuzz_target!(|wasm_bytes: &[u8]| {
let compiler = Cranelift::default();
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
Module::validate(&store, wasm_bytes);
});

View File

@@ -115,7 +115,7 @@ If you wish to use more than one compiler, you can simply create the own store.
```
use wasmer::{Store, JIT, Singlepass};
let engine = JIT::new(&Singlepass::default()).engine();
let engine = JIT::new(Singlepass::default()).engine();
let store = Store::new(&engine);
```"#
);

View File

@@ -80,7 +80,7 @@ impl Default for Store {
// sure this function doesn't emit a compile error even if
// more than one compiler is enabled.
#[allow(unreachable_code)]
fn get_config() -> impl CompilerConfig + Send + Sync {
fn get_config() -> impl CompilerConfig + Send + Sync + 'static {
cfg_if::cfg_if! {
if #[cfg(feature = "default-cranelift")] {
wasmer_compiler_cranelift::Cranelift::default()
@@ -95,13 +95,15 @@ impl Default for Store {
}
#[allow(unreachable_code, unused_mut)]
fn get_engine(mut config: impl CompilerConfig + Send + Sync) -> impl Engine + Send + Sync {
fn get_engine(
mut config: impl CompilerConfig + Send + Sync + 'static,
) -> impl Engine + Send + Sync {
cfg_if::cfg_if! {
if #[cfg(feature = "default-jit")] {
wasmer_engine_jit::JIT::new(&config)
wasmer_engine_jit::JIT::new(config)
.engine()
} else if #[cfg(feature = "default-native")] {
wasmer_engine_native::Native::new(&mut config)
wasmer_engine_native::Native::new(config)
.engine()
} else {
compile_error!("No default engine chosen")

View File

@@ -136,7 +136,7 @@ cfg_if! {
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
let compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(JIT::new(&*compiler_config).engine());
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(JIT::new(*compiler_config).engine());
Box::new(wasm_engine_t { inner: engine })
}
}
@@ -154,7 +154,7 @@ cfg_if! {
#[no_mangle]
pub extern "C" fn wasm_engine_new() -> Box<wasm_engine_t> {
let mut compiler_config: Box<dyn CompilerConfig> = get_default_compiler_config();
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(Native::new(&mut *compiler_config).engine());
let engine: Arc<dyn Engine + Send + Sync> = Arc::new(Native::new( *compiler_config).engine());
Box::new(wasm_engine_t { inner: engine })
}
}
@@ -243,7 +243,7 @@ pub extern "C" fn wasm_engine_new_with_config(
wasmer_engine_t::JIT => {
cfg_if! {
if #[cfg(feature = "jit")] {
Arc::new(JIT::new(&*compiler_config).engine())
Arc::new(JIT::new(*compiler_config).engine())
} else {
return return_with_error("Wasmer has not been compiled with the `jit` feature.");
}
@@ -252,7 +252,7 @@ pub extern "C" fn wasm_engine_new_with_config(
wasmer_engine_t::NATIVE => {
cfg_if! {
if #[cfg(feature = "native")] {
Arc::new(Native::new(&mut *compiler_config).engine())
Arc::new(Native::new( *compiler_config).engine())
} else {
return return_with_error("Wasmer has not been compiled with the `native` feature.");
}

View File

@@ -138,7 +138,7 @@ impl CompilerOptions {
let engine: Box<dyn Engine + Send + Sync> = match engine_type {
#[cfg(feature = "jit")]
EngineType::JIT => Box::new(
wasmer_engine_jit::JIT::new(&*compiler_config)
wasmer_engine_jit::JIT::new(*compiler_config)
.features(features)
.target(target)
.engine(),
@@ -147,7 +147,7 @@ impl CompilerOptions {
EngineType::Native => {
let mut compiler_config = compiler_config;
Box::new(
wasmer_engine_native::Native::new(&mut *compiler_config)
wasmer_engine_native::Native::new(*compiler_config)
.target(target)
.features(features)
.engine(),

View File

@@ -18,7 +18,7 @@ use wasmer_compiler_cranelift::Cranelift;
let compiler = Cranelift::new();
// Put it into an engine and add it to the store
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
```
*Note: you can find a [full working example using Cranelift compiler

View File

@@ -38,10 +38,8 @@ pub struct CraneliftCompiler {
impl CraneliftCompiler {
/// Creates a new Cranelift compiler
pub fn new(config: &Cranelift) -> Self {
Self {
config: config.clone(),
}
pub fn new(config: Cranelift) -> Self {
Self { config }
}
/// Gets the WebAssembly features for this Compiler

View File

@@ -194,8 +194,8 @@ impl CompilerConfig for Cranelift {
}
/// Transform it into the compiler
fn compiler(&self) -> Box<dyn Compiler + Send> {
Box::new(CraneliftCompiler::new(&self))
fn compiler(self: Box<Self>) -> Box<dyn Compiler + Send> {
Box::new(CraneliftCompiler::new(*self))
}
/// Pushes a middleware onto the back of the middleware chain.

View File

@@ -18,7 +18,7 @@ use wasmer_compiler_llvm::LLVM;
let compiler = LLVM::new();
// Put it into an engine and add it to the store
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
```
*Note: you can find a [full working example using LLVM compiler here][example].*

View File

@@ -27,10 +27,8 @@ pub struct LLVMCompiler {
impl LLVMCompiler {
/// Creates a new LLVM compiler
pub fn new(config: &LLVM) -> LLVMCompiler {
LLVMCompiler {
config: config.clone(),
}
pub fn new(config: LLVM) -> LLVMCompiler {
LLVMCompiler { config }
}
/// Gets the config for this Compiler

View File

@@ -207,8 +207,8 @@ impl CompilerConfig for LLVM {
}
/// Transform it into the compiler.
fn compiler(&self) -> Box<dyn Compiler + Send> {
Box::new(LLVMCompiler::new(&self))
fn compiler(self: Box<Self>) -> Box<dyn Compiler + Send> {
Box::new(LLVMCompiler::new(*self))
}
/// Pushes a middleware onto the back of the middleware chain.

View File

@@ -18,7 +18,7 @@ use wasmer_compiler_singlepass::Singlepass;
let compiler = Singlepass::new();
// Put it into an engine and add it to the store
let store = Store::new(&JIT::new(&compiler).engine());
let store = Store::new(&JIT::new(compiler).engine());
```
*Note: you can find a [full working example using Singlepass compiler

View File

@@ -29,10 +29,8 @@ pub struct SinglepassCompiler {
impl SinglepassCompiler {
/// Creates a new Singlepass compiler
pub fn new(config: &Singlepass) -> Self {
Self {
config: config.clone(),
}
pub fn new(config: Singlepass) -> Self {
Self { config }
}
/// Gets the config for this Compiler

View File

@@ -54,8 +54,8 @@ impl CompilerConfig for Singlepass {
}
/// Transform it into the compiler
fn compiler(&self) -> Box<dyn Compiler + Send> {
Box::new(SinglepassCompiler::new(&self))
fn compiler(self: Box<Self>) -> Box<dyn Compiler + Send> {
Box::new(SinglepassCompiler::new(*self))
}
/// Gets the default features for this compiler in the given target

View File

@@ -37,7 +37,7 @@ pub trait CompilerConfig {
}
/// Gets the custom compiler config
fn compiler(&self) -> Box<dyn Compiler + Send>;
fn compiler(self: Box<Self>) -> Box<dyn Compiler + Send>;
/// Gets the default features for this compiler in the given target
fn default_features_for_target(&self, _target: &Target) -> Features {

View File

@@ -2,18 +2,18 @@ use crate::JITEngine;
use wasmer_compiler::{CompilerConfig, Features, Target};
/// The JIT builder
pub struct JIT<'a> {
pub struct JIT {
#[allow(dead_code)]
compiler_config: Option<&'a dyn CompilerConfig>,
compiler_config: Option<Box<dyn CompilerConfig>>,
target: Option<Target>,
features: Option<Features>,
}
impl<'a> JIT<'a> {
impl JIT {
/// Create a new JIT
pub fn new(compiler_config: &'a dyn CompilerConfig) -> Self {
pub fn new(compiler_config: impl CompilerConfig + 'static) -> Self {
Self {
compiler_config: Some(compiler_config),
compiler_config: Some(Box::new(compiler_config)),
target: None,
features: None,
}

View File

@@ -2,20 +2,20 @@ use crate::NativeEngine;
use wasmer_compiler::{CompilerConfig, Features, Target};
/// The Native builder
pub struct Native<'a> {
compiler_config: Option<&'a dyn CompilerConfig>,
pub struct Native {
compiler_config: Option<Box<dyn CompilerConfig>>,
target: Option<Target>,
features: Option<Features>,
}
impl<'a> Native<'a> {
impl Native {
#[cfg(feature = "compiler")]
/// Create a new Native
pub fn new(compiler_config: &'a mut dyn CompilerConfig) -> Self {
pub fn new(mut compiler_config: impl CompilerConfig + 'static) -> Self {
compiler_config.enable_pic();
Self {
compiler_config: Some(compiler_config),
compiler_config: Some(Box::new(compiler_config)),
target: None,
features: None,
}
@@ -101,7 +101,7 @@ mod tests {
#[should_panic(expected = "compiler not implemented")]
fn build_engine() {
let mut compiler_config = TestCompilerConfig::default();
let native = Native::new(&mut compiler_config);
let native = Native::new(compiler_config);
let _engine = native.engine();
}

View File

@@ -2,20 +2,20 @@ use crate::ObjectFileEngine;
use wasmer_compiler::{CompilerConfig, Features, Target};
/// The ObjectFile builder
pub struct ObjectFile<'a> {
compiler_config: Option<&'a dyn CompilerConfig>,
pub struct ObjectFile {
compiler_config: Option<Box<dyn CompilerConfig>>,
target: Option<Target>,
features: Option<Features>,
}
impl<'a> ObjectFile<'a> {
impl ObjectFile {
#[cfg(feature = "compiler")]
/// Create a new ObjectFile
pub fn new(compiler_config: &'a mut dyn CompilerConfig) -> Self {
pub fn new(mut compiler_config: impl CompilerConfig + 'static) -> Self {
compiler_config.enable_pic();
Self {
compiler_config: Some(compiler_config),
compiler_config: Some(Box::new(compiler_config)),
target: None,
features: None,
}

View File

@@ -38,12 +38,12 @@ pub fn get_compiler(canonicalize_nans: bool) -> impl CompilerConfig {
#[cfg(feature = "test-jit")]
pub fn get_engine(canonicalize_nans: bool) -> impl Engine {
let compiler_config = get_compiler(canonicalize_nans);
JIT::new(&compiler_config).engine()
JIT::new(compiler_config).engine()
}
#[cfg(feature = "test-native")]
pub fn get_engine(canonicalize_nans: bool) -> impl Engine {
let mut compiler_config = get_compiler(canonicalize_nans);
Native::new(&mut compiler_config).engine()
Native::new(compiler_config).engine()
}
pub fn get_store(canonicalize_nans: bool) -> Store {
@@ -58,9 +58,9 @@ pub fn get_store_with_middlewares<I: Iterator<Item = Arc<dyn ModuleMiddleware>>>
compiler_config.push_middleware(x);
}
#[cfg(feature = "test-jit")]
let engine = JIT::new(&compiler_config).engine();
let engine = JIT::new(compiler_config).engine();
#[cfg(feature = "test-native")]
let engine = Native::new(&mut compiler_config).engine();
let engine = Native::new(compiler_config).engine();
Store::new(&engine)
}

View File

@@ -31,17 +31,13 @@ fn _native_prefixer(bytes: &[u8]) -> String {
#[cfg(feature = "test-jit")]
fn get_store(features: Features, try_nan_canonicalization: bool) -> Store {
let compiler_config = get_compiler(try_nan_canonicalization);
Store::new(&JIT::new(&compiler_config).features(features).engine())
Store::new(&JIT::new(compiler_config).features(features).engine())
}
#[cfg(feature = "test-native")]
fn get_store(features: Features, try_nan_canonicalization: bool) -> Store {
let mut compiler_config = get_compiler(try_nan_canonicalization);
Store::new(
&Native::new(&mut compiler_config)
.features(features)
.engine(),
)
Store::new(&Native::new(compiler_config).features(features).engine())
}
pub fn run_wast(wast_path: &str, compiler: &str) -> anyhow::Result<()> {