Files
chandra/interface/moonplasma/host/sys/top.mbt
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

275 lines
7.1 KiB
MoonBit

// Generated by `wit-bindgen` 0.63.0. DO NOT EDIT!
///|
/// 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.
pub(all) struct Received {
count : Int; fd : Int; data : FixedArray[Byte]
}
///|
/// Listen on a unix socket at `path`; -1 on failure.
pub fn unix_listen(path : String) -> Int {
let ptr = mbt_ffi_str2ptr(path)
let result : Int = wasmImportUnixListen(ptr, path.length());
let ret = result
mbt_ffi_free(ptr)
return ret
}
///|
/// Accept a pending client (non-blocking); -1 when none.
pub fn unix_accept(listen_fd : Int) -> Int {
let result : Int = wasmImportUnixAccept(listen_fd);
let ret = result
return ret
}
///|
pub fn unix_connect(path : String) -> Int {
let ptr = mbt_ffi_str2ptr(path)
let result : Int = wasmImportUnixConnect(ptr, path.length());
let ret = result
mbt_ffi_free(ptr)
return ret
}
///|
pub fn close_fd(fd : Int) -> Unit {
wasmImportCloseFd(fd);
}
///|
pub fn unlink(path : String) -> Unit {
let ptr = mbt_ffi_str2ptr(path)
wasmImportUnlink(ptr, path.length());
mbt_ffi_free(ptr)
}
///|
/// 1 when `fd` is readable within `timeout-ms`, 0 on timeout, <0 on error.
pub fn poll_read(fd : Int, timeout_ms : Int) -> Int {
let result : Int = wasmImportPollRead(fd, timeout_ms);
let ret = result
return ret
}
///|
pub fn recvmsg(fd : Int, max_len : UInt) -> Received {
let return_area = mbt_ffi_malloc(16)
wasmImportRecvmsg(fd, (max_len).reinterpret_as_int(), return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 8), mbt_ffi_load32((return_area) + 12))
let ret = Received::{count : mbt_ffi_load32((return_area) + 0), fd : mbt_ffi_load32((return_area) + 4), data : result}
mbt_ffi_free(return_area)
return ret
}
///|
/// Send `data`, with `send-fd` (or -1) as SCM_RIGHTS; bytes sent or <0.
pub fn sendmsg(fd : Int, data : FixedArray[Byte], send_fd : Int) -> Int {
let ptr = mbt_ffi_bytes2ptr(data)
let result : Int = wasmImportSendmsg(fd, ptr, data.length(), send_fd);
let ret = result
mbt_ffi_free(ptr)
return ret
}
///|
pub fn memfd_create(name : String, size : Int) -> Int {
let ptr = mbt_ffi_str2ptr(name)
let result : Int = wasmImportMemfdCreate(ptr, name.length(), size);
let ret = result
mbt_ffi_free(ptr)
return ret
}
///|
pub fn pwrite(fd : Int, data : FixedArray[Byte], offset : Int) -> Int {
let ptr = mbt_ffi_bytes2ptr(data)
let result : Int = wasmImportPwrite(fd, ptr, data.length(), offset);
let ret = result
mbt_ffi_free(ptr)
return ret
}
///|
/// Copy `size` bytes of the file behind `fd` (mapped read-only by the host).
pub fn mmap_read(fd : Int, size : Int) -> FixedArray[Byte] {
let return_area = mbt_ffi_malloc(8)
wasmImportMmapRead(fd, size, return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = result
mbt_ffi_free(return_area)
return ret
}
///|
pub fn read_file(path : String) -> FixedArray[Byte] {
let ptr = mbt_ffi_str2ptr(path)
let return_area = mbt_ffi_malloc(8)
wasmImportReadFile(ptr, path.length(), return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = result
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
///|
pub fn write_file(path : String, data : FixedArray[Byte]) -> Int {
let ptr = mbt_ffi_str2ptr(path)
let ptr0 = mbt_ffi_bytes2ptr(data)
let result : Int = wasmImportWriteFile(ptr, path.length(), ptr0, data.length());
let ret = result
mbt_ffi_free(ptr)
mbt_ffi_free(ptr0)
return ret
}
///|
/// Contents of a small /proc or /sys file ("" when unreadable).
pub fn read_proc(path : String) -> FixedArray[Byte] {
let ptr = mbt_ffi_str2ptr(path)
let return_area = mbt_ffi_malloc(8)
wasmImportReadProc(ptr, path.length(), return_area);
let result = mbt_ffi_ptr2bytes(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = result
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
///|
pub fn mkdir_p(path : String) -> Bool {
let ptr = mbt_ffi_str2ptr(path)
let result : Int = wasmImportMkdirP(ptr, path.length());
let ret = (result != 0)
mbt_ffi_free(ptr)
return ret
}
///|
/// Names of the *.desktop files directly in `dir`.
pub fn list_desktop_files(dir : String) -> Array[String] {
let ptr = mbt_ffi_str2ptr(dir)
let return_area = mbt_ffi_malloc(8)
wasmImportListDesktopFiles(ptr, dir.length(), return_area);
let array : Array[String] = [];
for index = 0; index < (mbt_ffi_load32((return_area) + 4)); index = index + 1 {
let iter_base = (mbt_ffi_load32((return_area) + 0)) + (index * 8)
let result = mbt_ffi_ptr2str(mbt_ffi_load32((iter_base) + 0), mbt_ffi_load32((iter_base) + 4))
array.push(result)
}
mbt_ffi_free(mbt_ffi_load32((return_area) + 0))
let ret = array
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
///|
pub fn sleep_ms(ms : Int) -> Unit {
wasmImportSleepMs(ms);
}
///|
/// Milliseconds on a monotonic clock (event timestamps).
pub fn monotonic_ms() -> UInt64 {
let result : Int64 = wasmImportMonotonicMs();
let ret = (result).reinterpret_as_uint64()
return ret
}
///|
/// Print a line to the host's stderr.
pub fn log(message : String) -> Unit {
let ptr = mbt_ffi_str2ptr(message)
wasmImportLog(ptr, message.length());
mbt_ffi_free(ptr)
}
///|
pub fn getpid() -> Int {
let result : Int = wasmImportGetpid();
let ret = result
return ret
}
///|
/// 0 year, 1 month (1-12), 2 day, 3 hour, 4 minute, 5 second, 6 weekday (0 = Sunday).
pub fn wall_time_field(which : Int) -> Int {
let result : Int = wasmImportWallTimeField(which);
let ret = result
return ret
}
///|
pub fn getenv(name : String) -> String {
let ptr = mbt_ffi_str2ptr(name)
let return_area = mbt_ffi_malloc(8)
wasmImportGetenv(ptr, name.length(), return_area);
let result = mbt_ffi_ptr2str(mbt_ffi_load32((return_area) + 0), mbt_ffi_load32((return_area) + 4))
let ret = result
mbt_ffi_free(ptr)
mbt_ffi_free(return_area)
return ret
}
///|
pub fn has_exe(name : String) -> Bool {
let ptr = mbt_ffi_str2ptr(name)
let result : Int = wasmImportHasExe(ptr, name.length());
let ret = (result != 0)
mbt_ffi_free(ptr)
return ret
}
///|
/// Launch `cmd` detached with WAYLAND_DISPLAY set to `display`.
pub fn spawn(cmd : String, display : String) -> Bool {
let ptr = mbt_ffi_str2ptr(cmd)
let ptr0 = mbt_ffi_str2ptr(display)
let result : Int = wasmImportSpawn(ptr, cmd.length(), ptr0, display.length());
let ret = (result != 0)
mbt_ffi_free(ptr)
mbt_ffi_free(ptr0)
return ret
}