Skip to content

Commit

Permalink
Switch runners and "wasmer run" over to WasiEnvBuilder::run_with_stor…
Browse files Browse the repository at this point in the history
…e_async()
  • Loading branch information
Michael-F-Bryan committed Jun 1, 2023
1 parent d38dc60 commit a03df59
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 19 deletions.
12 changes: 6 additions & 6 deletions lib/cli/src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ impl Run {
.resolve_target(&runtime)
.with_context(|| format!("Unable to resolve \"{}\"", self.input))?;

let result = self.execute_target(target, Arc::new(runtime), &mut store);
let result = self.execute_target(target, Arc::new(runtime), store);

if let Err(e) = &result {
self.maybe_save_coredump(e);
Expand All @@ -126,7 +126,7 @@ impl Run {
&self,
executable_target: ExecutableTarget,
runtime: Arc<dyn Runtime + Send + Sync>,
store: &mut Store,
store: Store,
) -> Result<(), Error> {
match executable_target {
ExecutableTarget::WebAssembly { module, path } => {
Expand All @@ -141,15 +141,15 @@ impl Run {
&self,
path: &Path,
module: &Module,
store: &mut Store,
mut store: Store,
runtime: Arc<dyn Runtime + Send + Sync>,
) -> Result<(), Error> {
if wasmer_emscripten::is_emscripten_module(module) {
self.execute_emscripten_module()
} else if wasmer_wasix::is_wasi_module(module) || wasmer_wasix::is_wasix_module(module) {
self.execute_wasi_module(path, module, runtime, store)
} else {
self.execute_pure_wasm_module(module, store)
self.execute_pure_wasm_module(module, &mut store)
}
}

Expand Down Expand Up @@ -296,15 +296,15 @@ impl Run {
wasm_path: &Path,
module: &Module,
runtime: Arc<dyn Runtime + Send + Sync>,
store: &mut Store,
store: Store,
) -> Result<(), Error> {
let program_name = wasm_path.display().to_string();

let builder = self
.wasi
.prepare(module, program_name, self.args.clone(), runtime)?;

builder.run_with_store(module.clone(), store)?;
builder.run_with_store_async(module.clone(), store)?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/runners/wasi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,11 @@ impl crate::runners::Runner for WasiRunner {
.unwrap_or_else(|| Wasi::new(command_name));

let module = crate::runners::compile_module(cmd.atom(), &*runtime)?;
let mut store = runtime.new_store();
let store = runtime.new_store();

self.prepare_webc_env(command_name, &wasi, pkg, runtime)
.context("Unable to prepare the WASI environment")?
.run_with_store(module, &mut store)?;
.run_with_store_async(module, store)?;

Ok(())
}
Expand Down
4 changes: 2 additions & 2 deletions lib/wasi/src/runners/wcgi/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ impl Handler {
);

let task_manager = self.runtime.task_manager();
let mut store = self.runtime.new_store();
let store = self.runtime.new_store();

let done = task_manager
.runtime()
.spawn_blocking(move || builder.run_with_store(module, &mut store))
.spawn_blocking(move || builder.run_with_store_async(module, store))
.map_err(Error::from)
.and_then(|r| async { r.map_err(Error::from) });

Expand Down
17 changes: 8 additions & 9 deletions lib/wasi/src/state/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -845,7 +845,7 @@ impl WasiEnvBuilder {

tasks.task_dedicated(Box::new(move || {
run_with_deep_sleep(store, start, None, env, tx);
}));
}))?;

let result = rx.recv()
.expect("main thread terminated without a result, this normally means a panic occurred within the main thread");
Expand Down Expand Up @@ -918,7 +918,7 @@ fn run_with_deep_sleep(
if errno != Errno::Success {
let exit_code = ExitCode::from(errno);
env.cleanup(&mut store, Some(exit_code));
sender.send(Err(WasiRuntimeError::Wasi(WasiError::Exit(exit_code))));
let _ = sender.send(Err(WasiRuntimeError::Wasi(WasiError::Exit(exit_code))));
return;
}
}
Expand All @@ -942,16 +942,15 @@ fn handle_result(

let tasks = env.data(&store).tasks().clone();
let rewind = work.rewind;
let respawn = {
let env = env.clone();
move |ctx, store, res| {
run_with_deep_sleep(store, start, Some((rewind, res)), env, sender)
}
let respawn = move |ctx, store, res| {
run_with_deep_sleep(store, start, Some((rewind, res)), ctx, sender)
};

// Spawns the WASM process after a trigger
unsafe {
tasks.resume_wasm_after_poller(Box::new(respawn), env, store, work.trigger);
tasks
.resume_wasm_after_poller(Box::new(respawn), env, store, work.trigger)
.unwrap();
}

return;
Expand All @@ -963,7 +962,7 @@ fn handle_result(

let (result, exit_code) = wasi_exit_code(result);
env.cleanup(&mut store, Some(exit_code));
sender.send(result);
let _ = sender.send(result);
}

/// Builder for preopened directories.
Expand Down

0 comments on commit a03df59

Please sign in to comment.