use std::{env, process::ExitCode};
use anyhow::Result;
use lune::Runtime;
pub(crate) mod metadata;
pub(crate) mod tracer;
use self::metadata::Metadata;
pub async fn check() -> Option<Vec<u8>> {
let (is_standalone, patched_bin) = Metadata::check_env().await;
if is_standalone {
Some(patched_bin)
} else {
None
}
}
pub async fn run(patched_bin: impl AsRef<[u8]>) -> Result<ExitCode> {
let args = env::args().skip(1).collect::<Vec<_>>();
let meta = Metadata::from_bytes(patched_bin).expect("must be a standalone binary");
let mut rt = Runtime::new()?.with_args(args);
let result = rt.run_custom("STANDALONE", meta.bytecode).await;
Ok(match result {
Err(err) => {
eprintln!("{err}");
ExitCode::FAILURE
}
Ok(values) => ExitCode::from(values.status()),
})
}