-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathcli.rs
More file actions
66 lines (56 loc) · 2.22 KB
/
cli.rs
File metadata and controls
66 lines (56 loc) · 2.22 KB
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
use clap::*;
#[derive(Debug, Parser, Clone)]
#[command(name = "lind-boot")]
pub struct CliOptions {
/// todo: Increase logging verbosity (-v, -vv, -vvv)
#[arg(short, long, action = clap::ArgAction::Count)]
pub verbose: u8,
/// Enable debug mode
#[arg(long)]
pub debug: bool,
/// AOT-compile a .wasm file to a .cwasm artifact and exit (no runtime needed)
#[arg(long)]
pub precompile: bool,
/// Enables wasmtime backtrace details. Equivalent to wasmtime binary's
/// WASMTIME_BACKTRACE_DETAILS=1 environment variable.
///
/// Does not need any special requirements for .wasm files, for .cwasm files, this configuration must
/// remain the same during compile and run.
#[arg(long = "wasmtime-backtrace")]
pub wasmtime_backtrace: bool,
/// First item is WASM file (argv[0]), rest are program args (argv[1..])
///
/// Example:
/// lind-wasm prog.wasm a b c
#[arg(value_name = "WASM_FILE", required = true, num_args = 1.., trailing_var_arg = true)]
pub args: Vec<String>,
/// Pass an environment variable to the program.
///
/// The `--env FOO=BAR` form will set the environment variable named `FOO`
/// to the value `BAR` for the guest program using WASI. The `--env FOO`
/// form will set the environment variable named `FOO` to the same value it
/// has in the calling process for the guest, or in other words it will
/// cause the environment variable `FOO` to be inherited.
#[arg(long = "env", number_of_values = 1, value_name = "NAME[=VAL]", value_parser = parse_env_var)]
pub vars: Vec<(String, Option<String>)>,
/// Run performance benchmark with CLOCK_GETTIME (requires the `lind_perf` feature)
#[cfg(feature = "lind_perf")]
#[arg(long)]
pub perf: bool,
/// Run performance benchmarks with TSC (requires the `lind_perf` feature)
#[cfg(feature = "lind_perf")]
#[arg(long)]
pub perftsc: bool,
}
pub fn parse_env_var(s: &str) -> Result<(String, Option<String>), String> {
let mut parts = s.splitn(2, '=');
Ok((
parts.next().unwrap().to_string(),
parts.next().map(|s| s.to_string()),
))
}
impl CliOptions {
pub fn wasm_file(&self) -> &str {
&self.args[0]
}
}