Skip to main content

wasmlet/
lib.rs

1pub mod config;
2mod engine;
3mod host;
4pub mod wasmtime;
5
6use core::fmt::Debug;
7use core::str::FromStr;
8use core::sync::atomic::AtomicU64;
9use core::task::Waker;
10use core::time::Duration;
11
12use std::env::{self, VarError};
13
14use tracing::warn;
15
16pub use self::config::Manifest;
17pub use self::engine::{
18    bindings, wasi, Cmd, Ctx, DynamicWorkloadInvocation, Engine, Wasi, WorkloadInvocation,
19    WorkloadInvocationPayload,
20};
21pub use self::host::{
22    apply_manifest, load_and_apply_manifest, load_manifest, read_and_apply_manifest, read_manifest,
23    Host,
24};
25
26pub const EPOCH_INTERVAL: Duration = Duration::from_millis(1);
27
28pub static EPOCH_MONOTONIC_NOW: AtomicU64 = AtomicU64::new(0);
29pub static EPOCH_SYSTEM_NOW: AtomicU64 = AtomicU64::new(0);
30
31pub(crate) const NOOP_WAKER: &Waker = Waker::noop();
32
33fn getenv<T>(key: &str) -> Option<T>
34where
35    T: FromStr,
36    T::Err: Debug,
37{
38    match env::var(key).as_deref().map(FromStr::from_str) {
39        Ok(Ok(v)) => Some(v),
40        Ok(Err(err)) => {
41            warn!(?err, "failed to parse `{key}` value, ignoring");
42            None
43        }
44        Err(VarError::NotPresent) => None,
45        Err(VarError::NotUnicode(..)) => {
46            warn!("`{key}` value is not valid UTF-8, ignoring");
47            None
48        }
49    }
50}