Skip to content

Commit

Permalink
Return impl Compiler from default_compiler to fix compilation with fe…
Browse files Browse the repository at this point in the history
…atures
  • Loading branch information
bjfish committed May 14, 2019
1 parent 7e00bef commit bef9f12
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ test:
# cargo test --all --exclude wasmer-emscripten -- --test-threads=1 $(runargs)
cargo test --manifest-path lib/spectests/Cargo.toml --features clif
cargo test --manifest-path lib/spectests/Cargo.toml --features llvm
cargo test --manifest-path lib/runtime/Cargo.toml --features llvm
cargo build -p wasmer-runtime-c-api
cargo test -p wasmer-runtime-c-api -- --nocapture

test-singlepass:
cargo test --manifest-path lib/spectests/Cargo.toml --features singlepass
cargo test --manifest-path lib/runtime/Cargo.toml --features singlepass

test-emscripten-llvm:
cargo test --manifest-path lib/emscripten/Cargo.toml --features llvm -- --test-threads=1 $(runargs)
Expand Down
2 changes: 1 addition & 1 deletion lib/runtime-c-api/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ pub unsafe extern "C" fn wasmer_module_deserialize(
let serialized_module: &[u8] = &*(serialized_module as *const &[u8]);

match Artifact::deserialize(serialized_module) {
Ok(artifact) => match load_cache_with(artifact, default_compiler()) {
Ok(artifact) => match load_cache_with(artifact, &default_compiler()) {
Ok(deserialized_module) => {
*module = Box::into_raw(Box::new(deserialized_module)) as _;
wasmer_result_t::WASMER_OK
Expand Down
4 changes: 3 additions & 1 deletion lib/runtime/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ impl Cache for FileSystemCache {
let mmap = unsafe { Mmap::map(&file)? };

let serialized_cache = Artifact::deserialize(&mmap[..])?;
unsafe { wasmer_runtime_core::load_cache_with(serialized_cache, super::default_compiler()) }
unsafe {
wasmer_runtime_core::load_cache_with(serialized_cache, &super::default_compiler())
}
}

fn store(&mut self, key: WasmHash, module: Module) -> Result<(), CacheError> {
Expand Down
14 changes: 4 additions & 10 deletions lib/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ use wasmer_runtime_core::backend::{Compiler, CompilerConfig};
/// # Errors:
/// If the operation fails, the function returns `Err(error::CompileError::...)`.
pub fn compile(wasm: &[u8]) -> error::CompileResult<Module> {
wasmer_runtime_core::compile_with(&wasm[..], default_compiler())
wasmer_runtime_core::compile_with(&wasm[..], &default_compiler())
}

/// The same as `compile` but takes a `CompilerConfig` for the purpose of
Expand All @@ -140,7 +140,7 @@ pub fn compile_with_config(
wasm: &[u8],
compiler_config: CompilerConfig,
) -> error::CompileResult<Module> {
wasmer_runtime_core::compile_with_config(&wasm[..], default_compiler(), compiler_config)
wasmer_runtime_core::compile_with_config(&wasm[..], &default_compiler(), compiler_config)
}

/// The same as `compile_with_config` but takes a `Compiler` for the purpose of
Expand Down Expand Up @@ -177,9 +177,7 @@ pub fn instantiate(wasm: &[u8], import_object: &ImportObject) -> error::Result<I
}

/// Get a single instance of the default compiler to use.
pub fn default_compiler() -> &'static dyn Compiler {
use lazy_static::lazy_static;

pub fn default_compiler() -> impl Compiler {
#[cfg(feature = "llvm")]
use wasmer_llvm_backend::LLVMCompiler as DefaultCompiler;

Expand All @@ -189,11 +187,7 @@ pub fn default_compiler() -> &'static dyn Compiler {
#[cfg(not(any(feature = "llvm", feature = "singlepass")))]
use wasmer_clif_backend::CraneliftCompiler as DefaultCompiler;

lazy_static! {
static ref DEFAULT_COMPILER: DefaultCompiler = { DefaultCompiler::new() };
}

&*DEFAULT_COMPILER as &dyn Compiler
DefaultCompiler::new()
}

/// The current version of this crate
Expand Down

0 comments on commit bef9f12

Please sign in to comment.