Skip to content

Commit

Permalink
cli: Use Runtime::load_module_sync in runners
Browse files Browse the repository at this point in the history
Remove duplicated code.
  • Loading branch information
theduke committed Jun 21, 2023
1 parent 5dabf58 commit f14f07a
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,29 +566,11 @@ impl ExecutableTarget {
match TargetOnDisk::from_file(path)? {
TargetOnDisk::WebAssemblyBinary | TargetOnDisk::Wat => {
let wasm = std::fs::read(path)?;
let engine = runtime.engine().context("No engine available")?;
pb.set_message("Compiling to WebAssembly");

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()))?
}
};
pb.set_message("Compiling to WebAssembly");
let module = runtime
.load_module_sync(&wasm)
.with_context(|| format!("Unable to compile \"{}\"", path.display()))?;

Ok(ExecutableTarget::WebAssembly {
module,
Expand Down

0 comments on commit f14f07a

Please sign in to comment.