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, PartialEq)]
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 config = self.common.config(None, None)?;
27 let store = Store::new(&Engine::new(&config)?, ());
28 let mut wast_context = WastContext::new(store);
29
30 wast_context
31 .register_spectest(&SpectestConfig {
32 use_shared_memory: true,
33 suppress_prints: false,
34 })
35 .expect("error instantiating \"spectest\"");
36
37 for script in self.scripts.iter() {
38 wast_context
39 .run_file(script)
40 .with_context(|| format!("failed to run script file '{}'", script.display()))?
41 }
42
43 Ok(())
44 }
45}