1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
use crate::{init_file_per_thread_logger, CommonOptions};
use anyhow::{Context as _, Result};
use std::path::PathBuf;
use structopt::{clap::AppSettings, StructOpt};
use wasmtime::{Engine, Store};
use wasmtime_wast::WastContext;
#[derive(StructOpt)]
#[structopt(
name = "wast",
version = env!("CARGO_PKG_VERSION"),
setting = AppSettings::ColoredHelp,
)]
pub struct WastCommand {
#[structopt(flatten)]
common: CommonOptions,
#[structopt(required = true, value_name = "SCRIPT_FILE", parse(from_os_str))]
scripts: Vec<PathBuf>,
}
impl WastCommand {
pub fn execute(&self) -> Result<()> {
if self.common.log_to_files {
let prefix = "wast.dbg.";
init_file_per_thread_logger(prefix);
} else {
pretty_env_logger::init();
}
let config = self.common.config()?;
let store = Store::new(&Engine::new(&config));
let mut wast_context = WastContext::new(store);
wast_context
.register_spectest()
.expect("error instantiating \"spectest\"");
for script in self.scripts.iter() {
wast_context
.run_file(script)
.with_context(|| format!("failed to run script file '{}'", script.display()))?
}
Ok(())
}
}