const std = @import("std"); pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); const core_dep = b.dependency("labelle_core", .{ .target = target, .optimize = optimize }); const core_module = core_dep.module("labelle-core"); const scene_dep = b.dependency("scene", .{ .target = target, .optimize = optimize }); const scene_module = scene_dep.module("scene"); const jsonc_dep = b.dependency("jsonc", .{ .target = target, .optimize = optimize }); const jsonc_module = jsonc_dep.module("jsonc"); // Backend-agnostic handle/POD types referenced from both the // engine module and the standalone `src/assets/` test root. // Promoted to named modules so loader.zig can `@import("audio_types")` / // `@import("font_types")` and resolve identically in both compilations. const audio_types_module = b.createModule(.{ .root_source_file = b.path("src/audio_types.zig"), .target = target, .optimize = optimize, }); const font_types_module = b.createModule(.{ .root_source_file = b.path("src/font_types.zig"), .target = target, .optimize = optimize, }); // font_types now aliases the canonical Glyph/CodepointEntry/KernPair from // labelle-core (labelle-assembler#647) instead of redefining them, so it // needs core in its own module graph (it used to be a dependency-free leaf). font_types_module.addImport("labelle-core", core_module); const engine_module = b.addModule("engine", .{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = optimize, // src/preview/socket.zig needs libc for its raw `close`/`write`/`fcntl` // bindings — 0.16 dropped `std.posix.fcntl`/`std.posix.close` and // routed file IO through `std.Io.File` (which would force an // `io: std.Io` thread-through), so going straight to libc is the // smallest restoration. Downstream consumers inherit libc linkage // automatically because the engine module declares it here. .link_libc = true, }); engine_module.addImport("labelle-core", core_module); engine_module.addImport("target_features", targetFeatures(b, target)); engine_module.addImport("scene", scene_module); engine_module.addImport("jsonc", jsonc_module); engine_module.addImport("audio_types", audio_types_module); engine_module.addImport("font_types", font_types_module); // #547: src/preview_iosurface.zig declares `extern "c"` bindings // for IOSurface + CoreFoundation. Even when no caller exercises // those code paths, Zig's analyzer reaches the function bodies // (e.g. `Producer.deinit`) for every test binary that imports // `engine`, and the linker then refuses to leave those symbols // unresolved. Linking the system frameworks at the module level // satisfies every downstream test binary in one place; non-macOS // builds skip them and the macOS-only code is unreachable behind // a `builtin.os.tag == .macos` gate at every entry point. if (target.result.os.tag == .macos) { engine_module.linkFramework("IOSurface", .{}); engine_module.linkFramework("CoreFoundation", .{}); } const test_step = b.step("test", "Run engine tests"); // labelle-engine#902: src/ must not name platforms, stores, packages or // backends. Same guard as the CLI core's (RFC #406). addAgnosticGuard(b, test_step, optimize); const storage_module = b.createModule(.{ .root_source_file = b.path("src/storage.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "labelle-core", .module = core_module }}, }); const storage_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("test/storage_test.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "storage", .module = storage_module }}, }) }); const storage_run = b.addRunArtifact(storage_tests); test_step.dependOn(&storage_run.step); b.step("test-storage", "Test persistent blob storage").dependOn(&storage_run.step); const settings_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("src/settings.zig"), .target = target, .optimize = optimize, .imports = &.{.{ .name = "labelle-core", .module = core_module }}, }) }); const settings_run = b.addRunArtifact(settings_tests); test_step.dependOn(&settings_run.step); b.step("test-settings", "Test asynchronous typed settings").dependOn(&settings_run.step); // #899: the preview socket shims take errno and the fcntl/errno // constants from `std.c`, which resolves them per target, and // `screenshot_request.nowNs` takes CLOCK_MONOTONIC the same way. This // step compiles both (no link) for targets the host never builds for, // so a per-OS/per-arch mistake fails in CI instead of on a device: // Linux ABIs whose flag values differ from asm-generic (MIPS // O_NONBLOCK=128, SPARC 0x4000), PowerPC, Android, macOS and Windows. const check_socket_targets_step = b.step("check-socket-targets", "Compile the preview socket shims and the monotonic clock for macOS, Windows, Android and several Linux ABIs (no link)"); const socket_check_queries = [_]std.Target.Query{ .{ .cpu_arch = .aarch64, .os_tag = .macos }, .{ .cpu_arch = .x86_64, .os_tag = .windows, .abi = .gnu }, .{ .cpu_arch = .aarch64, .os_tag = .linux, .abi = .android }, .{ .cpu_arch = .x86_64, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .powerpc64le, .os_tag = .linux, .abi = .gnu }, .{ .cpu_arch = .mips, .os_tag = .linux, .abi = .gnueabihf }, .{ .cpu_arch = .sparc64, .os_tag = .linux, .abi = .gnu }, }; for (socket_check_queries) |query| { check_socket_targets_step.dependOn(&addSocketTargetCheck(b, query, optimize).step); } // The definition package remains independent. Verify its frame slices // against the existing engine player before migrating playback ownership. const animation_module = b.dependency("animation", .{ .target = target, .optimize = optimize }).module("animation"); engine_module.addImport("animation", animation_module); const animation_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("animation/test/animation_package_test.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "engine", .module = engine_module }, .{ .name = "animation", .module = animation_module }, .{ .name = "labelle-core", .module = core_module }, }, }) }); const run_animation_tests = b.addRunArtifact(animation_tests); test_step.dependOn(&run_animation_tests.step); b.step("test-animation", "Test definition-to-engine playback compatibility").dependOn(&run_animation_tests.step); // Test files in test/ directory const test_files = [_][]const u8{ "test/root_test.zig", "test/shader_material_test.zig", // #881 — the comptime `.zon` entity writer must never silently // drop an engine BUILT-IN (`Camera`/`Image`/`Emitter` were), and a // NEW built-in that forgets a writer branch must fail to COMPILE. "test/zon_builtin_components_test.zig", // #883 — a shader material destroyed mid-update must never be // submitted for the frame the renderer had already cached it in. // Mock renderer with a CACHED DRAW LIST counts material vs // fallback draws and dead-id submits. "test/shader_material_retire_test.zig", // #855 — typed hook context: `engine.HookContext` injection by // field type, `ctx.game()` / `ctx.gameAs(G)`, the bound-Game // identity check, and a regression proving the legacy // `game_ptr: *anyopaque` receiver form still works unchanged. "test/typed_hook_context_test.zig", // #862/#863 — buffered payloads must outlive the drain that // delivers them. Uses a POISONING allocator: under a plain one // these tests pass with the bug present. "test/payload_lifetime_test.zig", // #864 — the two scene lifecycle events that were queued and then // discarded by `unloadCurrentScene`'s buffer clear. Listens on the // `engine__*` variants through the REAL setScene paths. "test/scene_lifecycle_events_test.zig", "test/easing_test.zig", "test/scene_test.zig", // #922 — startup scene registration through the shared noinline // helpers: each scene keeps its own loader, setters hit the right // entry, unknown names still fail. "test/scene_registration_test.zig", "test/gestures_test.zig", "test/sparse_set_test.zig", "test/query_test.zig", // #615 — first-class CommandBuffer(Command): enqueue (growable // engine-owned storage), conflict detection (write-key overlap + // release-before-acquire handoff exemption), deferred apply. "test/command_buffer_test.zig", "test/gui_view_test.zig", "animation/test/anim_timing_test.zig", "test/gui_runtime_state_test.zig", "test/form_binder_test.zig", "test/script_runner_test.zig", "test/game_log_test.zig", "test/fullscreen_api_test.zig", "test/cursor_api_test.zig", "test/vsync_api_test.zig", "animation/test/engine_sprite_anim_test.zig", // The atlas -> source_rect mapping, trim geometry included: the // seam where a parsed-but-unread `spriteSourceSize` silently // became a per-frame positional error. "test/atlas_source_rect_test.zig", "test/save_policy_test.zig", "test/storage_serialization_test.zig", "test/save_load_mixin_test.zig", // #921 — the save serializer split into bounded functions must // keep the save format byte-identical; pins a golden save and // loads it back as an "existing" save. "test/save_serializer_golden_test.zig", // #922 — the save loader split into bounded functions must load // existing saves into the same world (pinned re-serialization), // keep postLoad/marker/create semantics and leak nothing. "test/save_load_compat_test.zig", "test/save_scene_after_menu_load_test.zig", "test/jsonc/bridge_leak_test.zig", "test/jsonc/nested_lifecycle_test.zig", "test/jsonc/target_overrides_test.zig", "test/jsonc/unknown_component_warn_test.zig", // #808 — unknown components must not spawn ghost nested entities. "test/jsonc/unknown_component_nested_test.zig", // C2 — a project-registered component named `Tilemap` must win over // the engine built-in in the scene loader (no silent shadowing). "test/jsonc/tilemap_precedence_test.zig", // #568 — standalone `Image` component: scene-loader parse, loader // resolution through AssetCatalog, and registered-vs-built-in // precedence. "test/jsonc/image_component_test.zig", "test/scene_ref_test.zig", "test/asset_catalog_test.zig", "test/audio_loader_test.zig", "test/font_types_test.zig", "test/font_loader_test.zig", "test/asset_streaming_shim_test.zig", // #821 — atlas→texture binding integrity across scene swaps and GPU // surface loss: every atlas must rebind to ITS OWN freshly uploaded // texture, never a recycled slot (models the assembler adapter). "test/atlas_surface_crosswire_test.zig", // #831 — standalone `.image` load shims: `loadImageFromMemory` // blocks so an eager image is drawable on the FIRST frame, which // `assets.acquire` alone does not guarantee. "test/image_load_shim_test.zig", // #563 — sprite-based asset inference: reverse index (sprite/image → // resource bundle) + entity-tree walker that derives the `meta.assets` // set, plus the `AssetManifest` escape hatch. Engine half of the RFC // unification; assembler-side codegen (making `meta.assets` optional) // is the follow-up. "test/asset_manifest_test.zig", "test/asset_inference_wire_test.zig", "animation/test/animation_def_test.zig", "animation/test/animation_state_transitions_test.zig", "animation/test/animation_def_runtime_test.zig", "animation/test/animation_events_test.zig", "test/tween_test.zig", "test/behavior_tree_test.zig", "test/particles_test.zig", "test/emitter_component_test.zig", "test/particles_tick_test.zig", "test/jsonc/emitter_component_test.zig", "animation/test/sprite_animation_test.zig", "animation/test/sprite_animation_tick_test.zig", "animation/test/sprite_animation_events_test.zig", "animation/test/sprite_by_field_test.zig", "animation/test/sprite_by_field_tick_test.zig", "test/scene_assets_hooks_test.zig", "test/pause_hook_test.zig", // RFC-I18N §4 — frame-boundary hook: the generated main wires the // i18n module's `resetFrameArena` into the top of `tick` (every // frame, paused included) via `setFrameBoundaryFn`. "test/frame_boundary_test.zig", "test/fixed_timestep_test.zig", // #578 — `pub const Events` on the engine, dual-emit through // the buffered event path so flows can listen to lifecycle // hooks as Event-node variants. "test/engine_events_test.zig", // #856 — fallible event enqueue (`Game.tryEmit`): the failure // path driven with a FailingAllocator, the queue-intact / // no-duplicate guarantee, and proof the infallible `emit` call // shape is unchanged. "test/events_fallible_emit_test.zig", // #820 — direct `loadTextureFromMemory` uploads carried across a // GPU surface loss under their original ids (retain / invalidate / // re-upload / free), gated on the gfx re-arm seam. "test/direct_upload_lifecycle_test.zig", // labelle-gui#208 — engine-hosted input events scanned in // `Game.tick` through the unified `InputInterface`, dual-emitted // on the buffered event path so flows can listen via `OnEvent`. "test/input_events_test.zig", // Accessor methods on the game handle wrapping the unified // `InputInterface` for key-release / mouse-button polling (#208). "test/input_mixin_test.zig", // #611 — ControllerManager player↔controller mapping: unassigned // pool, assignment API, debounced-lost, guid/heuristic resume, // opt-in policy helpers, and the auto-pause integration. "test/controller_manager_test.zig", "test/spawn_from_prefab_test.zig", "test/jsonc/bridge_prefab_tags_test.zig", "test/save_load_two_phase_test.zig", "test/post_load_render_gate_test.zig", "animation/test/example_prefab_animation_walkthrough_test.zig", "test/jsonc/bridge_deserialize_test.zig", "test/jsonc/deserializer_test.zig", "test/jsonc/unified_format_test.zig", "test/jsonc_bridge_gizmo_visibility_test.zig", "test/collect_entities_test.zig", "test/entities_with_roster_test.zig", "test/set_sprite_flip_test.zig", // #826 — `setSpriteFrame`: the atlas frame swap that five games // hand-rolled, including the `texture_scale_*` application all five // copies omitted (silently mis-sampling a downscaled atlas). "test/set_sprite_frame_test.zig", "test/set_material_test.zig", // #842 — `Game.fontId` (public name → `FontId` for a declared // `.font` resource) and `Game.setTextFont`. Before this the only // resolution was `gui_mixin`'s private `resolveLabelFont`, so // `addText` from a script could only ever pass `FontId.invalid`. "test/font_id_test.zig", "test/video_component_test.zig", "test/camera_viewport_test.zig", "test/camera_viewport_seed_test.zig", // PIE viewport handshake (#543) — kept separate from // preview_mode_test.zig so the new coverage isn't gated on // that file's pre-existing 21-test subscription bug. "test/preview_handshake_test.zig", // PIE viewport frame stream (#544) — producer-side SHM // lifecycle + publishFrame. Companion to the handshake tests // above; spins up an in-test `preview_shm.Consumer` to read // back what the engine wrote. "test/preview_frame_stream_test.zig", // Backend-agnostic FrameCapture trait (#140 architecture rethink). // Validates the producer-side trait + publishFrame orchestration // without involving any real graphics backend — pure CPU mock. "test/preview_capture_test.zig", // preview_mode_test + flows_game_api_test: re-enabled after #543 // fixed the variadic-`fcntl` ABI bug (declared non-variadic on // a function libc declares variadic — mismatched on // aarch64-darwin where variadic args go on the stack rather // than in registers). With std.c.fcntl (correctly variadic) in // src/preview_mode.zig, O_NONBLOCK actually lands on the FD, // pollSubscription's read can EAGAIN, and the 21 previously- // hanging subscription-flow tests run to completion. "test/preview_mode_test.zig", "test/flows_game_api_test.zig", // cli#229: `engine.requestedScene()` reads `LABELLE_SCENE` so // loading-scene controllers can honour `--scene=` after // `assets.allReady` instead of racing the boot swap. "test/runtime_env_test.zig", // Runtime Scheduler for flow `Delay` nodes (#48 / #25 Stage 2). // Pause-aware timer wheel reusing the gameplay clock. "test/scheduler_test.zig", // Two-tier component visibility + per-pack registry partition (#652). "test/component_visibility_test.zig", // #630 — scene-teardown: O(N) `unloadCurrentScene` drain (guarded // untrack) + `resetEcsBackend` clears `scene_entities`. "test/scene_teardown_test.zig", // #639 — project Y-axis convention: `Game.y_axis` constant + // `yAxis()` accessor + additive `screenToLogical` picking path // (RFC §3, Q1→(b), Q3). Raw `screenToDesign` stays unchanged. "test/y_axis_test.zig", // #852 — screen coordinate spaces: `getMouseDesign` / // `getMouseLogical` (input mapped out of the backend's own space), // `designToScreen` / `logicalToScreen` (the inverse), and the // `framebufferSize` / `designSize` accessors. Covers a 2x // framebuffer, a 1x one, and a renderer with none of the decls. "test/screen_space_test.zig", // labelle-gfx#290 Stage 4 — render-phase custom-mesh seam: // `game.drawMesh(...)` forwarding + `SystemRegistry.renderMeshes` // plugin render callback (the seam `labelle-spine` submits skinned // meshes through). "test/render_mesh_test.zig", // In-game UI-kit DrawList renderer loop + font pipeline (#771): // the engine consumer of labelle-gui `ui_kit`'s backend-agnostic // DrawList — UV→pixel src mapping, glyph-run text pass, focus ring, // command conversion, and the full `bakeUiFont` + submit/render // integration through a recording renderer + mock font backend. "test/ui_draw_list_test.zig", // labelle-studio Play mode (Phase 3) — wasm editor control // surface: bind/dispatch vtable, pause/step tick gating, scene // digest JSON (+ truncation validity), camera override state // machine, pre-bind no-op safety. "test/editor_api_test.zig", // Runtime scene-source override map (editor_load_scene): set → // load consults override (loadSceneFromSource by loading scene // name, loadSceneFile includes by path stem); replace frees the // previous source. "test/scene_source_override_test.zig", // editor_api v1.1 — `Game.setStateOwned`: game-owned copy of // runtime-sourced state names (loader meta.initial_state + // editor_set_state share the PR #599 UAF-safe ordering). "test/set_state_owned_test.zig", // editor_reload_prefab v1.4 (#691) — bounded live-instance // refresh: declared-transient diff on roots + local_path-matched // children, runtime-attached survival, entity-ref preservation, // reference-mode override re-merge, length-gated structural edits. "test/prefab_refresh_test.zig", // #701 — destroyEntity/destroyEntityOnly unlink the destroyed // entity from its parent's `Children` list (stale-id/alias hole). // The cascade iterates a snapshot so the per-child unlink can't // invalidate the walk. "test/destroy_unlink_test.zig", // #697 — silent-failure hardening on the loading→gameplay // transition: the hot-reload loader swallow (`catch {}`) now // surfaces a loader failure through `game.log.err` instead of // vanishing. Drives a hot reload with a fail-on-demand loader and // asserts the error reaches a capturing log sink. "test/loading_transition_hardening_test.zig", // #380 — debug inspector: FPS/frame-time tracker (FrameProfiler) // + live per-script/per-plugin profiler-overlay data collection. // The per-script profiler timings themselves shipped in v1.6.0; // these cover the FPS counter and the overlay-facing surface. "test/frame_profiler_test.zig", "test/inspector_overlay_test.zig", // #737 — Script Runtime Contract v1: the `labelle_*` C-ABI // surface language plugins bind (RFC-LANGUAGE-PLUGINS). Covers // pre-bind no-op safety, the bind/vtable dispatch for every op, // component serde round-trips over the registry, name-dispatched // queries, event emit-by-name, and the subscribe/drain/poll FIFO // (incl. the two-arena payload lifetime). "test/script_contract_test.zig", // #886 — the contract's built-in set is derived from // `scene.builtins.Builtin`: every tag is script-addressable // (drift guard), Emitter's channel, and the shadowing rule. "test/script_contract_builtins_test.zig", // labelle-gfx#305 Phase 2 Slice C — post-fx type re-exports // (engine.PostPass/PostPassKind/PostPassUniforms are the SAME // labelle-core types gfx re-exports, unified diamond) + the // `Game.setPostFx/pushPostPass/clearPostFx` passthrough seam. "test/post_fx_passthrough_test.zig", // #827 — `drawGizmoText` + `…Screen`/`…Category` on the Game gizmo // mixin. `GizmoDraw` (labelle-core) has no text payload, so the // string is copied into a per-frame arena on the gizmo state and // joined to its draw by index (`getGizmoText`); these cover the // copy-not-borrow lifetime, the category gate, and the arena reset // at `clearGizmos`. "test/gizmo_text_test.zig", // #841 (companion to labelle-gfx#343) — collection-of-images // tilesets: one texture per per-tile `` instead of one per // tileset, deduped by `source`, unloaded once each. Drives a // renderer seam shaped like gfx's in BOTH the post-#343 and // pre-#343 shapes rather than the pinned gfx `tilemap` package // (which predates the `tile_images`/`resolveTileFn` fields), so it // needs only the standard core/engine/scene imports — and it pins // that an engine on OLDER gfx keeps full tilemap support. "test/tilemap_collection_test.zig", // #847 — tileset textures (sheet AND per-tile) across a GPU surface // loss/restore: invalidated (never freed) on loss, re-uploaded under // their original ids on restore, gfx's tilemap renderer re-bound. // Same hand-rolled gfx stand-in (`tilemap_fake_gfx.zig`). "test/tilemap_surface_test.zig", // Per-tile animation tick (companion to labelle-gfx#351). Same // reason for a hand-rolled gfx stand-in: the pinned gfx has no // `advanceAnimations`, and the pre/post pair is what pins the // `@hasDecl` degrade. "test/tilemap_animation_tick_test.zig", // #857 — the hook/event DELIVERY CONTRACT as an executable spec: // pre/post-drain state, FIFO + receiver-tuple order, next-drain // delivery of handler-emitted events, emitSync queue-jumping, // consumable break, borrowed-payload lifetime, scene-reset drop, // shutdown flush, and the generated loop's drain-before-tick // shape. Prose in `HOOK-DELIVERY-CONTRACT.md`. "test/hook_delivery_contract_test.zig", // #857 — the representative dispatcher size (64 event variants x // 16 receiver types). Compiles ONLY because `core.MergeHooks.emit` // raises the comptime branch quota; this file deliberately sets no // quota of its own, so dropping core's would break the build here. "test/hook_dispatch_scaling_test.zig", // #858 — the OFF half of opt-in hook tracing. `zig test` makes // the test RUNNER the compilation root, so this binary cannot // declare `labelle_hook_trace` and is structurally an untraced // build: it asserts the tracer folds to `void`, that `Game`'s // layout is unchanged, and that emit/drain behaviour matches the // traced harness's sequence exactly. Plus the tracing types that // compile either way (identity, filters, renderers, the ring). "test/hook_trace_off_test.zig", }; // #855 — the typed hook context's no-argument `ctx.game()` form // resolves `@import("root").Game`, and under `zig test` the root is // Zig's test runner, not the test file. So the shipping authoring // form can only be compiled and run from a real EXECUTABLE whose root // declares `pub const Game`, the way an assembler-generated // `main.zig` does. This headless harness is that root; it asserts and // exits non-zero on failure, so `zig build test` gates on it. const typed_hook_ctx_exe = b.addExecutable(.{ .name = "typed_hook_context_root_exe", .root_module = b.createModule(.{ .root_source_file = b.path("test/typed_hook_context_root_exe.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "labelle-core", .module = core_module }, .{ .name = "engine", .module = engine_module }, .{ .name = "scene", .module = scene_module }, }, }), }); test_step.dependOn(&b.addRunArtifact(typed_hook_ctx_exe).step); // #858 — opt-in hook tracing. Tracing is switched on by a decl on the // COMPILATION ROOT, and under `zig test` the root is Zig's test // runner, so — exactly as #855 found — the ON path can only be // compiled and run from a real executable whose root carries the // declaration. Two of them: // // * `hook_trace_root_exe` — the behaviour harness (enqueue, failed // enqueue, drain identity, sync vs buffered, listener execution, // consumable stop, filtering, the ring bound, sinks, text/JSONL // rendering, and PARITY with `core.MergeHooks.emit`'s own walk). // * `hook_trace_scaling_exe` — the comptime budget at the #854 // validation size (64 variants x 16 receivers) with tracing ON. // The traced walk pays the same `variants x receivers` product // `MergeHooks.emit` does, so this is the file that fails first if // `hook_trace_dispatch.dispatch`'s quota is ever removed. // // Both assert and exit non-zero on failure, so `zig build test` gates // on them. const hook_trace_exes = [_]struct { name: []const u8, root: []const u8 }{ .{ .name = "hook_trace_root_exe", .root = "test/hook_trace_root_exe.zig" }, // #858 review: an eventless game (GameEvents == void) with tracing // ENABLED. The traced enqueue path appended to a `void` buffer, so // this combination did not COMPILE — building it is the assertion. .{ .name = "hook_trace_eventless_exe", .root = "test/hook_trace_eventless_exe.zig" }, // #727/#858 review: `ring_capacity = 0` is a DOCUMENTED sink-only // configuration, and `Tracer.at` divides by `capacity`. Modulo by // a comptime zero is a compile error, so instantiating either // renderer in such a build could fail to compile — building this // is the assertion. .{ .name = "hook_trace_zero_ring_exe", .root = "test/hook_trace_zero_ring_exe.zig" }, // labelle-assembler#727: a root that DECLARES `hook_receiver_ids`. // Proves the tracer reads the generated table instead of deriving // — the table ids there are unlike both the derived and the // declared ones, so a fallback fails every check. .{ .name = "hook_trace_receiver_table_exe", .root = "test/hook_trace_receiver_table_exe.zig" }, // #866 review: the SINGLE-receiver dispatch path (`walkSingle`) // did not validate the table length, so a stale table silently // mislabelled slot 0. Valid one-receiver/one-entry shape. .{ .name = "hook_trace_single_receiver_table_exe", .root = "test/hook_trace_single_receiver_table_exe.zig" }, // #865 review: the SINGLE-receiver dispatch path never recorded // `Phase.consumed`, so a handled consumable event was // indistinguishable from an ignored one. Both controls — returned // true, returned false — in one harness. Distinct from the two // above: they cover the table's IDENTITY, this one the consumable // RETURN, and all three exercise `walkSingle`. .{ .name = "hook_trace_single_receiver_exe", .root = "test/hook_trace_single_receiver_exe.zig" }, .{ .name = "hook_trace_scaling_exe", .root = "test/hook_trace_scaling_exe.zig" }, }; for (hook_trace_exes) |spec| { const exe = b.addExecutable(.{ .name = spec.name, .root_module = b.createModule(.{ .root_source_file = b.path(spec.root), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "labelle-core", .module = core_module }, .{ .name = "engine", .module = engine_module }, .{ .name = "scene", .module = scene_module }, .{ .name = "animation", .module = animation_module }, }, }), }); test_step.dependOn(&b.addRunArtifact(exe).step); } const legacy_animation_step = b.step("test-animation-legacy", "Run all animation package and engine adapter tests"); legacy_animation_step.dependOn(&run_animation_tests.step); const save_regressions = b.step("test-save-storage", "Test storage and engine save/load integration"); save_regressions.dependOn(&storage_run.step); const shader_regressions = b.step("test-shader-regressions", "Execute shader, scene, prefab, and material regressions"); for (test_files) |test_file| { const t = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path(test_file), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "labelle-core", .module = core_module }, .{ .name = "engine", .module = engine_module }, .{ .name = "scene", .module = scene_module }, .{ .name = "animation", .module = animation_module }, }, }), }); const run = b.addRunArtifact(t); test_step.dependOn(&run.step); if (std.mem.startsWith(u8, test_file, "test/save_") or std.mem.eql(u8, test_file, "test/storage_serialization_test.zig")) save_regressions.dependOn(&run.step); for ([_][]const u8{ "test/shader_material_test.zig", "test/scene_test.zig", "test/scene_lifecycle_events_test.zig", "test/scene_teardown_test.zig", "test/prefab_refresh_test.zig", "test/jsonc/deserializer_test.zig", "test/set_material_test.zig" }) |related| { if (std.mem.eql(u8, test_file, related)) shader_regressions.dependOn(&run.step); } if (std.mem.eql(u8, test_file, "test/shader_material_test.zig")) b.step("test-shader-material", "Execute shader ownership and lifecycle tests").dependOn(&run.step); if (std.mem.startsWith(u8, test_file, "animation/test/")) legacy_animation_step.dependOn(&run.step); } // `zig build bench` — the id-column (#783) host+binding // micro-benchmark, forced ReleaseFast regardless of the top-level // optimize so the measurement is meaningful. The MEASURED code lives // in the engine module (`script_contract`), so the whole engine // module graph must be ReleaseFast too — the default `core_module`/ // `engine_module` inherit the top-level `optimize` (Debug by // default), which would silently measure Debug (#788 review). So // re-derive the graph at ReleaseFast for the bench alone. const bench_opt: std.builtin.OptimizeMode = .ReleaseFast; const core_rf = b.dependency("labelle_core", .{ .target = target, .optimize = bench_opt }).module("labelle-core"); const scene_rf = b.dependency("scene", .{ .target = target, .optimize = bench_opt }).module("scene"); const jsonc_rf = b.dependency("jsonc", .{ .target = target, .optimize = bench_opt }).module("jsonc"); const audio_types_rf = b.createModule(.{ .root_source_file = b.path("src/audio_types.zig"), .target = target, .optimize = bench_opt, }); const font_types_rf = b.createModule(.{ .root_source_file = b.path("src/font_types.zig"), .target = target, .optimize = bench_opt, }); font_types_rf.addImport("labelle-core", core_rf); const engine_rf = b.createModule(.{ .root_source_file = b.path("src/root.zig"), .target = target, .optimize = bench_opt, .link_libc = true, }); engine_rf.addImport("labelle-core", core_rf); engine_rf.addImport("target_features", targetFeatures(b, target)); engine_rf.addImport("scene", scene_rf); engine_rf.addImport("jsonc", jsonc_rf); const animation_rf = b.dependency("animation", .{ .target = target, .optimize = bench_opt }).module("animation"); engine_rf.addImport("animation", animation_rf); engine_rf.addImport("audio_types", audio_types_rf); engine_rf.addImport("font_types", font_types_rf); if (target.result.os.tag == .macos) { engine_rf.linkFramework("IOSurface", .{}); engine_rf.linkFramework("CoreFoundation", .{}); } const bench_step = b.step("bench", "Run the script-contract id-column benchmark (ReleaseFast)"); const bench_exe = b.addExecutable(.{ .name = "script_contract_bench", .root_module = b.createModule(.{ .root_source_file = b.path("test/script_contract_bench.zig"), .target = target, .optimize = bench_opt, .imports = &.{ .{ .name = "labelle-core", .module = core_rf }, .{ .name = "engine", .module = engine_rf }, }, }), }); bench_step.dependOn(&b.addRunArtifact(bench_exe).step); // PIE viewport macOS IOSurface frame stream (#547). The test // binary itself is cross-platform — on non-macOS hosts every // `test` block early-returns — so we always wire it into the // step. On macOS we additionally link the system frameworks the // test uses to look up surfaces by ID and inspect pixels: // - IOSurface for `IOSurfaceLookup`/`IOSurfaceLock`/etc. // - CoreFoundation for `CFRelease` (and the property-dict // helpers the producer side reaches through the engine module). // - OpenGL is **not** required by these tests — they read // pixels via `IOSurfaceGetBaseAddress` rather than going // through `CGLTexImageIOSurface2D`. It's still listed in the // ticket's "link these frameworks" callout for completeness // and so a future test that does want GL interop doesn't // have to re-touch build.zig. const iosurface_test_module = b.createModule(.{ .root_source_file = b.path("test/preview_iosurface_test.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "labelle-core", .module = core_module }, .{ .name = "engine", .module = engine_module }, .{ .name = "scene", .module = scene_module }, }, }); if (target.result.os.tag == .macos) { iosurface_test_module.linkFramework("IOSurface", .{}); iosurface_test_module.linkFramework("CoreFoundation", .{}); iosurface_test_module.linkFramework("OpenGL", .{}); } const iosurface_test = b.addTest(.{ .root_module = iosurface_test_module }); test_step.dependOn(&b.addRunArtifact(iosurface_test).step); // In-source tests under `src/assets/` (catalog, worker, loader, // loaders/*) cannot be dragged into a `test/*` binary through the // cross-module `engine` import — Zig only discovers top-level // `test` blocks in files that belong to the **same** module as // the test binary's root. Rooting an extra test binary directly // at `src/assets/mod.zig` gives those files a module of their // own where `_ = @import("...")` chains actually cascade the // test blocks into the binary. Added as part of #440 while the // real image loader started writing its own in-source tests. const assets_tests_module = b.createModule(.{ .root_source_file = b.path("src/assets/mod.zig"), .target = target, .optimize = optimize, // catalog.zig / worker.zig call `std.c.nanosleep`, which resolves to // an `extern "c"` decl — same libc-linkage requirement as the engine // module above. This standalone test binary doesn't go through the // `engine` import so it has to declare the link itself. .link_libc = true, }); assets_tests_module.addImport("audio_types", audio_types_module); assets_tests_module.addImport("font_types", font_types_module); const assets_tests = b.addTest(.{ .root_module = assets_tests_module }); test_step.dependOn(&b.addRunArtifact(assets_tests).step); // Issue #461 regression guard: the asset pipeline must compile // under `single_threaded = true` (WASM / emscripten default). // Historically `std.Thread.spawn` was unconditional and this // combination was a hard compile error on `main`, breaking every // downstream WASM build. A compile-only check here catches any // regression at `zig build test` time (the step it's wired to) — // no runtime needed because the point is the type-checker // reaching `std.Thread.spawn`. const assets_single_threaded_module = b.createModule(.{ .root_source_file = b.path("src/assets/mod.zig"), .target = target, .optimize = optimize, .single_threaded = true, .link_libc = true, }); assets_single_threaded_module.addImport("audio_types", audio_types_module); assets_single_threaded_module.addImport("font_types", font_types_module); const assets_single_threaded = b.addTest(.{ .root_module = assets_single_threaded_module }); test_step.dependOn(&assets_single_threaded.step); // T2 tilemap test — proves the engine `Tilemap` component + `.tmx` // decode + post-sprite render pass against the ACTUALLY-shipped gfx // 1.21.0 API. The engine module takes no gfx dependency; this test // reaches gfx's std-only `tilemap` sub-package (the `TileMap` decoder // + `TileMapRendererWith`) through the lazy `labelle_gfx` pin and // drives it over `core.mock_backend.MockBackend`. `lazyDependency` // returns null on the first uncached run and Zig re-invokes after // fetching, so downstream engine-module consumers never pull gfx. if (b.lazyDependency("labelle_gfx", .{ .target = target, .optimize = optimize })) |gfx_dep| { // gfx pins its `tilemap` sub-package in-tree (`.path = "tilemap"`); // reach that module through gfx's own builder. The sub-package is // std-only (no labelle-core), so there is no core-diamond to unify. const tilemap_module = gfx_dep.builder.dependency("tilemap", .{ .target = target, .optimize = optimize, }).module("tilemap"); const tilemap_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("test/tilemap_test.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "labelle-core", .module = core_module }, .{ .name = "engine", .module = engine_module }, .{ .name = "scene", .module = scene_module }, .{ .name = "tilemap", .module = tilemap_module }, }, }), }); test_step.dependOn(&b.addRunArtifact(tilemap_test).step); // T3 tilemap Z-interleave test — drives the `renderWithLayerHook` // (gfx v1.22.0) interleave path with a hook-capable, multi-camera // mock. Same gfx `tilemap` sub-package + MockBackend seam as the T2 // test above. const tilemap_interleave_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("test/tilemap_interleave_test.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "labelle-core", .module = core_module }, .{ .name = "engine", .module = engine_module }, .{ .name = "scene", .module = scene_module }, .{ .name = "tilemap", .module = tilemap_module }, }, }), }); test_step.dependOn(&b.addRunArtifact(tilemap_interleave_test).step); // T3 per-camera correctness (cull #711 P1 / background #709 / reap // #712). Shares mocks with the interleave test via // `tilemap_interleave_support.zig` (path-imported). const tilemap_percamera_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("test/tilemap_percamera_test.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "labelle-core", .module = core_module }, .{ .name = "engine", .module = engine_module }, .{ .name = "scene", .module = scene_module }, .{ .name = "tilemap", .module = tilemap_module }, }, }), }); test_step.dependOn(&b.addRunArtifact(tilemap_percamera_test).step); // Runtime tile mutation (#825) — `setTile` / `setTiles` / // `tilemapLayerSize` write into the DECODED map, which gfx's // immediate-mode pass re-reads each frame. Shares the mocks with the // interleave suite via `tilemap_interleave_support.zig`. const tilemap_mutation_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("test/tilemap_mutation_test.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "labelle-core", .module = core_module }, .{ .name = "engine", .module = engine_module }, .{ .name = "scene", .module = scene_module }, .{ .name = "tilemap", .module = tilemap_module }, }, }), }); test_step.dependOn(&b.addRunArtifact(tilemap_mutation_test).step); // External `.tsx` resolution (#834) — the runtime now hands gfx a // resolver backed by the same embedded registry that serves tileset // images, so a `` decodes in an embedded // build instead of failing into a warning. const tilemap_external_tsx_test = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("test/tilemap_external_tsx_test.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "labelle-core", .module = core_module }, .{ .name = "engine", .module = engine_module }, .{ .name = "scene", .module = scene_module }, .{ .name = "tilemap", .module = tilemap_module }, }, }), }); test_step.dependOn(&b.addRunArtifact(tilemap_external_tsx_test).step); } // zspec BDD specs — mirrors the `spec` step in labelle-pathfinding. // Uses zspec's own test runner; the spec files declare // `describe`-style nested structs rather than flat `test` blocks. // Wired into `test_step` as well so `zig build test` (what CI // runs) stays the single command that exercises everything. // // zspec is a `lazy` dependency: `b.lazyDependency` only resolves // (and fetches) it when a step that needs it is in the build graph, // so downstream consumers that just import the engine module never // pull this test-only dep. On the first run without the package in // cache it returns null and Zig re-invokes the build after fetching. if (b.lazyDependency("zspec", .{ .target = target, .optimize = optimize })) |zspec_dep| { const spec_module = b.createModule(.{ .root_source_file = b.path("spec/spec_tests.zig"), .target = target, .optimize = optimize, .imports = &.{ .{ .name = "zspec", .module = zspec_dep.module("zspec") }, .{ .name = "labelle-core", .module = core_module }, .{ .name = "engine", .module = engine_module }, .{ .name = "scene", .module = scene_module }, }, }); const spec_tests = b.addTest(.{ .root_module = spec_module, .test_runner = .{ .path = zspec_dep.path("src/runner.zig"), .mode = .simple }, }); const run_spec_tests = b.addRunArtifact(spec_tests); const spec_step = b.step("spec", "Run zspec BDD specs"); spec_step.dependOn(&run_spec_tests.step); test_step.dependOn(&run_spec_tests.step); } } /// What the target's libc and OS provide, as a `target_features` module the /// engine reads instead of naming platforms in `src/` (labelle-engine#902). /// The build knows the target; the source only asks about a capability. /// - `has_posix_shm`: libc ships `shm_open`/`shm_unlink`. Bionic (Android) /// does not; `libgame.so` would fail to `dlopen` with `cannot locate /// symbol "shm_unlink"` if the preview's shm code linked them. fn targetFeatures(b: *std.Build, target: std.Build.ResolvedTarget) *std.Build.Module { const options = b.addOptions(); options.addOption(bool, "has_posix_shm", !target.result.abi.isAndroid()); return options.createModule(); } /// Run the platform-agnosticism guard (labelle-engine#902) as part of /// `zig build test`, and on its own as `zig build test-guard`. It runs on the /// host with the repository root as its working directory, because it walks /// `src/` at test time; `test/agnostic_guard_test.zig` fails rather than /// passing vacuously if that walk misses the engine's root file. fn addAgnosticGuard(b: *std.Build, test_step: *std.Build.Step, optimize: std.builtin.OptimizeMode) void { const guard_tests = b.addTest(.{ .root_module = b.createModule(.{ .root_source_file = b.path("test/agnostic_guard_test.zig"), .target = b.graph.host, .optimize = optimize, }), }); const guard_run = b.addRunArtifact(guard_tests); guard_run.setCwd(b.path(".")); // The walk reads src/ at run time, which the test binary's cache inputs // do not cover: without this, a cached result (local, or a restored CI // cache) would skip the walk and let a new forbidden name through. guard_run.has_side_effects = true; test_step.dependOn(&guard_run.step); b.step("test-guard", "Check src/ for platform, store, package and backend names (labelle-engine#902)").dependOn(&guard_run.step); } /// #899: an executable rooted at `test/cross_target_check.zig` that /// references every preview socket shim and `screenshot_request.nowNs`, /// built for `query`. Callers depend on its step, which compiles it /// without linking. fn addSocketTargetCheck( b: *std.Build, query: std.Target.Query, optimize: std.builtin.OptimizeMode, ) *std.Build.Step.Compile { const check_target = b.resolveTargetQuery(query); return b.addExecutable(.{ .name = "cross_target_check", .root_module = b.createModule(.{ .root_source_file = b.path("test/cross_target_check.zig"), .target = check_target, .optimize = optimize, .link_libc = true, .imports = &.{ .{ .name = "preview_socket", .module = b.createModule(.{ .root_source_file = b.path("src/preview/socket.zig"), .target = check_target, .optimize = optimize, .link_libc = true, }) }, .{ .name = "screenshot_request", .module = b.createModule(.{ .root_source_file = b.path("src/screenshot_request.zig"), .target = check_target, .optimize = optimize, .link_libc = true, }) }, }, }), }); }