From 84eb39db96fbc9df5003f21791724386c255dc96 Mon Sep 17 00:00:00 2001 From: Marco Allegretti Date: Wed, 11 Mar 2026 15:15:11 +0100 Subject: [PATCH] feat(runtime): add weft:app/notify WIT package and notify-ready host interface Adds crates/weft-runtime/wit/weft-app.wit defining package weft:app@0.1.0 with interface notify { ready: func() }. In the wasmtime-runtime path: - Registers weft:app/notify@0.1.0 in the component linker before instantiation - ready() prints --- crates/weft-runtime/src/main.rs | 10 ++++++++-- crates/weft-runtime/wit/weft-app.wit | 10 ++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 crates/weft-runtime/wit/weft-app.wit diff --git a/crates/weft-runtime/src/main.rs b/crates/weft-runtime/src/main.rs index 111f668..8fb03bd 100644 --- a/crates/weft-runtime/src/main.rs +++ b/crates/weft-runtime/src/main.rs @@ -127,6 +127,14 @@ fn run_module( let mut linker: Linker = Linker::new(&engine); add_to_linker_sync(&mut linker).context("add WASI to linker")?; + linker + .instance("weft:app/notify@0.1.0") + .context("define weft:app/notify instance")? + .func_wrap("ready", |_: wasmtime::StoreContextMut<'_, State>, ()| { + println!("READY"); + Ok::<(), wasmtime::Error>(()) + }) + .context("define weft:app/notify#ready")?; let mut ctx_builder = WasiCtxBuilder::new(); ctx_builder.inherit_stdout().inherit_stderr(); @@ -150,8 +158,6 @@ fn run_module( }, ); - println!("READY"); - let command = Command::instantiate(&mut store, &component, &linker).context("instantiate component")?; diff --git a/crates/weft-runtime/wit/weft-app.wit b/crates/weft-runtime/wit/weft-app.wit new file mode 100644 index 0000000..6b7c526 --- /dev/null +++ b/crates/weft-runtime/wit/weft-app.wit @@ -0,0 +1,10 @@ +package weft:app@0.1.0; + +/// Host interface that a WEFT app component imports to signal lifecycle events. +interface notify { + /// Signal to the runtime that the application has finished initialising + /// and is ready to serve requests. The runtime forwards this signal to + /// the session supervisor (appd), which transitions the session to the + /// Running state. + ready: func(); +}