Repository navigation
refactor(codegen): extract lifecycle/callback.zig from main_zig.zig (#183 step 8b) - #203
Conversation
There was a problem hiding this comment.
Code Review
This pull request extracts the callback-lifecycle code builders (buildCallbackInitCode, buildImmersiveEntryCode, and buildCallbackCleanupCode) from src/main_zig.zig into a dedicated submodule src/codegen/lifecycle/callback.zig. To avoid breaking existing orchestrator calls, these functions are re-exported in src/main_zig.zig. Additionally, several helper functions and types in src/main_zig.zig have been made public so they can be accessed by the new submodule. I have no feedback to provide as there are no review comments to assess.
PR SummaryMedium Risk Overview
Behavior is intended unchanged: init emission order (image wiring → audio/font → resources → scenes → runner/plugins) and error style ( Reviewed by Cursor Bugbot for commit 993f5f3. Bugbot is set up for automated code reviews on this repo. Configure here. |
…part of #183) Per the plan in #193. Moved buildCallbackInitCode + buildImmersiveEntryCode + buildCallbackCleanupCode (sokol/wasm/Android callback path) to src/codegen/lifecycle/callback.zig (252 lines). Re-exported from main_zig.zig so callers in the orchestrator stay unchanged. HIGH-risk extraction per the plan -- preserves call order across the preview-mode wiring constants and the wasm/Android conditional branches. Verified bit-identical across all 8 working bundled examples (scripts/gen_all_examples.sh). The asset-wiring + resource-loader helpers (writeImageBackendWiring, writeAudioBackendWiring, writeFontBackendWiring, emitResourceLoad, LoadStyle) are still in main_zig.zig because the matching blocks/asset_wiring.zig + blocks/resource_loader.zig extractions (plan steps 4-5) haven't landed yet; the new submodule reaches them through @import("../../main_zig.zig") in the meantime. When those blocks land, the import flips to the new module paths and the pub markers in main_zig.zig revert to private. Refs: #183 Builds on: #202 (umbrella) Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
79e8b58 to
993f5f3
Compare
Summary
Step 8b of the cut plan in
docs/REFACTOR-PLAN-main-zig.md(#193). Moves the three callback-lifecycle builders --buildCallbackInitCode,buildImmersiveEntryCode,buildCallbackCleanupCode-- fromsrc/main_zig.zigto a newsrc/codegen/lifecycle/callback.zigsubmodule (252 lines, all 3 functions plus header doc).main_zig.zig: 3817 -> 3636 lines (-181).pub const lifecycle_callback = @import("codegen/lifecycle/callback.zig");plus three private aliases keep the orchestrator's call sites (lines 3315 / 3332 / 3447) unchanged.buildSetupCode's call order across image-wiring -> conditional audio/font -> resource loads -> prefabs -> JSONC scenes + manifests + initial state ->setScene->runner.setup-> plugin systems + controllers. Preserved exactly; verified by bit-identical diff below.Why the still-here helpers stayed put
writeImageBackendWiring,writeAudioBackendWiring,writeFontBackendWiring,emitResourceLoad, andLoadStyleare dependencies ofbuildCallbackInitCode-- but the matchingblocks/asset_wiring.zig+blocks/resource_loader.zigextractions (plan steps 4-5) haven't landed yet. Rather than churn them through an intermediate location, the new submodule reaches them through@import("../../main_zig.zig")and they were promoted fromfntopub fn(visibility only -- zero logic edit). When the block extractions land, the import flips and these revert to private.pathToIdentis reached viascan.zigdirectly (already extracted in the PoC), avoiding an unnecessary main_zig.zig round-trip.Verification
Test plan
zig buildsucceedszig build testexit 0, 506/510 expectedmain.zigbyte-identical across raylib / sokol / null / plugin-controllers / flows-smoke / asset-streaming-smoke / bgfx / wgpuscripts/gen_all_examples.shagainst the umbrella after the parallellifecycle/loop.zigPR landsCoordination
A sibling agent is extracting
src/codegen/lifecycle/loop.zigin parallel off the same umbrella. Different functions, non-overlapping line ranges inmain_zig.zig. The re-export header will have a small mechanical merge at merge time (one extrapub const lifecycle_loop = ...line next to this PR'spub const lifecycle_callback = ...).Builds on: #202 (umbrella
feat/183-split-main-zig)Refs: #183