use std::process::{Command, ExitStatus};
use std::path::{Path, PathBuf};
use std::io;
use std::fs;

fn build_wat(wat_file: &Path, wasm_file: &Path) -> io::Result<ExitStatus>  {
    Command::new("wat2wasm")
        .arg(wat_file)
        .arg("-o")
        .arg(wasm_file)
        .status()
}

fn main() {
    for wat_file in fs::read_dir("wasm").expect("Missing wasm dir") {
        let wat_file = wat_file.unwrap();
        let name = wat_file.file_name();
        let mut wasm_file = PathBuf::from("src/wasm/wasmtests");
        wasm_file.push(name);
        wasm_file.set_extension("wasm");
        build_wat(&wat_file.path(), &wasm_file).unwrap();
    }
}