feat(runtime): add weft-runtime crate skeleton

New crate: weft-runtime — the child process spawned by weft-appd to
execute WEFT application packages.

src/main.rs:
- Parses CLI arguments: <app_id> <session_id> (as per the supervisor
  contract in runtime.rs).
- resolve_package(): searches user store
  (~/.local/share/weft/apps/<app_id>) then system store
  (/usr/share/weft/apps/<app_id>) for a wapp.toml manifest. Overridden
  by WEFT_APP_STORE env var.
- Verifies app.wasm exists in the resolved package directory.
- Stubs Wasmtime execution with a TODO comment; prints 'READY' to
  stdout and exits cleanly so weft-appd's supervisor can complete the
  session lifecycle during development and integration testing.

Tests (2):
- package_store_roots_includes_system_path: system store path present.
- package_store_roots_uses_weft_app_store_when_set: WEFT_APP_STORE
  override replaces default search list.

Also:
- Added weft-runtime to workspace Cargo.toml members.
- wsl-test.sh: added cargo test -p weft-runtime.
This commit is contained in:
Marco Allegretti 2026-03-11 09:27:30 +01:00
parent f47150cec8
commit f38f2eef76
5 changed files with 126 additions and 0 deletions

9
Cargo.lock generated
View file

@ -2429,6 +2429,15 @@ dependencies = [
"wayland-server",
]
[[package]]
name = "weft-runtime"
version = "0.1.0"
dependencies = [
"anyhow",
"tracing",
"tracing-subscriber",
]
[[package]]
name = "weft-servo-shell"
version = "0.1.0"

View file

@ -3,6 +3,7 @@ members = [
"crates/weft-appd",
"crates/weft-build-meta",
"crates/weft-compositor",
"crates/weft-runtime",
"crates/weft-servo-shell",
]
resolver = "2"

View file

@ -0,0 +1,14 @@
[package]
name = "weft-runtime"
version.workspace = true
edition.workspace = true
rust-version.workspace = true
[[bin]]
name = "weft-runtime"
path = "src/main.rs"
[dependencies]
anyhow = "1.0"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

View file

@ -0,0 +1,98 @@
use std::path::PathBuf;
use anyhow::Context;
fn main() -> anyhow::Result<()> {
tracing_subscriber::fmt()
.with_env_filter(
tracing_subscriber::EnvFilter::try_from_default_env()
.unwrap_or_else(|_| tracing_subscriber::EnvFilter::new("info")),
)
.init();
let args: Vec<String> = std::env::args().collect();
if args.len() < 3 {
anyhow::bail!("usage: weft-runtime <app_id> <session_id>");
}
let app_id = &args[1];
let session_id: u64 = args[2]
.parse()
.with_context(|| format!("invalid session_id: {}", args[2]))?;
tracing::info!(session_id, %app_id, "weft-runtime starting");
let pkg_dir = resolve_package(app_id)?;
tracing::info!(path = %pkg_dir.display(), "package resolved");
let wasm_path = pkg_dir.join("app.wasm");
if !wasm_path.exists() {
anyhow::bail!("app.wasm not found at {}", wasm_path.display());
}
// TODO: Load wasm_path into a Wasmtime Engine and run the module.
// Until Wasmtime is integrated, print READY and exit cleanly so that
// weft-appd can complete the session lifecycle in tests and development.
tracing::info!(session_id, %app_id, wasm = %wasm_path.display(), "Wasmtime integration pending");
println!("READY");
tracing::info!(session_id, %app_id, "exiting");
Ok(())
}
fn resolve_package(app_id: &str) -> anyhow::Result<PathBuf> {
for store_root in package_store_roots() {
let pkg_dir = store_root.join(app_id);
let manifest = pkg_dir.join("wapp.toml");
if manifest.exists() {
return Ok(pkg_dir);
}
}
anyhow::bail!("package '{}' not found in any package store", app_id)
}
fn package_store_roots() -> Vec<PathBuf> {
if let Ok(explicit) = std::env::var("WEFT_APP_STORE") {
return vec![PathBuf::from(explicit)];
}
let mut roots = Vec::new();
if let Ok(home) = std::env::var("HOME") {
roots.push(
PathBuf::from(home)
.join(".local")
.join("share")
.join("weft")
.join("apps"),
);
}
roots.push(PathBuf::from("/usr/share/weft/apps"));
roots
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn package_store_roots_includes_system_path() {
let roots = package_store_roots();
assert!(
roots
.iter()
.any(|p| p == &PathBuf::from("/usr/share/weft/apps"))
);
}
#[test]
fn package_store_roots_uses_weft_app_store_when_set() {
// SAFETY: test binary is single-threaded at this point.
unsafe { std::env::set_var("WEFT_APP_STORE", "/custom/store") };
let roots = package_store_roots();
assert_eq!(roots, vec![PathBuf::from("/custom/store")]);
unsafe { std::env::remove_var("WEFT_APP_STORE") };
}
}

View file

@ -30,5 +30,9 @@ echo ""
echo "==> cargo test -p weft-appd"
cargo test -p weft-appd 2>&1
echo ""
echo "==> cargo test -p weft-runtime"
cargo test -p weft-runtime 2>&1
echo ""
echo "ALL DONE"