Skip to content

Commit 23b9f3b

Browse files
authored
Add --async[=true|false] flag to wast CLI (#11953)
This was needed to reproduce a fuzz bug recently and seemed like a good piece of functionality to have.
1 parent f95d2da commit 23b9f3b

File tree

3 files changed

+28
-11
lines changed

3 files changed

+28
-11
lines changed

crates/fuzzing/src/oracles.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ pub fn wast_test(u: &mut arbitrary::Unstructured<'_>) -> arbitrary::Result<()> {
758758
} else {
759759
wasmtime_wast::Async::Yes
760760
};
761+
log::debug!("async: {async_:?}");
761762
let engine = Engine::new(&fuzz_config.to_wasmtime()).unwrap();
762763
let mut wast_context = WastContext::new(&engine, async_, move |store| {
763764
fuzz_config.configure_store_epoch_and_fuel(store);

crates/wast/src/wast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ enum Export<'a> {
9292
/// Whether or not to use async APIs when calling wasm during wast testing.
9393
///
9494
/// Passed to [`WastContext::new`].
95-
#[derive(Copy, Clone, PartialEq)]
95+
#[derive(Debug, Copy, Clone, PartialEq)]
9696
#[expect(missing_docs, reason = "self-describing variants")]
9797
pub enum Async {
9898
Yes,

src/commands/wast.rs

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,41 @@ pub struct WastCommand {
3131
/// compiling natively.
3232
#[arg(long)]
3333
precompile_load: Option<PathBuf>,
34+
35+
/// Whether or not to run wasm in async mode.
36+
///
37+
/// This is enabled by default but disabling it may be useful when testing
38+
/// Wasmtime itself.
39+
#[arg(long = "async", require_equals = true, value_name = "true|false")]
40+
async_: Option<Option<bool>>,
3441
}
3542

3643
impl WastCommand {
3744
/// Executes the command.
3845
pub fn execute(mut self) -> Result<()> {
3946
self.common.init_logging()?;
4047

48+
let async_ = optional_flag_with_default(self.async_, true);
4149
let mut config = self.common.config(None)?;
42-
config.async_support(true);
50+
config.async_support(async_);
4351
let engine = Engine::new(&config)?;
44-
let mut wast_context = WastContext::new(&engine, wasmtime_wast::Async::Yes, move |store| {
45-
if let Some(fuel) = self.common.wasm.fuel {
46-
store.set_fuel(fuel).unwrap();
47-
}
48-
if let Some(true) = self.common.wasm.epoch_interruption {
49-
store.epoch_deadline_trap();
50-
store.set_epoch_deadline(1);
51-
}
52-
});
52+
let mut wast_context = WastContext::new(
53+
&engine,
54+
if async_ {
55+
wasmtime_wast::Async::Yes
56+
} else {
57+
wasmtime_wast::Async::No
58+
},
59+
move |store| {
60+
if let Some(fuel) = self.common.wasm.fuel {
61+
store.set_fuel(fuel).unwrap();
62+
}
63+
if let Some(true) = self.common.wasm.epoch_interruption {
64+
store.epoch_deadline_trap();
65+
store.set_epoch_deadline(1);
66+
}
67+
},
68+
);
5369

5470
wast_context.generate_dwarf(optional_flag_with_default(self.generate_dwarf, true));
5571
wast_context

0 commit comments

Comments
 (0)