Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure ExecutableTarget::from_file() for *.wasm files checks the module cache #4019

Merged
merged 3 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 23 additions & 1 deletion lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use wasmer_wasix::{
bin_factory::BinaryPackage,
runners::{MappedDirectory, Runner},
runtime::{
module_cache::{CacheError, ModuleHash},
package_loader::PackageLoader,
resolver::{PackageSpecifier, QueryError},
},
Expand Down Expand Up @@ -575,7 +576,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)) {
ptitSeb marked this conversation as resolved.
Show resolved Hide resolved
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(),
Expand Down