Compile the compositor to a wasm component, run by a small wasmtime host
CI / test (push) Failing after 22s
CI / test (push) Failing after 22s
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>
This commit is contained in:
1 parent
92d2b29889
commit
6aba9b6a4f
42 files changed
+3163
-10
No files matched your search
@@ -0,0 +1,233 @@
|
||||
///| Plasmoid host for the compositor-as-a-wasm-component build.
|
||||
///
|
||||
/// The native build runs panel modules itself through wasmer. A component can't embed a second
|
||||
/// wasm runtime, so the module host will become a host import (the native side instantiating the
|
||||
/// modules with wasmtime). Until that import exists, the same API is here with nothing loadable:
|
||||
/// `load` fails, no requests ever arrive, and the panel stays empty.
|
||||
|
||||
///|
|
||||
fn utf8(s : String) -> Bytes {
|
||||
let buf : Array[Byte] = []
|
||||
for ch in s {
|
||||
let code = ch.to_int()
|
||||
if code < 0x80 {
|
||||
buf.push(code.to_byte())
|
||||
} else if code < 0x800 {
|
||||
buf.push((0xC0 | (code >> 6)).to_byte())
|
||||
buf.push((0x80 | (code & 0x3F)).to_byte())
|
||||
} else if code < 0x10000 {
|
||||
buf.push((0xE0 | (code >> 12)).to_byte())
|
||||
buf.push((0x80 | ((code >> 6) & 0x3F)).to_byte())
|
||||
buf.push((0x80 | (code & 0x3F)).to_byte())
|
||||
} else {
|
||||
buf.push((0xF0 | (code >> 18)).to_byte())
|
||||
buf.push((0x80 | ((code >> 12) & 0x3F)).to_byte())
|
||||
buf.push((0x80 | ((code >> 6) & 0x3F)).to_byte())
|
||||
buf.push((0x80 | (code & 0x3F)).to_byte())
|
||||
}
|
||||
}
|
||||
Bytes::from_array(buf)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn pack_tokens(_t : @theme.Tokens) -> Bytes {
|
||||
Bytes::make(64, b'\x00')
|
||||
}
|
||||
|
||||
///| A loaded plasmoid instance.
|
||||
pub(all) struct Plasmoid {
|
||||
handle : Int
|
||||
id : String
|
||||
name : String
|
||||
pref_w : Int
|
||||
pref_h : Int
|
||||
min_w : Int
|
||||
stretch : Bool
|
||||
imports : Array[String]
|
||||
}
|
||||
|
||||
///| Always fails in the component build (see the file comment).
|
||||
pub fn load(_path : String, _tokens : @theme.Tokens) -> Result[Plasmoid, String] {
|
||||
Err("panel modules are not available in the wasm compositor yet")
|
||||
}
|
||||
|
||||
///|
|
||||
pub(all) struct SystemSnapshot {
|
||||
cpu_permille : Int
|
||||
mem_used_kib : Int64
|
||||
mem_total_kib : Int64
|
||||
battery_percent : Int
|
||||
charging : Bool
|
||||
uptime_secs : Int64
|
||||
rx_bps : Int64
|
||||
tx_bps : Int64
|
||||
load_centi : Int
|
||||
}
|
||||
|
||||
///|
|
||||
pub(all) struct WindowEntry {
|
||||
id : UInt64
|
||||
title : String
|
||||
app_id : String
|
||||
focused : Bool
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn set_system(_s : SystemSnapshot) -> Unit {
|
||||
()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn set_windows(_wins : Array[WindowEntry]) -> Unit {
|
||||
()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn take_focus_request() -> UInt64? {
|
||||
None
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Plasmoid::pointer_down(_self : Plasmoid, _x : Int, _y : Int) -> Bool {
|
||||
false
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Plasmoid::unload(_self : Plasmoid) -> Unit {
|
||||
()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Plasmoid::render(
|
||||
_self : Plasmoid,
|
||||
_w : Int,
|
||||
_h : Int,
|
||||
_tokens : @theme.Tokens,
|
||||
) -> Array[@types.DrawOp] {
|
||||
[]
|
||||
}
|
||||
|
||||
///| A popup surface a plasmoid wants shown next to its panel widget.
|
||||
pub(all) struct PopupSurface {
|
||||
w : Int
|
||||
h : Int
|
||||
ops : Array[@types.DrawOp]
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Plasmoid::popup(_self : Plasmoid) -> PopupSurface? {
|
||||
None
|
||||
}
|
||||
|
||||
///| An input event for a plasmoid (mirrors the WIT `input-event`).
|
||||
pub(all) enum PlasmoidEvent {
|
||||
PointerMove(Int, Int)
|
||||
PointerDown(Int, Int)
|
||||
PointerUp(Int, Int)
|
||||
PointerLeave
|
||||
FocusLost
|
||||
KeyDown(String)
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Plasmoid::on_event(_self : Plasmoid, _popup : Bool, _ev : PlasmoidEvent) -> Bool {
|
||||
false
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Plasmoid::imports(self : Plasmoid) -> Array[String] {
|
||||
self.imports
|
||||
}
|
||||
|
||||
///| Rows of host data a module can read through its capability imports.
|
||||
pub(all) struct Table {
|
||||
rows : Array[Byte]
|
||||
mut n : Int
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Table::new() -> Table {
|
||||
{ rows: [], n: 0 }
|
||||
}
|
||||
|
||||
///|
|
||||
fn Table::push32(self : Table, v : Int) -> Unit {
|
||||
for k = 0; k < 4; k = k + 1 {
|
||||
self.rows.push(((v >> (8 * k)) & 0xFF).to_byte())
|
||||
}
|
||||
}
|
||||
|
||||
///| An i32 field.
|
||||
pub fn Table::int(self : Table, v : Int) -> Unit {
|
||||
self.push32(v)
|
||||
}
|
||||
|
||||
///| A string field.
|
||||
pub fn Table::str(self : Table, s : String) -> Unit {
|
||||
let b = utf8(s)
|
||||
self.push32(b.length())
|
||||
for i = 0; i < b.length(); i = i + 1 {
|
||||
self.rows.push(b[i])
|
||||
}
|
||||
}
|
||||
|
||||
///| Finish one row.
|
||||
pub fn Table::end_row(self : Table) -> Unit {
|
||||
self.n = self.n + 1
|
||||
}
|
||||
|
||||
///|
|
||||
pub(all) enum HostTable {
|
||||
Apps
|
||||
Windows
|
||||
Layouts
|
||||
Modules
|
||||
Instances
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn publish(_which : HostTable, _t : Table) -> Unit {
|
||||
()
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn publish_state(_layout_mode : Int, _inspector_on : Bool) -> Unit {
|
||||
()
|
||||
}
|
||||
|
||||
///| Something a module asked the host to do during a call.
|
||||
pub(all) enum HostRequest {
|
||||
Launch(String)
|
||||
FocusWindow(Int)
|
||||
SetLayout(Int)
|
||||
SetInspector(Bool)
|
||||
LoadModule(String)
|
||||
UnloadInstance(String)
|
||||
Browse
|
||||
} derive(Eq, Debug)
|
||||
|
||||
///|
|
||||
pub fn next_request() -> HostRequest? {
|
||||
None
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn list_wasm_files(_dir : String) -> Array[String] {
|
||||
[]
|
||||
}
|
||||
|
||||
///| An in-flight native file-chooser dialog.
|
||||
pub(all) struct Picker {
|
||||
fd : Int
|
||||
buf : Array[Byte]
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Picker::start() -> Picker? {
|
||||
None
|
||||
}
|
||||
|
||||
///|
|
||||
pub fn Picker::poll(_self : Picker) -> String?? {
|
||||
None
|
||||
}
|
||||
Reference in new issue
Block a user