macro_rules! plug_env {
(@const, $ty:ty, $($wasm:ident),* $(,)?) => { ... };
(@static, $state:expr, $($wasm:ident),* $(,)?) => { ... };
(@inner, @const, $ty:ty, $($wasm:ident),*) => { ... };
(@inner, @static, $state:expr, $($wasm:ident),*) => { ... };
}Expand description
@block or @through Whether to import JavaScript runtime env from vfs, env is automatically imported even if you are not using it, so that you can block it @through if retrieving from JavaScript runtime.
@const or @static Whether to use const or static env. @const if using const env. @static if using static env. @const is faster and small than @static.
// @const
import_wasm!(test_wasm);
use const_struct::*;
use wasi_virt_layer::prelude::*;
#[const_struct]
const VIRTUAL_ENV: VirtualEnvConstState = VirtualEnvConstState {
environ: &["RUST_MIN_STACK=16777216", "HOME=~/"],
};
plug_env!(@const, VirtualEnvTy, test_wasm);// @static
import_wasm!(test_wasm);
use std::sync::{LazyLock, Mutex};
use wasi_virt_layer::prelude::*;
struct VirtualEnvState {
environ: Vec<String>,
}
impl<'a> VirtualEnv<'a> for VirtualEnvState {
type Str = String;
fn get_environ(&mut self) -> &[Self::Str] {
&self.environ
}
}
static VIRTUAL_ENV: LazyLock<Mutex<VirtualEnvState>> = LazyLock::new(|| {
let mut environ = Vec::<String>::new();
environ.push("RUST_MIN_STACK=16777216".into());
environ.push("HOME=~/".into());
Mutex::new(VirtualEnvState { environ })
});
plug_env!(@static, &mut VIRTUAL_ENV.lock().unwrap(), test_wasm);