diff --git a/lib/cli/src/commands/run.rs b/lib/cli/src/commands/run.rs index b5184b262bb..c48f28cfe82 100644 --- a/lib/cli/src/commands/run.rs +++ b/lib/cli/src/commands/run.rs @@ -34,6 +34,7 @@ use wasmer_wasix::{ bin_factory::BinaryPackage, runners::{MappedDirectory, Runner}, runtime::{ + module_cache::{CacheError, ModuleHash}, package_loader::PackageLoader, resolver::{PackageSpecifier, QueryError}, }, @@ -567,7 +568,28 @@ impl ExecutableTarget { let wasm = std::fs::read(path)?; let engine = runtime.engine().context("No engine available")?; pb.set_message("Compiling to WebAssembly"); - let module = Module::new(&engine, wasm)?; + + let tasks = runtime.task_manager(); + let module_cache = runtime.module_cache(); + let module_hash = ModuleHash::sha256(&wasm); + + let module = match tasks.block_on(module_cache.load(module_hash, &engine)) { + Ok(m) => m, + Err(e) => { + if !matches!(e, CacheError::NotFound) { + tracing::warn!( + module.path=%path.display(), + module.hash=%module_hash, + error=&e as &dyn std::error::Error, + "Unable to deserialize the pre-compiled module from the module cache", + ); + } + + Module::new(&engine, &wasm) + .with_context(|| format!("Unable to compile \"{}\"", path.display()))? + } + }; + Ok(ExecutableTarget::WebAssembly { module, path: path.to_path_buf(),