| Crates.io | runtime-macro |
| lib.rs | runtime-macro |
| version | 0.22.0 |
| created_at | 2026-01-06 17:40:39.928997+00 |
| updated_at | 2026-01-06 17:40:39.928997+00 |
| description | Procedural macros for runtime build code generation |
| homepage | https://credibil.io |
| repository | https://github.com/credibil/wrt |
| max_upload_size | |
| id | 2026382 |
| size | 19,923 |
Procedural macros for generating WebAssembly Component Initiator infrastructure.
This crate provides the runtime! macro that generates the necessary runtime infrastructure for executing WebAssembly components with WASI capabilities. Instead of manually managing feature flags and conditional compilation, you declaratively specify which WASI interfaces and backends your runtime needs.
Add buildgen to your dependencies:
[dependencies]
buildgen = { workspace = true }
Then use the runtime! macro to generate your runtime infrastructure:
use buildgen::runtime;
// Import the backend types you want to use
use wasi_http::WasiHttpCtx;
use wasi_otel::DefaultOtel;
use be_mongodb::Client as MongoDb;
use be_nats::Client as Nats;
use be_azure::Client as Azure;
// Generate runtime infrastructure
runtime!({
"http": WasiHttpCtx,
"otel": DefaultOtel,
"blobstore": MongoDb,
"keyvalue": Nats,
"messaging": Nats,
"vault": Azure
});
// The macro generates:
// - RuntimeContext struct with backend connections
// - RuntimeStoreCtx struct with per-instance contexts
// - State trait implementation
// - WASI view trait implementations
// - runtime_run() function
The macro accepts a map-like syntax:
runtime!({
"interface_name": BackendType,
// ...
});
http: HTTP client and server
WasiHttpCtx (marker type, no backend connection needed)otel: OpenTelemetry observability
DefaultOtel (connects to OTEL collector)blobstore: Object/blob storage
MongoDb or Natskeyvalue: Key-value storage
Nats or Redismessaging: Pub/sub messaging
Nats or Kafkavault: Secrets management
Azure (Azure Key Vault)sql: SQL database
Postgresidentity: Identity and authentication
Azure (Azure Identity)websockets: WebSocket connections
WebSocketsCtxImpl (default implementation for development use)The macro generates the following:
A struct holding pre-instantiated components and backend connections:
#[derive(Clone)]
struct RuntimeContext {
instance_pre: InstancePre<RuntimeStoreCtx>,
// ... backend fields
}
Per-instance data shared between the WebAssembly runtime and host functions:
pub struct RuntimeStoreCtx {
pub table: ResourceTable,
pub wasi: WasiCtx,
// ... interface context fields
}
Implements the State trait from the runtime crate, providing methods to create new store contexts and access the pre-instantiated component.
Implements view traits for each configured WASI interface, allowing the WebAssembly guest to call host functions.
A public async function that:
You can create different runtime configurations for different use cases:
// Minimal HTTP server
mod http_runtime {
use wasi_http::WasiHttpCtx;
warp::runtime!({
"http": WasiHttpCtx
});
}
// Full-featured runtime
mod full_runtime {
use wasi_http::WasiHttpCtx;
use wasi_otel::DefaultOtel;
use be_nats::Client as Nats;
warp::runtime!({
"http": WasiHttpCtx,
"otel": DefaultOtel,
"keyvalue": Nats,
"messaging": Nats,
"blobstore": Nats
});
}
Before this macro, runtime configurations were managed through feature flags:
[features]
credibil = ["http-default", "otel-default", "blobstore-mongodb", "keyvalue-nats", "messaging-nats", "vault-azure"]
Now you can declaratively specify your configuration:
#[cfg(feature = "credibil")]
mod credibil_runtime {
warp::runtime!({
"http": WasiHttpCtx,
"otel": DefaultOtel,
"blobstore": MongoDb,
"keyvalue": Nats,
"messaging": Nats,
"vault": Azure
});
}
This provides:
MIT OR Apache-2.0