aboutsummaryrefslogtreecommitdiff
path: root/zkvms_guest_io/src/main.rs
blob: 97cf3fa82c654b26f850dabd61acb5a94be0adb3 (plain) (blame)
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
use clap::Parser;
use std::process::{Command, Stdio};

/// A CLI tool for running and benchmarking a guest program inside all
/// supported zkVMs.
/// This binary has been built with a single guest program in mind.
/// If you want to run or benchmark your own guest program inside a zkVM,
/// head on over to https://github.com/blocksense-network/zkVMs-benchmarks
#[derive(Parser, Debug)]
#[command(about, long_about = None)]
struct Cli {
    /// Ignored zkVMs. Values are substrings of names.
    #[arg(short, long, value_delimiter = ',', num_args = 1..)]
    ignore: Option<Vec<String>>,

    /// Make one failiure stop the entire process
    #[arg(short, long)]
    fail_propagation: bool,

    /// Arguments which are passed to each tool for a single guest and single zkVM
    #[arg(trailing_var_arg = true, allow_hyphen_values = true)]
    zkvm_args: Vec<String>,
}

fn main() {
    let cli = Cli::parse();

    let zkvm_guest_commands: Vec<&str> = env!("PROGRAMS")
        .split(',')
        .filter(|x| !x.is_empty())
        .collect();
    let ignored = cli.ignore.unwrap_or(Vec::new());

    for zkvm_guest_command in zkvm_guest_commands.into_iter() {
        if ignored.iter().any(|i| zkvm_guest_command.contains(i)) {
            continue;
        }

        println!("== Executing {} ==", zkvm_guest_command);

        let output = Command::new(zkvm_guest_command)
            .args(cli.zkvm_args.clone())
            .stdout(Stdio::piped())
            .output();

        if let Err(msg) = output {
            println!("Failed to run command {}!", zkvm_guest_command);
            println!("{msg}");
            if cli.fail_propagation {
                break;
            }
            continue;
        }
        // The if above makes sure this is an Ok
        let output = output.unwrap();

        if !output.stdout.is_empty() {
            print!(
                "{}",
                String::from_utf8(output.stdout).expect("failed to convert stdout to String")
            );
        }
        if !output.stderr.is_empty() {
            print!(
                "{}",
                String::from_utf8(output.stderr).expect("failed to convert stderr to String")
            );
        }

        if cli.fail_propagation && !output.status.success() {
            break;
        }
    }
}