Files
chandra/wit/host/sys.wit
T
nandiandClaude Sonnet 5.5 6aba9b6a4f
CI / test (push) Failing after 22s
Compile the compositor to a wasm component, run by a small wasmtime host
The whole compositor (Wayland server, window manager, scene, rasteriser, shell) now builds as
build/components/compositor.wasm: a component that imports only moonplasma:host/sys
(wit/host/sys.wit: sockets + SCM_RIGHTS, memfd, poll, spawn, files, clock) and exports run().
host-wasm/ is the native side: a wasmtime program implementing that interface with libc.

- compositor/sys: per-target backends (sys_native.mbt over the C shim, sys_wasm.mbt over the WIT
  imports) behind one API; wayland/nested/host/shell/scene/renderer/gfx build for wasm unchanged.
- compositor/app: the entry point (arg parsing + main loop) as a library for both targets;
  --serve keeps refreshing a PNG so a live compositor can be inspected without a display.
- compositor/font, compositor/wasm: wasm-side placeholders (bitmap font; no panel modules yet,
  since a component can't embed a second wasm runtime: that becomes a host import).
- scripts/gen-native-stubs.py: native stand-ins for wasm-only generated imports.
- just compositor-wasm / host-wasm / run-wasm.

Verified: foot connects to the component's socket and renders into it; native build and
tests unchanged (16/23, the same 7 need unbuilt panel modules).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-25 01:41:31 -08:00

61 lines
2.5 KiB
Plaintext

package moonplasma:host@0.1.0;
/// The operating-system surface the compositor component needs, nothing more. The native host
/// implements it with real syscalls; the component holds only integer handles (fds) and bytes.
/// Mirrors compositor/sys.
interface sys {
/// Listen on a unix socket at `path`; -1 on failure.
unix-listen: func(path: string) -> s32;
/// Accept a pending client (non-blocking); -1 when none.
unix-accept: func(listen-fd: s32) -> s32;
unix-connect: func(path: string) -> s32;
close-fd: func(fd: s32);
unlink: func(path: string);
/// 1 when `fd` is readable within `timeout-ms`, 0 on timeout, <0 on error.
poll-read: func(fd: s32, timeout-ms: s32) -> s32;
/// Result of `recvmsg`: byte count (-1 would-block, -2 error, 0 EOF), an fd received over
/// SCM_RIGHTS (-1 when none), and the bytes read.
record received {
count: s32,
fd: s32,
data: list<u8>,
}
recvmsg: func(fd: s32, max-len: u32) -> received;
/// Send `data`, with `send-fd` (or -1) as SCM_RIGHTS; bytes sent or <0.
sendmsg: func(fd: s32, data: list<u8>, send-fd: s32) -> s32;
memfd-create: func(name: string, size: s32) -> s32;
pwrite: func(fd: s32, data: list<u8>, offset: s32) -> s32;
/// Copy `size` bytes of the file behind `fd` (mapped read-only by the host).
mmap-read: func(fd: s32, size: s32) -> list<u8>;
read-file: func(path: string) -> list<u8>;
write-file: func(path: string, data: list<u8>) -> s32;
/// Contents of a small /proc or /sys file ("" when unreadable).
read-proc: func(path: string) -> list<u8>;
mkdir-p: func(path: string) -> bool;
/// Names of the *.desktop files directly in `dir`.
list-desktop-files: func(dir: string) -> list<string>;
sleep-ms: func(ms: s32);
/// Milliseconds on a monotonic clock (event timestamps).
monotonic-ms: func() -> u64;
/// Print a line to the host's stderr.
log: func(message: string);
getpid: func() -> s32;
/// 0 year, 1 month (1-12), 2 day, 3 hour, 4 minute, 5 second, 6 weekday (0 = Sunday).
wall-time-field: func(which: s32) -> s32;
getenv: func(name: string) -> string;
has-exe: func(name: string) -> bool;
/// Launch `cmd` detached with WAYLAND_DISPLAY set to `display`.
spawn: func(cmd: string, display: string) -> bool;
}
/// The compositor as one component: it imports the OS surface and exports its entry point.
world compositor {
import sys;
/// Run the compositor until it exits. `args` are the command-line arguments (without argv[0]).
export run: func(args: list<string>) -> s32;
}