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(); +}