Skip to main content

Crate omnia

Crate omnia 

Source
Expand description

§Omnia Wasm Runtime

The Omnia Wasm runtime provides a thin wrapper around wasmtime for ergonomic integration of host-based services for WASI components.

It allows you to declaratively assemble a runtime that provides specific capabilities (like HTTP, Key-Value, Messaging) to guest components, backed by real host implementations.

§Quick Start

Use the runtime! macro to configure which WASI interfaces and backends your host runtime needs. This generates a runtime_run function that handles the entire lifecycle.

use omnia::runtime;
use omnia_wasi_http::WasiHttpCtx;
use omnia_wasi_keyvalue::KeyValueDefault;
use omnia_wasi_otel::DefaultOtel;

// Define the runtime with required capabilities
omnia::runtime!({
    "http": WasiHttpCtx,
    "keyvalue": KeyValueDefault,
    "otel": DefaultOtel,
});

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    // Parse command line arguments (provided by the macro-generated Cli)
    let cli = Cli::parse();

    // Run the runtime
    runtime_run(cli).await
}

§Core Traits

The runtime is built around a set of traits that allow services to be plugged in:

TraitPurpose
Host<T>Links a WASI interface (e.g., wasi:http) into the wasmtime::Linker.
Server<S>Starts a server (e.g., HTTP listener, NATS subscriber) to handle incoming requests.
BackendConnects to an external service (e.g., Redis, Postgres) during startup.
StateManages per-request state and provides access to the component instance.
FromEnvConfigures backend connections from environment variables.

§Features

  • jit (default): Enables Cranelift JIT compilation, allowing you to run .wasm files directly. Disable this to only support pre-compiled .bin components (useful for faster startup in production).

§Configuration

The runtime and its included services are configured via environment variables:

  • RUST_LOG: Controls logging verbosity (e.g., info, debug, omnia=trace).
  • OTEL_GRPC_URL: Endpoint for OpenTelemetry collector (if omnia-otel is used).

§Architecture

See the workspace documentation for the full architecture guide and list of available WASI interface crates.

§License

MIT OR Apache-2.0

Macros§

runtime
Generates the runtime infrastructure based on the configuration.

Structs§

Cli
Command line interface for omnia.
Compiled
A compiled WebAssembly component with its associated Linker.

Enums§

Command
Subcommands for the omnia CLI.

Traits§

Backend
Implemented by backend resources to allow the backend to be connected to a WASI component.
FromEnv
Trait for creating connection options from environment variables.
Host
Implemented by all WASI hosts in order to allow the runtime to link their dependencies.
Parser
Parse command-line arguments into Self.
Server
Implemented by WASI hosts that are servers in order to allow the runtime to start them.
State
State trait for WASI components.

Functions§

compile
Compile wasm32-wasip2 component.
create
Build the Wasmtime Engine and Linker for this runtime.

Type Aliases§

FutureResult
Result type for asynchronous operations.

Derive Macros§

Parser
Generates the Parser implementation.