refactor: split build_files.zig into focused sub-modules (behavior-preserving) - #549
Conversation
…eserving) Pure extraction, mirrors #539/#541. `build_files.zig` was a single ~1165-line module; it is now a 35-line barrel re-exporting the public surface from two cohesive sub-modules under `build_files/`: - build_files/build_zig.zig — build.zig generation (sanitizeExeName, BuildZigOptions, generateBuildZig, emit* helpers, desktopUsesGenericV2, ...) - build_files/build_zig_zon.zig — build.zig.zon generation (BuildZigZonOptions, generateBuildZigZon, deps-link/fallback path, deps_linker re-export, v2BackendDepName, relativePath) Split along the natural build.zig-vs-build.zig.zon seam; no private helper crosses the boundary. Public surface (root.zig call sites) unchanged; every symbol keeps its name and identity. Sub-files are path-@import'd (no build.zig change). `zig build` + `zig build test` green; golden suite zero diff; `zig fmt --check` clean. Claude-Session: https://claude.ai/code/session_017pW3ifKf9wgxNg4viy6okw
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe monolithic Changesbuild.zig / build.zig.zon generator split
Estimated code review effort: 4 (Complex) | ~60 minutes Sequence Diagram(s)sequenceDiagram
participant Caller
participant generateBuildZig
participant ManifestV2
participant PackModules
participant Template
Caller->>generateBuildZig: generateBuildZig(allocator, cfg, opts)
generateBuildZig->>ManifestV2: load/validate backend manifest
ManifestV2-->>generateBuildZig: capabilities or UnsupportedCapability
generateBuildZig->>PackModules: emitPackModules / emitPromotedScriptModules
PackModules-->>generateBuildZig: wired modules
generateBuildZig->>Template: emit platform header/link/footer sections
Template-->>Caller: rendered build.zig text
sequenceDiagram
participant Caller
participant generateBuildZigZon
participant deps_linker
participant ManifestV2
participant Template
Caller->>generateBuildZigZon: generateBuildZigZon(allocator, cfg, target_dir, output_dir, project_dir, opts)
generateBuildZigZon->>deps_linker: createDepsLinks(.labelle/deps)
deps_linker-->>generateBuildZigZon: linked paths or fallback
generateBuildZigZon->>ManifestV2: derive root deps / backend dep re-key when v2 enabled
ManifestV2-->>generateBuildZigZon: dep entries
generateBuildZigZon->>Template: render header/footer with fingerprint and deps
Template-->>Caller: rendered build.zig.zon text
Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Code Review
This pull request refactors src/build_files.zig by splitting the large module into a thin barrel file that re-exports two new sub-modules: src/build_files/build_zig.zig for build.zig generation and src/build_files/build_zig_zon.zig for build.zig.zon generation. The review feedback identifies a potential memory leak in both sub-modules where converting the allocating writer's buffer to an ArrayList could leak memory if a subsequent toOwnedSlice call fails with an out-of-memory error. Adding an errdefer to deinit the ArrayList in both files is recommended to prevent this leak.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
|
|
||
| var arr_list = alloc_writer.toArrayList(); |
There was a problem hiding this comment.
When moving the allocating writer's buffer to an ArrayList via toArrayList(), the writer is reset to empty. To prevent memory leaks if the subsequent toOwnedSlice fails with OutOfMemory, an errdefer should be added to deinit the ArrayList.
var arr_list = alloc_writer.toArrayList();
errdefer arr_list.deinit(allocator);
return arr_list.toOwnedSlice(allocator);
References
- In Zig, when moving an allocating writer's buffer to an ArrayList via toArrayList(), the writer is reset to empty. To prevent memory leaks if a subsequent toOwnedSlice fails with OutOfMemory, add an errdefer to deinit the ArrayList.
| var arr_list = alloc_writer.toArrayList(); | ||
| return arr_list.toOwnedSlice(allocator); |
There was a problem hiding this comment.
When moving the allocating writer's buffer to an ArrayList via toArrayList(), the writer is reset to empty. To prevent memory leaks if the subsequent toOwnedSlice fails with OutOfMemory, an errdefer should be added to deinit the ArrayList.
var arr_list = alloc_writer.toArrayList();
errdefer arr_list.deinit(allocator);
return arr_list.toOwnedSlice(allocator);
References
- In Zig, when moving an allocating writer's buffer to an ArrayList via toArrayList(), the writer is reset to empty. To prevent memory leaks if a subsequent toOwnedSlice fails with OutOfMemory, add an errdefer to deinit the ArrayList.
Rebuilt onto the six parallel split-refactors (#539-#549): identical semantics, new homes — scanPack verb-copy in root/pack_scan.zig, surface+depends_on emission in build_files/build_zig.zig, the .all diagnostic in plugin_manifest/pack.zig. pack_root/pack_validate/ pack_refs/tests/docs carried verbatim (untouched by the splits). Includes the review fixes from the first head: @"…" escaping on exposed verb idents both sides, token-sequence .exposes = .all detection (exposesAllShorthand), docs aligned with header-only + targeted-diagnostic behavior. Claude-Session: https://claude.ai/code/session_01P7YLw4hXFCCaY2LAUt4G1j
…548) Rebuilt onto the six parallel split-refactors (#539-#549): identical semantics, new homes — scanPack verb-copy in root/pack_scan.zig, surface+depends_on emission in build_files/build_zig.zig, the .all diagnostic in plugin_manifest/pack.zig. pack_root/pack_validate/ pack_refs/tests/docs carried verbatim (untouched by the splits). Includes the review fixes from the first head: @"…" escaping on exposed verb idents both sides, token-sequence .exposes = .all detection (exposesAllShorthand), docs aligned with header-only + targeted-diagnostic behavior. Claude-Session: https://claude.ai/code/session_01P7YLw4hXFCCaY2LAUt4G1j
What
Pure, behavior-preserving extraction of
src/build_files.zig(~1165 lines) into asrc/build_files/sub-package, leavingbuild_files.ziga thin 35-line barrel. Mirrors the proven #539/#541 pattern.Sections
Split along the natural, cohesive seam the file already documented with
====banners: build.zig generation vs build.zig.zon generation. No private helper crosses the boundary (sanitizeExeNameis build.zig-only;v2BackendDepName/relativePath/generateZonPathsFallbackare zon-only), so there are no circular imports.build_files/build_zig.zig(862 lines) —sanitizeExeName,BuildZigOptions,generateBuildZig, plus theemit*helpers,desktopUsesGenericV2,androidNeedsAppImport,inProjectLibDir.build_files/build_zig_zon.zig(323 lines) —BuildZigZonOptions,generateBuildZigZon, the deps-link/fallback path, thedeps_linkerre-export,v2BackendDepName,relativePath.build_files.zig(35 lines) — barrel re-exporting the exact public surface.Unchanged public surface
Every re-exported symbol keeps its original name and identity, so
root.zig'sbuild_files.generateBuildZig/BuildZigOptions/generateBuildZigZon/deps_linkercall sites are untouched. Sub-files are path-@import'd (embed paths adjustedtemplates/…→../templates/…); nobuild.zigchange.Before / after
build_files.zigbuild_files/build_zig.zigbuild_files/build_zig_zon.zigBar
zig build— greenzig build test— green (exit 0)zig build test; any byte divergence would fail the run)zig fmt --check— cleanhttps://claude.ai/code/session_017pW3ifKf9wgxNg4viy6okw
Summary by CodeRabbit