diff options
Diffstat (limited to 'build.zig')
| -rw-r--r-- | build.zig | 99 |
1 files changed, 40 insertions, 59 deletions
@@ -6,7 +6,7 @@ //! //! const sb = sketchbook.init(b, .{ .target = target, .optimize = optimize }); //! const app = sb.app(.{ .name = "demo", .root_source_file = b.path("src/main.zig") }); -//! _ = app.addSteps(.{}); // run, lib, probe, e2e, test, install; +//! _ = app.addSteps(.{}); // run, lib, e2e, test, install; //! // web and serve with `.web = .{}` //! //! or pick the pieces: `app.addLibrary()`, `app.addExecutable()`, @@ -110,18 +110,7 @@ pub fn build(b: *Build) void { }); b.installArtifact(host_exe); - const probe = b.addExecutable(.{ - .name = "sketchbook-probe", - .root_module = b.createModule(.{ - .root_source_file = b.path("src/host/probe.zig"), - .target = target, - .optimize = optimize, - .imports = &.{.{ .name = "abi", .module = abi }}, - }), - }); - b.installArtifact(probe); - - 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, .probe_exe = probe, .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 }, .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. @@ -389,17 +378,22 @@ pub fn build(b: *Build) void { test_step.dependOn(&reload.step); // A session survives a kill -9 up to its last commit: 255 frames - // played, four commits of 60 made, the fifth lost with the process. - // Its sketch records in every mode, so the test does in release builds too. + // played, four commits of 60 made, the fifth lost with the process; the + // next run starts from frame 240's State, replayed. Its sketch records + // in every mode, so the test does in release builds too; and a sketch + // that does not record keeps its present all the same. const recorded = sb.app(.{ .name = "replay", .root_source_file = b.path("test/replay.zig"), .record = true }).addLibrary(); + const unrecorded = sb.app(.{ .name = "replay", .root_source_file = b.path("test/replay.zig"), .record = false }).addLibrary(); const killed = b.addSystemCommand(&.{ "sh", "-c", \\set -e \\db="${3%.state}.xitdb" - \\rm -f "$3" "$db" - \\if "$0" --headless --script "$1" --state "$3" "$4"; then echo "killed run exited"; exit 1; else test $? = 137; fi - \\"$0" --headless --script "$2" --state "$3" "$4" + \\for lib in "$4" "$5"; do + \\rm -f "$db" + \\if "$0" --headless --script "$1" --state "$3" "$lib"; then echo "killed run exited"; exit 1; else test $? = 137; fi + \\"$0" --headless --script "$2" --state "$3" "$lib" \\test "$(stat -c %s "$db")" -lt 1048576 - \\rm -f "$3" "$db" + \\rm -f "$db" + \\done }); killed.setName("a session survives kill -9"); killed.addArtifactArg(host_exe); @@ -407,6 +401,7 @@ pub fn build(b: *Build) void { killed.addFileArg(b.path("test/killed.script")); _ = killed.addOutputFileArg("kill.state"); killed.addArtifactArg(recorded); + killed.addArtifactArg(unrecorded); killed.has_side_effects = true; killed.expectExitCode(0); test_step.dependOn(&killed.step); @@ -468,7 +463,7 @@ pub fn build(b: *Build) void { // A script run twice records the same database but for the wall clock's // times: the log and the keyframes follow from the script alone. From - // fresh state it records in memory: no database at all. + // fresh state it records in memory: no file at all. const same_sessions = b.addExecutable(.{ .name = "same_sessions", .root_module = b.createModule(.{ .root_source_file = b.path("test/same_sessions.zig"), .target = target, @@ -482,7 +477,7 @@ pub fn build(b: *Build) void { \\"$0" --headless --script "$1" --state "$d/b.state" "$4" \\"$2" "$d/a.xitdb" "$d/b.xitdb" \\"$0" --headless --fresh --script "$1" --state "$d/c.state" "$4" - \\test -e "$d/c.state"; test ! -e "$d/c.xitdb" + \\test ! -e "$d/c.state"; test ! -e "$d/c.xitdb" \\rm -f "$d"/* }); twice.setName("a script recorded twice"); @@ -496,34 +491,36 @@ pub fn build(b: *Build) void { test_step.dependOn(&twice.step); b.step("test-same", "A script run twice records the same database but for times").dependOn(&twice.step); - // Where files go. Without --state: the XDG data directory, state and - // sessions. In .sketchbook/ (`zig build run`'s): a .gitignore, and an - // older build's state moved in, once, never over a file there. + // Where files go. Without --state: the XDG data directory, one file. In + // .sketchbook/ (`zig build run`'s): a .gitignore and the save, whose + // present the next run starts from; an older build's state file beside + // it is moved in, once, never over a file there, and never deleted. const paths = b.addSystemCommand(&.{ "sh", "-c", \\set -e \\exe=$(realpath "$0"); lib=$(realpath "$1"); mkdir -p "$2"; d=$(realpath "$2") \\rm -rf "$d"/* "$d"/.sketchbook; cd "$d" \\XDG_DATA_HOME="$d/data" "$exe" --headless --console quit "$lib" - \\test -s data/replay/replay.state; test -s data/replay/replay.xitdb - \\"$exe" --headless --state replay.state --console "set updates 7" --console quit "$lib" - \\"$exe" --headless --state .sketchbook/replay.state --console quit "$lib" 2>err - \\grep -q moved err; test ! -e replay.state; grep -qx '*' .sketchbook/.gitignore + \\test "$(ls -A data/replay)" = replay.xitdb + \\"$exe" --headless --state .sketchbook/replay.xitdb --console "set updates 7" --console quit "$lib" + \\test "$(ls -A .sketchbook | tr '\n' ' ')" = ".gitignore replay.xitdb "; grep -qx '*' .sketchbook/.gitignore \\printf 'expect updates 7\n' >check.script - \\"$exe" --headless --state .sketchbook/replay.state --script check.script "$lib" - \\"$exe" --headless --state replay.state --console quit "$lib" - \\"$exe" --headless --state .sketchbook/replay.state --console quit "$lib" 2>err - \\grep -q 'both exist' err; test -e replay.state - \\"$exe" --headless --state .sketchbook/replay.state --script check.script "$lib" + \\"$exe" --headless --state .sketchbook/replay.xitdb --script check.script "$lib" + \\printf 'not a state file' >old.state + \\"$exe" --headless --state .sketchbook/old.xitdb --console quit "$lib" 2>err + \\grep -q moved err; test ! -e old.state; test "$(cat .sketchbook/old.state)" = 'not a state file' + \\printf 'not a state file' >old.state + \\"$exe" --headless --state .sketchbook/old.xitdb --console quit "$lib" 2>err + \\grep -q 'both exist' err; test -e old.state \\rm -rf "$d"/* "$d"/.sketchbook }); - paths.setName("state and sessions paths"); + paths.setName("where the save goes"); paths.addArtifactArg(host_exe); paths.addArtifactArg(recorded); _ = paths.addOutputDirectoryArg("paths"); paths.has_side_effects = true; paths.expectExitCode(0); test_step.dependOn(&paths.step); - b.step("test-paths", "Check where state and sessions files go").dependOn(&paths.step); + b.step("test-paths", "Check where the save goes").dependOn(&paths.step); // Recorded input replays to the same state: played, seeked, stepped, // and after a live pointer move (core host behaviour, not an API). @@ -719,7 +716,6 @@ pub fn init(b: *Build, options: Options) Sketchbook { .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") }, .host_exe = dep.artifact("sketchbook"), - .probe_exe = dep.artifact("sketchbook-probe"), .gltf_generator = dep.artifact("gltf-bindings"), .web = dep.path("web"), .glsl = dep.path("src/glsl.zig"), @@ -771,8 +767,6 @@ pub const Sketchbook = struct { 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 }, /// The generic host: loads and hot-reloads a sketch library. host_exe: *Build.Step.Compile, - /// Prints any sketch's state file. - probe_exe: *Build.Step.Compile, /// `host.js` and the `index.html` template. web: Build.LazyPath, /// The GLSL declaration generator (see `addGlslLayouts`). @@ -1432,9 +1426,8 @@ pub const App = struct { } pub const RunOptions = struct { - /// State file, relative to the working directory; - /// `.sketchbook/<name>.state` by default, where the host keeps the - /// sessions database beside it, all ignored by git and jj. + /// The save, relative to the working directory; + /// `.sketchbook/<name>.xitdb` by default, ignored by git and jj. state: ?[]const u8 = null, /// Where relative asset paths resolve; the project root by default. cwd: ?Build.LazyPath = null, @@ -1447,7 +1440,7 @@ pub const App = struct { const install = b.addInstallArtifact(library, .{}); const run = b.addRunArtifact(app.sb.host_exe); run.step.dependOn(&install.step); - run.addArgs(&.{ "--state", options.state orelse b.fmt(".sketchbook/{s}.state", .{app.name}) }); + run.addArgs(&.{ "--state", options.state orelse b.fmt(".sketchbook/{s}.xitdb", .{app.name}) }); run.addFileArg(b.graph.path(.install_lib, library.out_filename)); run.setCwd(options.cwd orelse b.path(".")); run.stdio = .inherit; @@ -1461,7 +1454,7 @@ pub const App = struct { cwd: ?Build.LazyPath = null, }; - /// Plays a script headless, with a throwaway state file, against + /// Plays a script headless, from fresh state and saving nothing, against /// `artifact`: the executable (`addExecutable`), or the hot-reloadable /// library (`addLibrary`) through the generic host, which scripts can /// `reload`. Fails when an expectation or a console line does. @@ -1473,7 +1466,7 @@ pub const App = struct { run.addFileArg(script); run.addArg("--state"); // Named per script: runs of one app may share an output directory. - _ = run.addOutputFileArg(b.fmt("{s}-{s}.state", .{ app.name, std.fs.path.stem(script.getDisplayName()) })); + _ = run.addOutputFileArg(b.fmt("{s}-{s}.xitdb", .{ app.name, std.fs.path.stem(script.getDisplayName()) })); for (options.defines) |pair| run.addArgs(&.{ "--define", b.fmt("{s}={s}", .{ pair[0], pair[1] }) }); if (library) run.addArtifactArg(artifact); run.setCwd(options.cwd orelse b.path(".")); @@ -1503,7 +1496,7 @@ pub const App = struct { const b = app.sb.b; const run = b.addRunArtifact(exe); run.addArg("--state"); - _ = run.addOutputFileArg(b.fmt("{s}-export.state", .{app.name})); + _ = run.addOutputFileArg(b.fmt("{s}-export.xitdb", .{app.name})); run.addArg("--export"); const frames = run.addOutputDirectoryArg("frames"); run.addArgs(&.{ "--fps", b.fmt("{d}", .{options.fps}) }); @@ -1514,17 +1507,6 @@ pub const App = struct { return .{ .run = run, .frames = frames }; } - /// Prints the app's live state; `zig build probe -- --watch` follows it. - pub fn addProbe(app: App, state: ?[]const u8) *Build.Step.Run { - const b = app.sb.b; - const run = b.addRunArtifact(app.sb.probe_exe); - run.addArg(state orelse b.fmt(".sketchbook/{s}.state", .{app.name})); - run.setCwd(b.path(".")); - run.stdio = .inherit; - run.addPassthruArgs(); - return run; - } - /// Tests in `root_source_file` (the app's root by default), with the /// app's imports and the app itself importable as `app`. pub fn addTest(app: App, options: struct { root_source_file: ?Build.LazyPath = null }) *Build.Step.Compile { @@ -1769,7 +1751,7 @@ pub const App = struct { /// The conventional wiring. Installs the executable, and adds: /// `run` (host + hot reload), `lib` (rebuild the library; use `--watch`), - /// `web` and `serve` (with `web` options), `probe`, `export` (frames + /// `web` and `serve` (with `web` options), `export` (frames /// for ffmpeg), `e2e` (scripts) and `test`. pub fn addSteps(app: App, options: StepsOptions) Steps { const b = app.sb.b; @@ -1780,7 +1762,6 @@ pub const App = struct { const run = app.addRun(library, .{}); b.step("run", "Run with hot reload (rebuild with `zig build lib --watch`)").dependOn(&run.step); b.step("lib", "Build and install the hot-reloadable library").dependOn(&b.addInstallArtifact(library, .{}).step); - b.step("probe", "Print the live state (-- --watch to follow)").dependOn(&app.addProbe(null).step); const web = if (options.web) |web_options| blk: { const web = app.addWeb(web_options); @@ -1792,7 +1773,7 @@ pub const App = struct { // `--export` takes the first argument after `--`. const exporting = b.addRunArtifact(exe); - exporting.addArgs(&.{ "--state", b.fmt(".sketchbook/{s}.state", .{app.name}), "--export" }); + exporting.addArgs(&.{ "--state", b.fmt(".sketchbook/{s}.xitdb", .{app.name}), "--export" }); exporting.addPassthruArgs(); exporting.setCwd(b.path(".")); exporting.stdio = .inherit; |
