use std::{path::PathBuf, sync::Arc};
use anyhow::Result;
use clap::Parser;
use lunatic_process::{
env::{Environments, LunaticEnvironments},
runtimes::{self},
};
use super::common::{run_wasm, RunWasm};
#[derive(Parser, Debug)]
#[command(version)]
pub struct Args {
#[arg(long, value_name = "DIRECTORY")]
pub dir: Vec<PathBuf>,
#[arg(long)]
pub bench: bool,
#[arg(index = 1)]
pub path: PathBuf,
#[arg(index = 2)]
pub wasm_args: Vec<String>,
#[cfg(feature = "prometheus")]
#[command(flatten)]
prometheus: super::common::PrometheusArgs,
}
pub(crate) async fn start(mut args: Args) -> Result<()> {
#[cfg(feature = "prometheus")]
if args.prometheus.prometheus {
super::common::prometheus(args.prometheus.prometheus_http, None)?;
}
let wasmtime_config = runtimes::wasmtime::default_config();
let runtime = runtimes::wasmtime::WasmtimeRuntime::new(&wasmtime_config)?;
let envs = Arc::new(LunaticEnvironments::default());
let env = envs.create(1).await;
if args.bench {
args.wasm_args.push("--bench".to_owned());
}
run_wasm(RunWasm {
path: args.path,
wasm_args: args.wasm_args,
dir: args.dir,
runtime,
envs,
env,
distributed: None,
})
.await
}