Files
chandra/justfile
T
Claude 932fca627e
CI / test (push) Successful in 2m6s
Face unlock: a Howdy-style PAM module, shown in the password dialog and set up in Settings
- face/pam_chandra_face.so (`-auth sufficient`): runs `chandra-face compare` as root with a clean
  environment, forwards what it says as PAM_TEXT_INFO / PAM_ERROR_MSG, and maps its exit status
  to success / auth error / unavailable, so the password always still works. Skips remote
  sessions (PAM_RHOST, SSH_CONNECTION), a closed lid and users without faces; refuses a helper
  that isn't root's; kills one that hangs (timeout + 6 s).
- face/chandra-face (Python + OpenCV): YuNet finds the face, SFace embeds it, cosine similarity
  against the enrolled embeddings (threshold 0.42, two matching frames, dark IR warm-up frames
  skipped, optional require_ir). enroll / list / remove / clear / test / status / pam
  enable|disable / fetch-models (sha256-pinned opencv_zoo models). Embeddings only, in
  /var/lib/chandra-face/USER/faces.json (root, 0600); labels in faces.list (0644). Store, config
  and models must be root's and not writable by others. Root commands re-run through run0 (or
  pkexec), so polkit asks first. Settings in /etc/chandra/face.conf.
- `just install-face [--pam]`, `just uninstall-face [--purge]` (face/install.py; uninstall takes
  the module out of every PAM service first). `pam enable` inserts before the first auth or
  @include line (Debian's sudo has only @include common-auth), keeping a .bak.
- Password dialog: a face row ("Looking for your face…" with a sweeping ring, "Face
  recognized", or why not, "Type your password instead"); typing and Enter during the scan go in
  when PAM asks for the password. Howdy's pam_howdy.so messages are understood too.
- Settings > Session > Face unlock: "Use my face for passwords" (polkit-1 + sudo), the enrolled
  faces (Remove takes a second click), "Add a face…", and the tool's progress. New `face-unlock`
  capability: tables 24 (status) and 25 (faces), request 44, in the wasmer/wasmtime stub, the Rust
  host, the MoonBit wasmhost and chandra:host/plasmoids. compositor/shell/face.mbt runs the tool
  on a socket so the compositor never waits.
- Tests: face/test_face.py (fake camera of PGM frames + fake recognizer; --pam builds the module
  and runs it through pamtester), dialog states and message parsing (polkit_test), the dialog via
  a mock helper (auth_test, shots 14/15), Settings against a fake chandra-face (face_test).
  scripts/test.sh runs them (compositor/polkit was missing from its native list), CI installs
  libpam0g-dev + pamtester. Also regenerated two stale desktop-module bindings (doc comments).
- docs/face-unlock.md, including the limits of 2D face recognition.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DPL5hhiJfJNAYqWzQiuKMf
2026-11-26 01:19:29 +00:00

214 lines
9.8 KiB
Makefile

# chandra tasks. `just` lists them.
set shell := ["pixi", "run", "bash", "-euo", "pipefail", "-c"]
export PATH := env_var('HOME') + "/.moon/bin:" + env_var('PATH')
socket := env_var_or_default('XDG_RUNTIME_DIR', '/tmp') + "/wayland-moon-0"
theme := "config/themes/moon-night.json"
exe := "_build/native/debug/build/compositor/bin/bin.exe"
release_exe := "_build/native/release/build/compositor/bin/bin.exe"
tcc := justfile_directory() + "/scripts/tcc/tcc"
default:
@just --list
# Build the vendored tinycc (third_party/tinycc) into _build/tcc, once. Optional: `just build` uses any tcc it can find.
tcc-build:
#!/usr/bin/env bash
set -euo pipefail
[ -x _build/tcc/bin/tcc ] && exit 0
root="$PWD"
rm -rf _build/tcc-src
mkdir -p _build
cp -r third_party/tinycc _build/tcc-src
cd _build/tcc-src
./configure --prefix="$root/_build/tcc" >/dev/null
make -j"$(nproc)" >/dev/null
make install >/dev/null
# Build the panel's wasm modules (application menu, task list, clock, ...) into build/components.
modules:
pixi run modules
# Debug build of the native compositor, compiled and linked with tcc ($TCC, the vendored build if present, or tcc on PATH). Never builds tcc itself.
build:
@{{tcc}} --which >/dev/null
MOON_CC={{tcc}} MOON_STUB_CC={{tcc}} moon build --target native --warn-list -a compositor/bin
# Optimised build with the system C compiler (slower to build, faster to run).
build-release:
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`.
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}}
host-wasm/target/release/chandra-host build/compositor.wasm --socket {{socket}} --theme {{theme}} --window
# Run the native compositor (tcc debug build, with the wasm panel modules) in a window on your current Wayland session.
run-native: build modules
rm -f {{socket}}
{{exe}} --window --socket {{socket}} --theme {{theme}}
# Rebuild the Desktop Pulse plasmoid (wasm component) into compositor/wasm/testdata.
build-pulse:
moon build --target wasm --release
wasm-tools component embed wit _build/wasm/release/build/components/pulse/gen/gen.wasm --world pulse-widget --encoding utf16 -o _build/pulse.embed.wasm
wasm-tools component new _build/pulse.embed.wasm -o compositor/wasm/testdata/pulse.component.wasm
wasm-tools component targets --world pulse-widget wit compositor/wasm/testdata/pulse.component.wasm
# Run the compositor in a window with the Desktop Pulse widget loaded (live system + window integration).
run-pulse: build
rm -f {{socket}}
{{exe}} --window --socket {{socket}} --theme {{theme}} --widget compositor/wasm/testdata/pulse.component.wasm
# One frame of the desktop with Desktop Pulse loaded, to _build/pulse.png.
view-pulse: build
{{exe}} --socket {{socket}}-snap --theme {{theme}} --widget compositor/wasm/testdata/pulse.component.wasm --gfx-out _build/pulse.png
# Run the compositor with no window (clients only; no output).
run-headless: build modules
rm -f {{socket}}
{{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-drm: compositor-wasm wasmhost modules
rm -f {{socket}}
# 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
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}}
# The same on the native compositor (system-cc release build), for comparison.
run-drm-native: build-release modules
rm -f {{socket}}
-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}}
# Install the Chandra login session (display-manager entry): the wasm compositor + its host (the MoonBit host). Asks for root once.
install: compositor-wasm wasmhost modules
scripts/as-root python3 "{{justfile_directory()}}/session/install.py"
# Dev install: symlink the session into this checkout, so after one root install `just compositor-wasm wasmhost modules` is all a rebuild needs.
install-dev: compositor-wasm wasmhost modules
scripts/as-root python3 "{{justfile_directory()}}/session/install.py" --link
# Install the login session with the Rust host (host-wasm) instead of the MoonBit one.
install-rust: compositor-wasm host-wasm modules
scripts/as-root python3 "{{justfile_directory()}}/session/install.py" --rust-host
# Install the login session with the native compositor instead.
install-native: build-release modules
scripts/as-root python3 "{{justfile_directory()}}/session/install.py" --native
# Reload the running session's panel modules from disk (after install or `just modules`), keeping their order and settings. `just reload clock-digital` reloads one. See docs/reloading.md.
reload *name:
python3 session/chandra-ctl reload {{name}}
# Remove the login session again.
uninstall:
scripts/as-root python3 "{{justfile_directory()}}/session/install.py" --remove
# Install face unlock (PAM module + chandra-face + models; docs/face-unlock.md). `just install-face --pam` also turns it on for polkit-1 and sudo.
install-face *args:
scripts/as-root python3 "{{justfile_directory()}}/face/install.py" {{args}}
# Remove face unlock (from every PAM service first). `just uninstall-face --purge` also deletes the enrolled faces.
uninstall-face *args:
scripts/as-root python3 "{{justfile_directory()}}/face/install.py" --remove {{args}}
# Face unlock tests (fake camera; add --pam as root with pamtester to test the PAM module too).
test-face *args:
python3 face/test_face.py {{args}}
# Old names, kept so existing habits and scripts still work.
[private]
install-session:
@echo "note: install-session is now 'just install'" >&2
{{just_executable()}} --justfile "{{justfile()}}" install
[private]
install-session-dev:
@echo "note: install-session-dev is now 'just install-dev'" >&2
{{just_executable()}} --justfile "{{justfile()}}" install-dev
[private]
install-session-rust:
@echo "note: install-session-rust is now 'just install-rust'" >&2
{{just_executable()}} --justfile "{{justfile()}}" install-rust
[private]
install-session-native:
@echo "note: install-session-native is now 'just install-native'" >&2
{{just_executable()}} --justfile "{{justfile()}}" install-native
[private]
uninstall-session:
@echo "note: uninstall-session is now 'just uninstall'" >&2
{{just_executable()}} --justfile "{{justfile()}}" uninstall
# Start a Wayland client inside the running compositor (default: foot).
client *cmd="foot":
WAYLAND_DISPLAY={{socket}} {{cmd}}
# Build host + wasm compositor + modules on a sprites.dev sprite (CHANDRA_SPRITE, default chandra-build) and pull the artifacts back.
remote-build *targets:
scripts/remote-build.sh {{targets}}
# Compositor + wasm component + lib tests.
test: modules
XDG_CONFIG_HOME="$(mktemp -d)" CHANDRA_TEST_CONFIG=1 moon test --target native --warn-list -a compositor/renderer compositor/wasm compositor/host
moon test --target wasm --warn-list -a lib/shell lib/panel lib/clock lib/launcher lib/wm lib/taskbar lib/layoutpick lib/modmgr
# Render one composed frame to _build/e2e_frame.png (via the e2e test).
frame: modules
moon test --target native --warn-list -a compositor/host
@echo "wrote _build/e2e_frame.png"
# Everything CI runs.
ci:
scripts/test.sh
# Render one frame of the desktop to _build/desktop.png and open it.
view: build modules
{{exe}} --socket {{socket}}-snap --theme {{theme}} --gfx-out _build/desktop.png
xdg-open _build/desktop.png
# Time the native build (cold / warm / one-file edit), tcc vs system cc, on a temp copy: `just bench 5` or `just bench 3 "tcc cc cc-release"`.
bench runs="3" configs="tcc cc":
scripts/bench-build.sh {{runs}} "{{configs}}"
# Delete build output (compiled compositor, wasm modules, rendered frames) but keep the built tinycc in _build/tcc.
clean:
#!/usr/bin/env bash
set -euo pipefail
rm -rf build
[ -d _build ] && find _build -mindepth 1 -maxdepth 1 ! -name tcc -exec rm -rf {} + || true
echo "cleaned build/ and _build/ (kept _build/tcc; \`just clean-all\` removes that too)"
# Delete all build output, including the built tinycc (the next build recompiles it).
clean-all:
rm -rf _build build
# Build the compositor as a wasm component (build/compositor.wasm): imports only chandra:host/sys.
compositor-wasm:
scripts/build-compositor-wasm.sh
# Build the host that runs the compositor component (build/wasmhost): MoonBit, linking the prebuilt wasmtime C API, so it builds in seconds.
wasmhost:
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