Make the MoonBit host the default: just run, run-drm and install-session use build/wasmhost
CI / test (push) Failing after 17s

The Rust host stays as a fallback: just run-rust, run-drm-rust, install-session-rust
(session/install.py --rust-host). build-wasmhost.sh fetches the wasmtime C API when it is
missing and replaces build/wasmhost by renaming, so a running dev session keeps its copy.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hiNfjrw2edja7LiRLB
This commit is contained in:
Claude committed 2026-11-25 20:10:51 +00:00
1 parent 2774516abf
commit f33f84c35b
6 files changed
+65 -32

No files matched your search

+5 -3
View File
@@ -1,11 +1,13 @@
# chandra-host # chandra-host (Rust, fallback)
Runs the compositor **as a WebAssembly component**. Runs the compositor **as a WebAssembly component**. The default host is now the MoonBit one in
[`wasmhost/`](../wasmhost/README.md), which builds in seconds; this crate compiles wasmtime (about
2 minutes cold) and is kept as a fallback until it is removed. Both serve the same `wit/host`.
``` ```
just compositor-wasm # build/compositor.wasm (the compositor, a component) just compositor-wasm # build/compositor.wasm (the compositor, a component)
just host-wasm # host-wasm/target/release/chandra-host (this crate) just host-wasm # host-wasm/target/release/chandra-host (this crate)
just run-wasm # both, then run in a window on your current Wayland session just run-rust # both, then run in a window on your current Wayland session
``` ```
The component (`components/compositor`, entry in `compositor/app`) imports exactly one interface, The component (`components/compositor`, entry in `compositor/app`) imports exactly one interface,
+27 -13
View File
@@ -39,8 +39,13 @@ build:
build-release: build-release:
moon build --target native --release --warn-list -a compositor/bin moon build --target native --release --warn-list -a compositor/bin
# Run the compositor, built as a wasm component, in a window on your current Wayland session (close the window or Ctrl-C to stop). Connect clients via `just client`. The panel is empty until panel modules run in the component; `just run-native` has them. # Run the compositor, built as a wasm component, in a window on your current Wayland session (close the window or Ctrl-C to stop). Connect clients via `just client`.
run: compositor-wasm host-wasm modules run: compositor-wasm wasmhost modules
rm -f {{socket}}
build/wasmhost build/compositor.wasm --socket {{socket}} --theme {{theme}} --window
# The same on the Rust host (host-wasm), kept as a fallback while the MoonBit host settles in.
run-rust: compositor-wasm host-wasm modules
rm -f {{socket}} rm -f {{socket}}
host-wasm/target/release/chandra-host build/compositor.wasm --socket {{socket}} --theme {{theme}} --window host-wasm/target/release/chandra-host build/compositor.wasm --socket {{socket}} --theme {{theme}} --window
@@ -71,10 +76,16 @@ run-headless: build modules
{{exe}} --socket {{socket}} --theme {{theme}} {{exe}} --socket {{socket}} --theme {{theme}}
# Run the wasm compositor on the real display (DRM/KMS + libinput, through the host). Run from a login VT (Ctrl+Alt+F3), not inside another session. Ctrl+Alt+Backspace quits, Ctrl+Alt+F<n> switches VT. # Run the wasm compositor on the real display (DRM/KMS + libinput, through the host). Run from a login VT (Ctrl+Alt+F3), not inside another session. Ctrl+Alt+Backspace quits, Ctrl+Alt+F<n> switches VT.
run-drm: compositor-wasm host-wasm modules run-drm: compositor-wasm wasmhost modules
rm -f {{socket}} rm -f {{socket}}
# Let D-Bus-activated helpers (gcr-prompter's keyring unlock prompt, portals) open windows here. # Let D-Bus-activated helpers (gcr-prompter's keyring unlock prompt, portals) open windows here.
-dbus-update-activation-environment --systemd WAYLAND_DISPLAY=$(basename {{socket}}) XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=chandra 2>/dev/null -dbus-update-activation-environment --systemd WAYLAND_DISPLAY=$(basename {{socket}}) XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=chandra 2>/dev/null
build/wasmhost build/compositor.wasm --drm --socket {{socket}} --theme {{theme}}
# The same on the Rust host (host-wasm).
run-drm-rust: compositor-wasm host-wasm modules
rm -f {{socket}}
-dbus-update-activation-environment --systemd WAYLAND_DISPLAY=$(basename {{socket}}) XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=chandra 2>/dev/null
host-wasm/target/release/chandra-host build/compositor.wasm --drm --socket {{socket}} --theme {{theme}} host-wasm/target/release/chandra-host build/compositor.wasm --drm --socket {{socket}} --theme {{theme}}
# The same on the native compositor (system-cc release build), for comparison. # The same on the native compositor (system-cc release build), for comparison.
@@ -83,14 +94,18 @@ run-drm-native: build-release modules
-dbus-update-activation-environment --systemd WAYLAND_DISPLAY=$(basename {{socket}}) XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=chandra 2>/dev/null -dbus-update-activation-environment --systemd WAYLAND_DISPLAY=$(basename {{socket}}) XDG_SESSION_TYPE=wayland XDG_CURRENT_DESKTOP=chandra 2>/dev/null
{{release_exe}} --drm --socket {{socket}} --theme {{theme}} {{release_exe}} --drm --socket {{socket}} --theme {{theme}}
# Install the Chandra login session (display-manager entry): the wasm compositor + its host. Asks for root once. # Install the Chandra login session (display-manager entry): the wasm compositor + its host (the MoonBit host). Asks for root once.
install-session: compositor-wasm host-wasm modules install-session: compositor-wasm wasmhost modules
run0 python3 session/install.py run0 python3 session/install.py
# Dev install: symlink the session into this checkout, so after one root install `just compositor-wasm host-wasm modules` is all a rebuild needs. # Dev install: symlink the session into this checkout, so after one root install `just compositor-wasm wasmhost modules` is all a rebuild needs.
install-session-dev: compositor-wasm host-wasm modules install-session-dev: compositor-wasm wasmhost modules
run0 python3 session/install.py --link run0 python3 session/install.py --link
# Install the login session with the Rust host (host-wasm) instead of the MoonBit one.
install-session-rust: compositor-wasm host-wasm modules
run0 python3 session/install.py --rust-host
# Install the login session with the native compositor instead. # Install the login session with the native compositor instead.
install-session-native: build-release modules install-session-native: build-release modules
run0 python3 session/install.py --native run0 python3 session/install.py --native
@@ -146,12 +161,11 @@ clean-all:
compositor-wasm: compositor-wasm:
scripts/build-compositor-wasm.sh scripts/build-compositor-wasm.sh
# Build the native host that runs the compositor component (wasmtime; implements the sys imports). # Build the host that runs the compositor component (build/wasmhost): MoonBit, linking the prebuilt wasmtime C API, so it builds in seconds.
host-wasm:
cd host-wasm && cargo build --release
# Build the MoonBit host for the compositor component (build/wasmhost): links the prebuilt wasmtime
# C API instead of compiling wasmtime. Work in progress: it will replace host-wasm.
wasmhost: wasmhost:
scripts/build-wasmhost.sh scripts/build-wasmhost.sh
# Build the Rust host (host-wasm/target/release/chandra-host): the fallback, compiles wasmtime (about 2 minutes cold).
host-wasm:
cd host-wasm && cargo build --release
+2 -2
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Build the compositor itself as a wasm component: build/compositor.wasm. # Build the compositor itself as a wasm component: build/compositor.wasm.
# It imports only chandra:host/sys (wit/host/sys.wit) and exports `run`; the native host in # It imports the chandra:host interfaces (wit/host) and exports `run`; the host (wasmhost/,
# host-wasm/ provides the imports. Needs moon and wasm-tools. # build/wasmhost; or the Rust host-wasm/) provides the imports. Needs moon and wasm-tools.
# scripts/build-compositor-wasm.sh # scripts/build-compositor-wasm.sh
set -euo pipefail set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT" ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT"
+4 -1
View File
@@ -8,6 +8,7 @@ set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT" ROOT="$(cd "$(dirname "$0")/.." && pwd)"; cd "$ROOT"
export PATH="$ROOT/.tools/bin:$HOME/.moon/bin:$PATH" export PATH="$ROOT/.tools/bin:$HOME/.moon/bin:$PATH"
CAPI="$ROOT/.tools/wasmtime-c-api" CAPI="$ROOT/.tools/wasmtime-c-api"
[ -f "$CAPI/lib/libwasmtime.a" ] || scripts/setup-toolchain.sh
[ -f "$CAPI/lib/libwasmtime.a" ] || { echo "error: $CAPI missing; run scripts/setup-toolchain.sh" >&2; exit 1; } [ -f "$CAPI/lib/libwasmtime.a" ] || { echo "error: $CAPI missing; run scripts/setup-toolchain.sh" >&2; exit 1; }
command -v moon >/dev/null || { echo "error: moon not found" >&2; exit 1; } command -v moon >/dev/null || { echo "error: moon not found" >&2; exit 1; }
export C_INCLUDE_PATH="$CAPI/include${C_INCLUDE_PATH:+:$C_INCLUDE_PATH}" export C_INCLUDE_PATH="$CAPI/include${C_INCLUDE_PATH:+:$C_INCLUDE_PATH}"
@@ -20,5 +21,7 @@ if [ -d "$PIXI/lib" ]; then
fi fi
moon build --target native --release --warn-list -a wasmhost/bin moon build --target native --release --warn-list -a wasmhost/bin
mkdir -p build mkdir -p build
cp _build/native/release/build/wasmhost/bin/bin.exe build/wasmhost # Replace it by renaming, so a running session (install-session-dev links to it) keeps its copy.
cp _build/native/release/build/wasmhost/bin/bin.exe build/wasmhost.new
mv -f build/wasmhost.new build/wasmhost
echo "build/wasmhost $(stat -c %s build/wasmhost) bytes" echo "build/wasmhost $(stat -c %s build/wasmhost) bytes"
+10 -5
View File
@@ -4,14 +4,15 @@
run0 python3 session/install.py # install: the compositor as a wasm component run0 python3 session/install.py # install: the compositor as a wasm component
run0 python3 session/install.py --link # dev: symlink into this checkout (see below) run0 python3 session/install.py --link # dev: symlink into this checkout (see below)
run0 python3 session/install.py --native # install the native compositor instead run0 python3 session/install.py --native # install the native compositor instead
run0 python3 session/install.py --rust-host # the wasm compositor on the Rust host (host-wasm)
run0 python3 session/install.py --remove # uninstall run0 python3 session/install.py --remove # uninstall
With --link nothing is copied: the installed files are symlinks to the build outputs in this With --link nothing is copied: the installed files are symlinks to the build outputs in this
checkout, so after one root install, `just compositor-wasm host-wasm modules` is all it takes for the checkout, so after one root install, `just compositor-wasm wasmhost modules` is all it takes for the
next login to run your latest build (no root, no reinstall). The checkout must stay where it is. next login to run your latest build (no root, no reinstall). The checkout must stay where it is.
Installs: Installs:
/usr/local/bin/chandra-host wasmtime host that runs the compositor component /usr/local/bin/chandra-host host that runs the compositor component (build/wasmhost)
/usr/local/share/chandra/compositor.wasm the compositor, as a WebAssembly component /usr/local/share/chandra/compositor.wasm the compositor, as a WebAssembly component
/usr/local/bin/chandra (--native) release native compositor binary /usr/local/bin/chandra (--native) release native compositor binary
/usr/local/bin/chandra-session session launcher (starts the host if installed) /usr/local/bin/chandra-session session launcher (starts the host if installed)
@@ -25,7 +26,11 @@ root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
native = "--native" in sys.argv native = "--native" in sys.argv
linked = "--link" in sys.argv linked = "--link" in sys.argv
exe = os.path.join(root, "_build/native/release/build/compositor/bin/bin.exe") exe = os.path.join(root, "_build/native/release/build/compositor/bin/bin.exe")
host = os.path.join(root, "host-wasm/target/release/chandra-host") rust_host = "--rust-host" in sys.argv
# The host that runs the compositor component: the MoonBit one (just wasmhost), or the Rust
# one (just host-wasm) with --rust-host. Either is installed as chandra-host.
host_build = "just host-wasm" if rust_host else "just wasmhost"
host = os.path.join(root, "host-wasm/target/release/chandra-host" if rust_host else "build/wasmhost")
component = os.path.join(root, "build/compositor.wasm") component = os.path.join(root, "build/compositor.wasm")
share = "/usr/local/share/chandra" share = "/usr/local/share/chandra"
targets = [ targets = [
@@ -51,7 +56,7 @@ if native:
if not os.path.exists(exe): if not os.path.exists(exe):
sys.exit("missing %s - run `just build-release` first" % exe) sys.exit("missing %s - run `just build-release` first" % exe)
else: else:
for f, how in ((host, "just host-wasm"), (component, "just compositor-wasm")): for f, how in ((host, host_build), (component, "just compositor-wasm")):
if not os.path.exists(f): if not os.path.exists(f):
sys.exit("missing %s - run `%s` first" % (f, how)) sys.exit("missing %s - run `%s` first" % (f, how))
@@ -106,7 +111,7 @@ mods = os.path.join(root, "build/components")
dst = os.path.join(share, "modules") dst = os.path.join(share, "modules")
if linked: if linked:
link(mods, dst) link(mods, dst)
print("done: pick 'Chandra' in the session menu; rebuild with `just compositor-wasm host-wasm modules`") print("done: pick 'Chandra' in the session menu; rebuild with `just compositor-wasm %s modules`" % host_build.split()[1])
sys.exit(0) sys.exit(0)
if os.path.lexists(dst): if os.path.lexists(dst):
shutil.rmtree(dst) if os.path.isdir(dst) and not os.path.islink(dst) else os.remove(dst) shutil.rmtree(dst) if os.path.isdir(dst) and not os.path.islink(dst) else os.remove(dst)
+17 -8
View File
@@ -1,7 +1,10 @@
# wasmhost # wasmhost
The MoonBit host for the compositor component (`build/compositor.wasm`), replacing the Rust The host that runs the compositor component (`build/compositor.wasm`): `just run`, `just run-drm`
`host-wasm/`. It links wasmtime as the prebuilt C API library (`libwasmtime.a` from the upstream and `just install-session` use it. It replaces the Rust `host-wasm/`, which stays as a fallback
(`just run-rust`, `just run-drm-rust`, `just install-session-rust`).
It links wasmtime as the prebuilt C API library (`libwasmtime.a` from the upstream
`wasmtime-v$WASMTIME_VERSION-x86_64-linux-c-api` release, fetched by `scripts/setup-toolchain.sh` `wasmtime-v$WASMTIME_VERSION-x86_64-linux-c-api` release, fetched by `scripts/setup-toolchain.sh`
into `.tools/wasmtime-c-api`) instead of compiling wasmtime, so a cold build takes about 4 s into `.tools/wasmtime-c-api`) instead of compiling wasmtime, so a cold build takes about 4 s
instead of about 2 minutes. instead of about 2 minutes.
@@ -14,14 +17,20 @@ build/wasmhost build/compositor.wasm --socket PATH --gfx-out frame.png
- `wt/`: the wasmtime C API (`wt_stub.c`) and the value encoding host calls cross as (`val.mbt`). - `wt/`: the wasmtime C API (`wt_stub.c`) and the value encoding host calls cross as (`val.mbt`).
wasmtime's C API has no bindgen: every call goes through one callback with dynamic values, so wasmtime's C API has no bindgen: every call goes through one callback with dynamic values, so
each import is a small handler from values to values. A `list<u8>` crosses as one dynamic value each import is a small handler from values to values. A `list<u8>` crosses as one dynamic value
per byte and wasmtime caps how much one call may copy (about 2.7 MB of `list<u8>`), so large per byte (about 0.4 s for a 720p frame) and wasmtime caps how much one call may copy (about
files are written as `write-file` plus `append-file` chunks. 2.7 MB of `list<u8>`), so large files are written as `write-file` plus `append-file` chunks,
and screenshots, recording and `--gfx-out` keep the screen's pixels on the host
(`snapshot-*`, `*-recording-frame`, `write-frame-png` in `wit/host/raster.wit`).
- `bin/`: the interfaces of `wit/host`. Most of it is the native compositor's own packages: - `bin/`: the interfaces of `wit/host`. Most of it is the native compositor's own packages:
`sys` is compositor/sys, glyphs come from compositor/font (stb_truetype). The rasteriser `sys` is compositor/sys, glyphs come from compositor/font (stb_truetype). The rasteriser
(`raster.mbt`, pixel work in `raster_stub.c`) is a port of `host-wasm/src/raster.rs`; SVG icons (`raster.mbt`, pixel work in `raster_stub.c`) is a port of `host-wasm/src/raster.rs`; SVG icons
use nanosvg (`third_party/nanosvg`) where the Rust host used resvg. use nanosvg (`third_party/nanosvg`, patched for clip paths and masks) where the Rust host used
resvg. `plasmoids.mbt` runs panel modules through compositor/wasm (wasm.h, which libwasmtime
provides); `display.mbt` is the login session's DRM/KMS output and input (compositor/kms).
Status: sys, font and raster work (`--gfx-out` frames match the Rust host's). Panel modules Every interface of `wit/host` is served, so a host change goes in both hosts until host-wasm is
(plasmoids), the login-session display (`--drm`) and the nested window are still to come. removed. `--gfx-out` frames match the Rust host's except for text anti-aliasing (stb_truetype
against ab_glyph). CPU matches it in use: about 1 s at start to compile the component, then idle.
`WASMHOST_TRACE=1` logs every host call. `WASMHOST_TRACE=1` logs every host call; `WASMHOST_PROFILE=1` prints the time spent in each host
function every 5 s.