wasmtime_cli/commands/
wast.rs1use anyhow::{Context as _, Result};
4use clap::Parser;
5use std::path::PathBuf;
6use wasmtime::{Engine, Store};
7use wasmtime_cli_flags::CommonOptions;
8use wasmtime_wast::{SpectestConfig, WastContext};
9
10#[derive(Parser)]
12pub struct WastCommand {
13 #[command(flatten)]
14 common: CommonOptions,
15
16 #[arg(required = true, value_name = "SCRIPT_FILE")]
18 scripts: Vec<PathBuf>,
19}
20
21impl WastCommand {
22 pub fn execute(mut self) -> Result<()> {
24 self.common.init_logging()?;
25
26 let mut config = self.common.config(None)?;
27 config.async_support(true);
28 let mut store = Store::new(&Engine::new(&config)?, ());
29 if let Some(fuel) = self.common.wasm.fuel {
30 store.set_fuel(fuel)?;
31 }
32 if let Some(true) = self.common.wasm.epoch_interruption {
33 store.epoch_deadline_trap();
34 store.set_epoch_deadline(1);
35 }
36 let mut wast_context = WastContext::new(store, wasmtime_wast::Async::Yes);
37
38 wast_context
39 .register_spectest(&SpectestConfig {
40 use_shared_memory: true,
41 suppress_prints: false,
42 })
43 .expect("error instantiating \"spectest\"");
44
45 for script in self.scripts.iter() {
46 wast_context
47 .run_file(script)
48 .with_context(|| format!("failed to run script file '{}'", script.display()))?
49 }
50
51 Ok(())
52 }
53}