wasi_test_generator/
main.rs

1#[macro_use]
2extern crate serde;
3
4mod set_up_toolchain;
5mod util;
6mod wasi_version;
7mod wasitests;
8
9pub use crate::set_up_toolchain::install_toolchains;
10pub use crate::wasi_version::{
11    ALL_WASI_VERSIONS, LATEST_WASI_VERSION, NIGHTLY_VERSION, WasiVersion,
12};
13pub use crate::wasitests::{WasiOptions, WasiTest, build};
14
15use gumdrop::Options;
16
17#[derive(Debug, Options)]
18pub struct TestGenOptions {
19    /// if you want to specify specific tests to generate
20    #[options(free)]
21    free: Vec<String>,
22    /// Whether to use the current nightly instead of the latest snapshot0 compiler
23    nightly: bool,
24    /// Whether or not to do operations for all versions of WASI or just the latest.
25    all_versions: bool,
26    /// Whether or not the Wasm will be generated.
27    generate_wasm: bool,
28    /// Whether or not the logic to install the needed Rust compilers is run.
29    set_up_toolchain: bool,
30    /// Print the help message
31    help: bool,
32}
33
34fn main() {
35    let opts = TestGenOptions::parse_args_default_or_exit();
36
37    if opts.help {
38        println!("{}", TestGenOptions::usage());
39        std::process::exit(0);
40    }
41
42    let generate_all = opts.all_versions;
43    let set_up_toolchain = opts.set_up_toolchain;
44    let generate_wasm = opts.generate_wasm;
45    let nightly = opts.nightly;
46    let wasi_versions = if generate_all {
47        ALL_WASI_VERSIONS
48    } else if nightly {
49        NIGHTLY_VERSION
50    } else {
51        LATEST_WASI_VERSION
52    };
53
54    // Install the Rust WASI toolchains for each of the versions
55    if set_up_toolchain {
56        install_toolchains(wasi_versions);
57    }
58
59    // Generate the WASI Wasm files
60    if generate_wasm {
61        let specific_tests: Vec<&str> = opts.free.iter().map(|st| st.as_str()).collect();
62        build(wasi_versions, &specific_tests);
63    }
64}