summaryrefslogtreecommitdiff
path: root/build.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-11-17 01:57:33 -0300
committerGabriel Schneider <[email protected]>2026-11-17 12:15:01 -0300
commit41bdeb1b3fadc266823c43086de61913be8e60f6 (patch)
treebc042874c8c614b788e6f59d3e090144671fd90e /build.zig
parentb1311b3d489a8054456cba7054160ed7fb7e70e1 (diff)
downloadsketchbook-41bdeb1b3fadc266823c43086de61913be8e60f6.tar.gz
sketchbook-41bdeb1b3fadc266823c43086de61913be8e60f6.zip
Dial by name, and fs in every sketch's binary, answering with the sketch closed
A run a person watches (not headless, a script or an export) posts its tree as $XDG_RUNTIME_DIR/9p/sketchbook/<name>, the sketch's Info.name; --9p NAME posts under another name, --9p /path listens at a socket path as before. A name a live run holds is refused, a stale one replaced; a default post that fails says so and the run goes on without one, an explicit --9p that fails ends it as before. (cloud9's post() takes names without a slash, so control.zig makes the sketchbook/ directory and binds there itself, with post.probe deciding live or stale.) `fs VERB [PATH [WORDS]]`, after the options, in the generic host (`sketchbook LIBRARY fs ...`) and in every executable built with sketchbook (`drat-meout fs read state/scene`), is cloud9.verbs.run on an Fsys: the running sketch's tree when one is posted (or at --9p), else the same tree served in this process over a socketpair, on a thread (Control.serveOffline, the same respond with `offline` set), from the save's newest State (--state's save, else the default one; read only: Sessions.openRead, no session started, restored into today's layout), else from the State's declared defaults (init is not run). README, commands, ctl's read and state/ answer; a write and status, log, screen.png and the traces answer in words, "drat-meout is not running: this is its save's newest State, frame 61 of <save>". No window, no SDL. sketchbook.init's modules gain cloud9, so an app's own tests can dial its executable with cloud9.Fsys. Tests: a new step, test-fs (in test): the replay fixture posted by name under a private runtime directory, driven with its own binary's fs: ls, a state write and read, a refused value in words, a live click, a screenshot read, help of state/dots and ctl, quit and the name gone; then closed: a state file read from the defaults, status refused in words. test-fs, test-control, test-paths, test-setup, test-sessions: 56/56 steps, 27/27 tests. drat-meout's copy builds unchanged and answers fs with the game closed: 94 leaves, 16,522 files, 17,608 values, 10,408 directories. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_016Y9MNBECMWcJD5pdS4SR6T
Diffstat (limited to 'build.zig')
-rw-r--r--build.zig42
1 files changed, 39 insertions, 3 deletions
diff --git a/build.zig b/build.zig
index ab1e142..3517237 100644
--- a/build.zig
+++ b/build.zig
@@ -81,6 +81,7 @@ pub fn build(b: *Build) void {
// No optimize mode of its own: the host's Zig code builds in the mode
// of the executable it is part of (`script_optimize` makes use of it).
const cloud9 = b.dependency("cloud9", .{ .target = target, .optimize = optimize }).module("cloud9");
+ b.modules.put(b.graph.arena, "cloud9", cloud9) catch @panic("OOM");
const host = b.addModule("host", .{
.root_source_file = b.path("src/host/root.zig"),
.target = target,
@@ -110,7 +111,7 @@ pub fn build(b: *Build) void {
});
b.installArtifact(host_exe);
- var sb: Sketchbook = .{ .b = b, .target = target, .optimize = optimize, .modules = .{ .abi = abi, .sketch = sketch, .host = host, .tracy = tracy, .vector = undefined, .scope = undefined, .anim = undefined, .gltf = gltf }, .host_exe = host_exe, .gltf_generator = gltf_generator, .web = b.path("web"), .glsl = b.path("src/glsl.zig"), .tools = b.path("tools"), .anim_dir = b.path("src/anim"), .gltf_render_dir = b.path("src/gltf_render"), .script_optimize = optimize, .shared = .create(b) };
+ var sb: Sketchbook = .{ .b = b, .target = target, .optimize = optimize, .modules = .{ .abi = abi, .sketch = sketch, .host = host, .tracy = tracy, .vector = undefined, .scope = undefined, .anim = undefined, .gltf = gltf, .cloud9 = cloud9 }, .host_exe = host_exe, .gltf_generator = gltf_generator, .web = b.path("web"), .glsl = b.path("src/glsl.zig"), .tools = b.path("tools"), .anim_dir = b.path("src/anim"), .gltf_render_dir = b.path("src/gltf_render"), .script_optimize = optimize, .shared = .create(b) };
// Vector graphics: built with the same shader step apps use. Both forms
// of its shaders are exported, so apps' web builds can swap them too.
@@ -549,6 +550,39 @@ pub fn build(b: *Build) void {
test_step.dependOn(&paths.step);
b.step("test-paths", "Check where the save goes").dependOn(&paths.step);
+ // The tree by name and the fs verbs, live and with the sketch closed.
+ const tree = b.addSystemCommand(&.{ "sh", "-c",
+ \\set -e
+ \\exe=$(realpath "$0"); lib=$(realpath "$1"); mkdir -p "$2"; d=$(realpath "$2")
+ \\rm -rf "$d"/*; cd "$d"; rt=$(mktemp -d /tmp/sketchbook-fs.XXXXXX)
+ \\unset PARDES_PID PARDES_9P PARDES_PANE PARDES_MOUNT NINE_MOUNT NINE_MNTGEN
+ \\export XDG_RUNTIME_DIR="$rt" XDG_DATA_HOME="$d/data"
+ \\fs() { "$exe" --9p fstest "$lib" fs "$@"; }
+ \\"$exe" --headless --fresh --state live.xitdb --9p fstest "$lib" & pid=$!
+ \\trap 'kill $pid 2>/dev/null || true; rm -rf "$rt"' EXIT
+ \\i=0; while ! test -S "$rt"/9p/sketchbook/fstest; do i=$((i+1)); test $i -lt 500; sleep 0.01; done
+ \\fs ls | grep -qx 'state/'
+ \\fs write state/dots/buffer/2/kind big; test "$(fs read state/dots/buffer/2/kind)" = .big
+ \\! fs write state/dots/buffer/2/kind huge 2>err; grep -q InvalidValue err
+ \\fs write ctl 'click 30 40'
+ \\test "$(fs read screen.png | head -c 4 | tail -c 3)" = PNG
+ \\fs help state/dots | grep -q '^state/dots/len '
+ \\fs help ctl | grep -q '^ click X Y '
+ \\fs write ctl quit; wait $pid
+ \\test ! -e "$rt"/9p/sketchbook/fstest
+ \\test "$(fs read state/dots/buffer/2/kind)" = .small
+ \\! fs read status 2>err; grep -q 'replay is not running' err
+ \\rm -rf "$d"/*
+ });
+ tree.setName("the tree by name, live and closed");
+ tree.addArtifactArg(host_exe);
+ tree.addArtifactArg(recorded);
+ _ = tree.addOutputDirectoryArg("tree");
+ tree.has_side_effects = true;
+ tree.expectExitCode(0);
+ test_step.dependOn(&tree.step);
+ b.step("test-fs", "Drive a sketch's tree by name with the fs verbs, running and closed").dependOn(&tree.step);
+
// Recorded input replays to the same state: played, seeked, stepped,
// and after a live pointer move (core host behaviour, not an API).
const replay = b.addRunArtifact(host_exe);
@@ -741,7 +775,7 @@ pub fn init(b: *Build, options: Options) Sketchbook {
.b = b,
.target = options.target,
.optimize = options.optimize,
- .modules = .{ .abi = dep.module("abi"), .sketch = dep.module("sketch"), .host = dep.module("host"), .tracy = dep.module("tracy"), .vector = dep.module("vector"), .scope = dep.module("scope"), .anim = dep.module("anim"), .gltf = dep.module("gltf") },
+ .modules = .{ .abi = dep.module("abi"), .sketch = dep.module("sketch"), .host = dep.module("host"), .tracy = dep.module("tracy"), .vector = dep.module("vector"), .scope = dep.module("scope"), .anim = dep.module("anim"), .gltf = dep.module("gltf"), .cloud9 = dep.module("cloud9") },
.host_exe = dep.artifact("sketchbook"),
.gltf_generator = dep.artifact("gltf-bindings"),
.web = dep.path("web"),
@@ -791,7 +825,9 @@ pub const Sketchbook = struct {
/// waveform, spectrogram, spectrum and oscilloscope views of a sound.
/// `anim`: manim-style scenes as code (see `addScene`).
/// `gltf`: native glTF/GLB documents, accessors and extras through cgltf.
- modules: struct { abi: *Build.Module, sketch: *Build.Module, host: *Build.Module, tracy: *Build.Module, vector: *Build.Module, scope: *Build.Module, anim: *Build.Module, gltf: *Build.Module },
+ /// `cloud9` is the 9P library the host serves its tree with: its `Fsys`
+ /// dials a sketch's executable from the app's own tests.
+ modules: struct { abi: *Build.Module, sketch: *Build.Module, host: *Build.Module, tracy: *Build.Module, vector: *Build.Module, scope: *Build.Module, anim: *Build.Module, gltf: *Build.Module, cloud9: *Build.Module },
/// The generic host: loads and hot-reloads a sketch library.
host_exe: *Build.Step.Compile,
/// `host.js` and the `index.html` template.