Skip to content

Commit

Permalink
Revert "feat(wasmtime-cli): add async support flag"
Browse files Browse the repository at this point in the history
This reverts commit b743ff2.
  • Loading branch information
eduardomourar committed Aug 26, 2023
1 parent d3c5ec4 commit 09a16ed
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 90 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

2 changes: 0 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ wasmtime-wasi-http = { workspace = true, optional = true }
wasmtime-runtime = { workspace = true }
clap = { workspace = true, features = ["color", "suggestions", "derive"] }
anyhow = { workspace = true }
futures = { workspace = true }
target-lexicon = { workspace = true }
humantime = "2.0.0"
once_cell = { workspace = true }
Expand Down Expand Up @@ -279,7 +278,6 @@ default = [
"jitdump",
"wasmtime/wat",
"wasmtime/parallel-compilation",
"wasmtime/async",
"vtune",
"wasi-nn",
"wasi-threads",
Expand Down
67 changes: 15 additions & 52 deletions src/commands/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,6 @@ fn parse_profile(s: &str) -> Result<Profile> {
}
}

fn run_future<F: futures::Future>(future: F) -> F::Output {
let mut f = Box::pin(future);
futures::executor::block_on(f.as_mut())
}

static AFTER_HELP: Lazy<String> = Lazy::new(|| crate::FLAG_EXPLANATIONS.to_string());

/// Runs a WebAssembly module
Expand Down Expand Up @@ -278,10 +273,6 @@ pub struct RunCommand {
/// removed. For now this is primarily here for testing.
#[clap(long)]
preview2: bool,

/// Indicates that the async support will be enabled
#[clap(long = "async")]
async_support: bool,
}

#[derive(Clone)]
Expand Down Expand Up @@ -340,9 +331,6 @@ impl RunCommand {
}
None => {}
}
if self.async_support {
config.async_support(true);
}

config.wmemcheck(self.wmemcheck);

Expand Down Expand Up @@ -628,12 +616,7 @@ impl RunCommand {
CliLinker::Core(linker) => {
// Use "" as a default module name.
let module = module.unwrap_core();
if self.async_support {
run_future(linker.module_async(&mut *store, "", &module))
} else {
linker.module(&mut *store, "", &module)
}
.context(format!(
linker.module(&mut *store, "", &module).context(format!(
"failed to instantiate {:?}",
self.module_and_args[0]
))?;
Expand Down Expand Up @@ -662,24 +645,17 @@ impl RunCommand {

let component = module.unwrap_component();

let result = if self.async_support {
let (command, _instance) =
run_future(preview2::command::Command::instantiate_async(
&mut *store,
component,
linker,
))?;
run_future(command.wasi_cli_run().call_run(&mut *store))
} else {
let (command, _instance) = preview2::command::sync::Command::instantiate(
&mut *store,
component,
linker,
)?;
command.wasi_cli_run().call_run(&mut *store)
}
.context("failed to invoke `run` function")
.map_err(|e| self.handle_coredump(e));
let (command, _instance) = preview2::command::sync::Command::instantiate(
&mut *store,
&component,
&linker,
)?;

let result = command
.wasi_cli_run()
.call_run(&mut *store)
.context("failed to invoke `run` function")
.map_err(|e| self.handle_coredump(e));

// Translate the `Result<(),()>` produced by wasm into a feigned
// explicit exit here with status 1 if `Err(())` is returned.
Expand Down Expand Up @@ -733,12 +709,7 @@ impl RunCommand {
// Invoke the function and then afterwards print all the results that came
// out, if there are any.
let mut results = vec![Val::null(); ty.results().len()];
let invoke_res = if self.async_support {
run_future(func.call_async(store, &values, &mut results))
} else {
func.call(store, &values, &mut results)
}
.with_context(|| {
let invoke_res = func.call(store, &values, &mut results).with_context(|| {
if let Some(name) = &self.invoke {
format!("failed to invoke `{}`", name)
} else {
Expand Down Expand Up @@ -924,11 +895,7 @@ impl RunCommand {
match linker {
CliLinker::Core(linker) => {
if self.preview2 {
if self.async_support {
preview2::preview1::add_to_linker_async(linker)?;
} else {
preview2::preview1::add_to_linker_sync(linker)?;
}
wasmtime_wasi::preview2::preview1::add_to_linker_sync(linker)?;
self.set_preview2_ctx(store)?;
} else {
wasmtime_wasi::add_to_linker(linker, |host| {
Expand All @@ -939,11 +906,7 @@ impl RunCommand {
}
#[cfg(feature = "component-model")]
CliLinker::Component(linker) => {
if self.async_support {
preview2::command::add_to_linker(linker)?;
} else {
preview2::command::sync::add_to_linker(linker)?;
}
wasmtime_wasi::preview2::command::sync::add_to_linker(linker)?;
self.set_preview2_ctx(store)?;
}
}
Expand Down
35 changes: 0 additions & 35 deletions tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -730,14 +730,6 @@ fn wasi_misaligned_pointer() -> Result<()> {
Ok(())
}

#[test]
fn hello_with_async() -> Result<()> {
let wasm = build_wasm("tests/all/cli_tests/hello_wasi_snapshot1.wat")?;
let stdout = run_wasmtime(&["--disable-cache", "--async", wasm.path().to_str().unwrap()])?;
assert_eq!(stdout, "Hello, world!\n");
Ok(())
}

#[test]
#[ignore] // FIXME(#6811) currently is flaky and may produce no output
fn hello_with_preview2() -> Result<()> {
Expand All @@ -751,20 +743,6 @@ fn hello_with_preview2() -> Result<()> {
Ok(())
}

#[test]
#[ignore] // FIXME(#6811) currently is flaky and may produce no output
fn hello_with_preview2_and_async() -> Result<()> {
let wasm = build_wasm("tests/all/cli_tests/hello_wasi_snapshot1.wat")?;
let stdout = run_wasmtime(&[
"--disable-cache",
"--preview2",
"--async",
wasm.path().to_str().unwrap(),
])?;
assert_eq!(stdout, "Hello, world!\n");
Ok(())
}

#[test]
#[cfg_attr(not(feature = "component-model"), ignore)]
fn component_missing_feature() -> Result<()> {
Expand Down Expand Up @@ -830,19 +808,6 @@ fn run_basic_component() -> Result<()> {
Ok(())
}

#[test]
#[cfg_attr(not(feature = "component-model"), ignore)]
fn run_basic_component_async() -> Result<()> {
let wasm = build_wasm("tests/all/cli_tests/component-basic.wat")?;
run_wasmtime(&[
"--disable-cache",
"--wasm-features=component-model",
"--async",
wasm.path().to_str().unwrap(),
])?;
Ok(())
}

#[test]
#[cfg_attr(not(feature = "component-model"), ignore)]
fn run_precompiled_component() -> Result<()> {
Expand Down

0 comments on commit 09a16ed

Please sign in to comment.