diff --git a/lib/cache/src/cache.rs b/lib/cache/src/cache.rs index bdb561719..4ae69c294 100644 --- a/lib/cache/src/cache.rs +++ b/lib/cache/src/cache.rs @@ -20,5 +20,5 @@ pub trait Cache { unsafe fn load(&self, store: &Store, key: WasmHash) -> Result; /// Store a [`Module`] into the cache with the given [`WasmHash`]. - fn store(&mut self, key: WasmHash, module: Module) -> Result<(), Self::SerializeError>; + fn store(&mut self, key: WasmHash, module: &Module) -> Result<(), Self::SerializeError>; } diff --git a/lib/cache/src/filesystem.rs b/lib/cache/src/filesystem.rs index ed9c54aad..054a1081f 100644 --- a/lib/cache/src/filesystem.rs +++ b/lib/cache/src/filesystem.rs @@ -78,7 +78,7 @@ impl Cache for FileSystemCache { Module::deserialize_from_file(&store, new_path_buf) } - fn store(&mut self, key: WasmHash, module: Module) -> Result<(), Self::SerializeError> { + fn store(&mut self, key: WasmHash, module: &Module) -> Result<(), Self::SerializeError> { let filename = key.to_string(); let mut new_path_buf = self.path.clone(); diff --git a/src/commands/run.rs b/src/commands/run.rs index 0a9b894e6..022af5945 100644 --- a/src/commands/run.rs +++ b/src/commands/run.rs @@ -195,7 +195,7 @@ impl Run { } let module = Module::new(&store, &contents)?; // Store the compiled Module in cache - cache.store(hash, module.clone())?; + cache.store(hash, &module)?; Ok(module) } } diff --git a/src/store.rs b/src/store.rs index a14965141..9ffa86126 100644 --- a/src/store.rs +++ b/src/store.rs @@ -2,13 +2,14 @@ //! commands. use crate::common::WasmFeatures; -use anyhow::{Context, Error, Result}; +use anyhow::{Error, Result}; use std::path::PathBuf; use std::str::FromStr; use std::string::ToString; use std::sync::Arc; use structopt::StructOpt; use wasmer::*; +#[cfg(feature = "compiler")] use wasmer_compiler::CompilerConfig; #[derive(Debug, Clone, StructOpt)] @@ -104,13 +105,13 @@ impl StoreOptions { // Auto mode, we choose the best compiler for that platform cfg_if::cfg_if! { if #[cfg(all(feature = "cranelift", target_arch = "x86_64"))] { - return Ok(CompilerType::Cranelift); + Ok(CompilerType::Cranelift) } else if #[cfg(all(feature = "singlepass", target_arch = "x86_64"))] { - return Ok(CompilerType::Singlepass); + Ok(CompilerType::Singlepass) } else if #[cfg(feature = "llvm")] { - return Ok(CompilerType::LLVM); + Ok(CompilerType::LLVM) } else { bail!("There are no available compilers for your architecture"); } @@ -303,7 +304,7 @@ impl StoreOptions { engine.to_string() ), }; - return Ok((engine, engine_type)); + Ok((engine, engine_type)) } } @@ -363,16 +364,14 @@ impl StoreOptions { engine.to_string() ), }; - return Ok((engine, engine_type)); + Ok((engine, engine_type)) } /// Get the store (headless engine) pub fn get_store(&self) -> Result<(Store, EngineType, CompilerType)> { // Get the tunables for the current host let tunables = Tunables::default(); - let (engine, engine_type) = self - .get_engine_headless(tunables) - .with_context(|| "No compilers enabled. Operating in headless mode")?; + let (engine, engine_type) = self.get_engine_headless(tunables)?; let store = Store::new(engine); Ok((store, engine_type, CompilerType::Headless)) }