-
-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.rs
53 lines (50 loc) · 1.63 KB
/
main.rs
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
//! SPDX-License-Identifier: MIT
//!
//! Copyright (c) 2023, eunomia-bpf
//! All rights reserved.
//!
use anyhow::{anyhow, Context};
use clap::Parser;
use flexi_logger::Logger;
use log_format::my_log_format;
use std::fs;
use wasm_bpf_rs::{run_wasm_bpf_module, Config};
mod log_format;
#[derive(Parser, Debug)]
#[command(
author,
version,
about,
long_about = "A WebAssembly runtime for eBPF user-space programs."
)]
struct CommandArgs {
#[arg(help = "The WebAssembly Module file to run")]
wasm_module_file: String,
#[arg(long, help = "Display more logs")]
verbose: bool,
#[arg(short = 'm', long, help = "Wrapper module name", default_value_t = String::from("callback-wrapper"))]
wrapper_module_name: String,
#[arg(short = 'c', long, help = "Callback export name", default_value_t = String::from("go-callback"))]
callback_export_name: String,
#[arg(help = "Arguments that will be passed to the Wasm program")]
args_to_wasm: Vec<String>,
}
fn main() -> anyhow::Result<()> {
let args = CommandArgs::parse();
Logger::try_with_str(if args.verbose { "debug" } else { "info" })?
.format(my_log_format)
.start()?;
let mut args_to_wasm = args.args_to_wasm;
args_to_wasm.insert(0, args.wasm_module_file.clone());
let binary = fs::read(&args.wasm_module_file)
.with_context(|| anyhow!("Failed to read wasm module file"))?;
run_wasm_bpf_module(
&binary,
&args_to_wasm[..],
Config {
callback_export_name: args.callback_export_name,
wrapper_module_name: args.wrapper_module_name,
..Default::default()
},
)
}