feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
use std::path::PathBuf;
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
use std::sync::Arc;
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
|
|
|
|
|
use anyhow::Context;
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
use tokio::io::AsyncWriteExt;
|
|
|
|
|
use tokio::sync::Mutex;
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
mod ipc;
|
|
|
|
|
|
|
|
|
|
use ipc::{AppStateKind, Request, Response};
|
|
|
|
|
|
|
|
|
|
type Registry = Arc<Mutex<SessionRegistry>>;
|
|
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
struct SessionRegistry {
|
|
|
|
|
next_id: u64,
|
|
|
|
|
sessions: std::collections::HashMap<u64, AppStateKind>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl SessionRegistry {
|
|
|
|
|
fn launch(&mut self, _app_id: &str) -> u64 {
|
|
|
|
|
self.next_id += 1;
|
|
|
|
|
let id = self.next_id;
|
|
|
|
|
self.sessions.insert(id, AppStateKind::Starting);
|
|
|
|
|
id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn terminate(&mut self, session_id: u64) -> bool {
|
|
|
|
|
self.sessions.remove(&session_id).is_some()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn running_ids(&self) -> Vec<u64> {
|
|
|
|
|
self.sessions.keys().copied().collect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn state(&self, session_id: u64) -> AppStateKind {
|
|
|
|
|
self.sessions
|
|
|
|
|
.get(&session_id)
|
|
|
|
|
.cloned()
|
|
|
|
|
.unwrap_or(AppStateKind::NotFound)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[tokio::main]
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
async 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();
|
|
|
|
|
|
|
|
|
|
run().await
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn run() -> anyhow::Result<()> {
|
|
|
|
|
let socket_path = appd_socket_path()?;
|
feat(appd): implement IPC server with Unix socket and MessagePack framing
Replaces the skeleton bail with a functional IPC server.
ipc.rs — transport layer:
- Request enum: LaunchApp, TerminateApp, QueryRunning, QueryAppState.
Serialized with serde MessagePack (rmp-serde, SCREAMING_SNAKE_CASE
type tag).
- Response enum: LaunchAck, AppReady, RunningApps, AppState, Error.
- AppStateKind: Starting, Running, Stopping, Stopped, NotFound.
- read_frame / write_frame: async 4-byte LE length-prefixed codec over
any AsyncRead / AsyncWrite.
main.rs — server:
- SessionRegistry: in-memory HashMap<session_id, AppStateKind> with
monotonic ID counter; launch / terminate / running_ids / state.
- run(): creates socket parent directory, removes stale socket, binds
UnixListener, sends sd_notify READY=1, then accept-loops with
ctrl-c / SIGTERM shutdown. Cleans up socket on exit.
- handle_connection(): splits stream into BufReader/BufWriter, reads
request frames, calls dispatch, writes response frames.
- dispatch(): maps Request variants to SessionRegistry operations;
returns typed Response. Wasmtime spawning and compositor client
deferred to later implementation.
New deps: serde (derive), rmp-serde, tokio net/io-util/sync/rt-multi-thread.
2026-03-11 07:25:55 +00:00
|
|
|
|
|
|
|
|
if let Some(parent) = socket_path.parent() {
|
|
|
|
|
std::fs::create_dir_all(parent).with_context(|| format!("create {}", parent.display()))?;
|
|
|
|
|
}
|
|
|
|
|
let _ = std::fs::remove_file(&socket_path);
|
|
|
|
|
|
|
|
|
|
let listener = tokio::net::UnixListener::bind(&socket_path)
|
|
|
|
|
.with_context(|| format!("bind {}", socket_path.display()))?;
|
|
|
|
|
tracing::info!(path = %socket_path.display(), "IPC socket listening");
|
|
|
|
|
|
|
|
|
|
let _ = sd_notify::notify(false, &[sd_notify::NotifyState::Ready]);
|
|
|
|
|
|
|
|
|
|
let registry: Registry = Arc::new(Mutex::new(SessionRegistry::default()));
|
|
|
|
|
|
|
|
|
|
let mut shutdown = std::pin::pin!(tokio::signal::ctrl_c());
|
|
|
|
|
|
|
|
|
|
loop {
|
|
|
|
|
tokio::select! {
|
|
|
|
|
result = listener.accept() => {
|
|
|
|
|
let (stream, _) = result.context("accept")?;
|
|
|
|
|
let reg = Arc::clone(®istry);
|
|
|
|
|
tokio::spawn(async move {
|
|
|
|
|
if let Err(e) = handle_connection(stream, reg).await {
|
|
|
|
|
tracing::warn!(error = %e, "connection error");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
_ = &mut shutdown => {
|
|
|
|
|
tracing::info!("shutting down");
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let _ = std::fs::remove_file(&socket_path);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn handle_connection(
|
|
|
|
|
stream: tokio::net::UnixStream,
|
|
|
|
|
registry: Registry,
|
|
|
|
|
) -> anyhow::Result<()> {
|
|
|
|
|
let (reader, writer) = tokio::io::split(stream);
|
|
|
|
|
let mut reader = tokio::io::BufReader::new(reader);
|
|
|
|
|
let mut writer = tokio::io::BufWriter::new(writer);
|
|
|
|
|
|
|
|
|
|
while let Some(req) = ipc::read_frame(&mut reader).await? {
|
|
|
|
|
tracing::debug!(?req, "request");
|
|
|
|
|
let resp = dispatch(req, ®istry).await;
|
|
|
|
|
ipc::write_frame(&mut writer, &resp).await?;
|
|
|
|
|
writer.flush().await?;
|
|
|
|
|
}
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async fn dispatch(req: Request, registry: &Registry) -> Response {
|
|
|
|
|
match req {
|
|
|
|
|
Request::LaunchApp {
|
|
|
|
|
app_id,
|
|
|
|
|
surface_id: _,
|
|
|
|
|
} => {
|
|
|
|
|
let session_id = registry.lock().await.launch(&app_id);
|
|
|
|
|
tracing::info!(session_id, %app_id, "launched");
|
|
|
|
|
Response::LaunchAck { session_id }
|
|
|
|
|
}
|
|
|
|
|
Request::TerminateApp { session_id } => {
|
|
|
|
|
let found = registry.lock().await.terminate(session_id);
|
|
|
|
|
if found {
|
|
|
|
|
tracing::info!(session_id, "terminated");
|
|
|
|
|
Response::AppState {
|
|
|
|
|
session_id,
|
|
|
|
|
state: AppStateKind::Stopped,
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
Response::Error {
|
|
|
|
|
code: 1,
|
|
|
|
|
message: format!("session {session_id} not found"),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Request::QueryRunning => {
|
|
|
|
|
let session_ids = registry.lock().await.running_ids();
|
|
|
|
|
Response::RunningApps { session_ids }
|
|
|
|
|
}
|
|
|
|
|
Request::QueryAppState { session_id } => {
|
|
|
|
|
let state = registry.lock().await.state(session_id);
|
|
|
|
|
Response::AppState { session_id, state }
|
|
|
|
|
}
|
|
|
|
|
}
|
feat(appd): add weft-appd skeleton crate and service unit
New crate implementing the application daemon entry point:
- crates/weft-appd/Cargo.toml: tokio (current-thread runtime), anyhow,
sd-notify, tracing dependencies
- crates/weft-appd/src/main.rs: async run() resolves IPC socket path
from WEFT_APPD_SOCKET or XDG_RUNTIME_DIR/weft/appd.sock; stubs for
AppRegistry, IpcServer, CompositorClient, RuntimeSupervisor,
CapabilityBroker, ResourceController per WEFT-OS-APPD-DESIGN.md;
sd_notify(READY=1) to be sent after IpcServer bind + CompositorClient
connect
- infra/systemd/weft-appd.service: Type=notify, Requires+After
weft-compositor.service, After servo-shell.service
Also fix two winit backend issues that were present in the working tree:
- remove spurious mut on display binding (never mutated after init)
- wrap std::env::set_var in unsafe block (required since Rust 1.80)
2026-03-11 00:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn appd_socket_path() -> anyhow::Result<PathBuf> {
|
|
|
|
|
if let Ok(p) = std::env::var("WEFT_APPD_SOCKET") {
|
|
|
|
|
return Ok(PathBuf::from(p));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let runtime_dir = std::env::var("XDG_RUNTIME_DIR").context("XDG_RUNTIME_DIR not set")?;
|
|
|
|
|
|
|
|
|
|
Ok(PathBuf::from(runtime_dir).join("weft/appd.sock"))
|
|
|
|
|
}
|