Skip to content

refactor: split manifest_v2_splice.zig into per-platform sub-modules (behavior-preserving) - #544

Merged
apotema merged 1 commit into
mainfrom
refactor/split-v2splice
Jul 5, 2026
Merged

apotema merged 1 commit into
mainfrom
refactor/split-v2splice

Conversation

@apotema

@apotema apotema commented Jul 5, 2026 •

Copy link
Copy Markdown
Contributor

What

Pure, behavior-preserving extraction of the 1501-line src/codegen/manifest_v2_splice.zig (manifest-v2 → build.zig codegen) into a focused manifest_v2_splice/ sub-package, split along the cohesive per-platform seam. Follows the proven #539 pattern (barrel + path-@import sub-files, no build.zig change).

Sections / platforms extracted

Sub-module Contents
common.zig cross-platform helpers: depOptionValue, mergeDepOptions, moduleAlias, artifactIdent, emitCoreDiamondWalk, isDesktopByteAnchor, hook_import_name, stageBackendBuildHook, platformEntry, renderPackageV2, emitRootBuildDepsV2
desktop.zig desktop byte-anchor + generic emitters (renderDesktop*) + the sokol anchor residual constants
android.zig renderAndroidHeaderV2 / DepsDeclsV2 / BackendDepV2 / LinkV2
ios.zig renderIosHeaderV2 / DepsDeclsV2 / BackendDepV2 / LinkV2
wasm.zig renderWasmHeaderV2 / DepsDeclsV2 / BackendDepV2 / LinkV2 / FooterV2 + footer-helpers const
dispatch.zig the two switch (cfg.platform) routers (renderBackendDepSectionV2, renderLinkSectionV2)

manifest_v2_splice.zig is now a thin barrel: re-exports the unchanged public surface (every symbol keeps its original name/identity, so manifest_v2_splice.<Name> call sites in build_files.zig / root.zig are untouched) plus a test { _ = sub; } block to pull sub-module tests into zig build test.

Layering (acyclic, no forced coupling)

common (leaf) ← desktop/android/ios/wasm ← dispatch; barrel imports all. Dispatchers live in dispatch.zig so the platform modules stay leaf consumers of common with no cross-platform imports and no cycle. Tests moved with the code they cover; sub-file @import/@embedFile paths shifted one level deeper.

Verification

  • zig build — green
  • zig build test — green (exit 0), including the byte-exact golden suite (test/build_zig_tests.zig, expectEqualStrings against embedded .build.zig goldens) → zero golden diff
  • zig fmt --check — clean

No behavior change; no reviewer-flagged bugs fixed here (pure extraction).

https://claude.ai/code/session_017pW3ifKf9wgxNg4viy6okw

Summary by CodeRabbit

  • New Features

    • Added updated manifest-v2 generation support across desktop, Android, iOS, and WebAssembly targets.
    • Improved platform-specific build output generation with more consistent dependency, linking, and packaging handling.
  • Bug Fixes

    • Preserved existing generated behavior while simplifying the code path behind the scenes.
    • Added broader test coverage to help catch regressions in generated build output.

…(behavior-preserving)

Pure extraction of the 1501-line `src/codegen/manifest_v2_splice.zig` into a
`manifest_v2_splice/` sub-package along the per-platform seam, mirroring #539.
The barrel re-exports the unchanged public surface; every symbol keeps its
name and identity so `manifest_v2_splice.<Name>` call sites are untouched.

  - common.zig   — cross-platform helpers (dep-option values, merge,
                   module/artifact idents, generic walk splice, byte-anchor
                   discriminator, hook staging, packaging, root build-deps)
  - desktop.zig  — desktop byte-anchor + generic emitters + sokol residual
  - android.zig / ios.zig / wasm.zig — per-platform header/deps/backend-dep/link
  - dispatch.zig — the backend-dep + link section routers
  - manifest_v2_splice.zig — thin barrel (re-exports + test pull-in)

Sub-file `@import`/`@embedFile` paths shifted one level deeper. Tests moved
with the code they cover. No behavior change: `zig build` + `zig build test`
green, golden byte-comparison suite zero diff, `zig fmt --check` clean.

Claude-Session: https://claude.ai/code/session_017pW3ifKf9wgxNg4viy6okw
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@coderabbitai

coderabbitai Bot commented Jul 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The monolithic manifest_v2_splice.zig implementation is refactored into a thin barrel module that re-exports functionality now split across new files under manifest_v2_splice/: common.zig, dispatch.zig, desktop.zig, android.zig, ios.zig, and wasm.zig, each with associated unit tests.

Changes

Manifest-v2 splice refactor into submodules

Layer / File(s) Summary
Barrel module re-exports
src/codegen/manifest_v2_splice.zig
File is reduced to imports and pub const re-exports of the previously in-file public entrypoints, plus a test {} shim referencing submodules.
Shared common helpers
src/codegen/manifest_v2_splice/common.zig
Adds dep-option merge/value resolution, module alias helper, core diamond walk emission, desktop byte-anchor detection, artifact identifier sanitization, backend build hook staging, platform entry lookup, package rendering, root build deps emission, and their tests.
Dispatch routing
src/codegen/manifest_v2_splice/dispatch.zig
Adds renderBackendDepSectionV2/renderLinkSectionV2 dispatching by platform, with desktop further branching on byte-anchor vs generic mode.
Desktop emitters and tests
src/codegen/manifest_v2_splice/desktop.zig
Adds generic and byte-anchor desktop dependency/link emitters, per-OS link switch generation, byte-anchor residual constants, and tests.
Android emitters
src/codegen/manifest_v2_splice/android.zig
Adds header, deps declarations, backend dependency emission with unifyCoreDiamond walk, and link emission delegating to backend hook post_wire.
iOS emitters
src/codegen/manifest_v2_splice/ios.zig
Adds header (resolve_target + sdk_path), deps declarations, backend dependency emission, and link emission via post_wire with SDK path context.
WASM emitters and drift test
src/codegen/manifest_v2_splice/wasm.zig
Adds header/deps for a fixed wasm target, backend dependency emission, link emission delegating to post_wire, footer helpers, and a drift-guard test against the android footer template.

Estimated code review effort: 4 (Complex) | ~60 minutes

Possibly related issues

Possibly related PRs

Poem

A monolith once stood so tall,
Now split into modules, one for all—
Desktop, Android, iOS, and Wasm too,
Each hopping off with work to do. 🐇
Barrel re-exports tie them tight,
This bunny thumps with pure delight! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: splitting manifest_v2_splice.zig into per-platform submodules while preserving behavior.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/split-v2splice

Comment @coderabbitai help to get the list of available commands.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors src/codegen/manifest_v2_splice.zig by splitting the large ~1500-line module into focused, per-platform sub-modules under src/codegen/manifest_v2_splice/ (specifically common.zig, desktop.zig, android.zig, ios.zig, wasm.zig, and dispatch.zig). The original file is simplified into a thin barrel module that re-exports the public surface, preserving all symbol names and identities. I have no feedback to provide as there are no review comments and the changes are a clean, behavior-preserving refactoring.

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/codegen/manifest_v2_splice/desktop.zig (1)

79-97: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Duplicated core-diamond-walk boilerplate across all four platform emitters.

The "Generic core+gfx-diamond unification" comment block + core_diamond_visited setup (lines 83-92) is repeated near-verbatim in android.zig (125-134), ios.zig (110-119), and wasm.zig (109-118) — only the target var name / extra-modules loop differ. Since common.zig already hosts shared helpers (mergeDepOptions, moduleAlias, artifactIdent), consider extracting this into a shared common.emitCoreDiamondWalkHeader(w) (and optionally a loop helper taking a modules slice) to prevent the four copies from silently drifting.

♻️ Sketch of a shared helper
// common.zig
pub fn emitCoreDiamondWalkHeader(w: anytype) !void {
    try w.writeAll(
        \\
        \\    // Generic core+gfx-diamond unification (design §5) — the loop form of
        \\    // the per-site overrideImport diamond (golden cell, not the desktop
        \\    // byte-anchor's unrolled form). Rooted at each imported provider.
        \\    var core_diamond_visited: std.AutoHashMapUnmanaged(*std.Build.Module, void) = .empty;
        \\    unifyCoreDiamond(b.allocator, gfx_mod, core_mod, gfx_mod, &core_diamond_visited);
        \\    unifyCoreDiamond(b.allocator, engine_mod, core_mod, gfx_mod, &core_diamond_visited);
        \\
    );
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/codegen/manifest_v2_splice/desktop.zig` around lines 79 - 97, The
core-diamond walk boilerplate is duplicated across the platform emitters, so
refactor `desktop.zig` to use a shared helper instead of inlining the same
header/setup block. Move the repeated “Generic core+gfx-diamond unification”
comment plus `core_diamond_visited` initialization and the common
`unifyCoreDiamond` calls into `common.zig` as a reusable emitter (for example, a
`emitCoreDiamondWalkHeader` helper), then have `desktop.zig` call it and keep
only the platform-specific module loop. This should align the `desktop.zig`,
`android.zig`, `ios.zig`, and `wasm.zig` emit paths around the shared helper and
reduce drift.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/codegen/manifest_v2_splice/android.zig`:
- Around line 110-114: Artifact names are being emitted verbatim as Zig
identifiers in the android manifest splice, which can generate invalid code for
free-form names like hyphenated or numeric artifacts. Update the generation in
android.zig to use common.artifactIdent for both the const declaration and the
later linkLibrary/artifact reference sites, and apply the same identifier
sanitization in the matching ios.zig and wasm.zig generation paths.

---

Nitpick comments:
In `@src/codegen/manifest_v2_splice/desktop.zig`:
- Around line 79-97: The core-diamond walk boilerplate is duplicated across the
platform emitters, so refactor `desktop.zig` to use a shared helper instead of
inlining the same header/setup block. Move the repeated “Generic
core+gfx-diamond unification” comment plus `core_diamond_visited` initialization
and the common `unifyCoreDiamond` calls into `common.zig` as a reusable emitter
(for example, a `emitCoreDiamondWalkHeader` helper), then have `desktop.zig`
call it and keep only the platform-specific module loop. This should align the
`desktop.zig`, `android.zig`, `ios.zig`, and `wasm.zig` emit paths around the
shared helper and reduce drift.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: a504873a-c870-4942-a4b4-add7579255c8

📥 Commits

Reviewing files that changed from the base of the PR and between 990f68f and fa97875.

📒 Files selected for processing (7)
  • src/codegen/manifest_v2_splice.zig
  • src/codegen/manifest_v2_splice/android.zig
  • src/codegen/manifest_v2_splice/common.zig
  • src/codegen/manifest_v2_splice/desktop.zig
  • src/codegen/manifest_v2_splice/dispatch.zig
  • src/codegen/manifest_v2_splice/ios.zig
  • src/codegen/manifest_v2_splice/wasm.zig

Comment on lines +110 to +114
// GENERATED: artifact decls + declarative `.pic` (design §2 note 1).
for (android.artifacts) |art| {
try w.print(" const {s} = backend_dep.artifact(\"{s}\");\n", .{ art.name, art.name });
if (art.pic) try w.print(" {s}.root_module.pic = true;\n", .{art.name});
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== files ==\n'
git ls-files 'src/codegen/manifest_v2_splice/*' | sort

printf '\n== artifactIdent references ==\n'
rg -n "artifactIdent|art\.name|backend_dep\.artifact|linkLibrary" src/codegen/manifest_v2_splice -S

printf '\n== android.zig slice ==\n'
sed -n '1,240p' src/codegen/manifest_v2_splice/android.zig

printf '\n== desktop.zig slice ==\n'
sed -n '1,260p' src/codegen/manifest_v2_splice/desktop.zig

printf '\n== ios.zig slice ==\n'
sed -n '1,240p' src/codegen/manifest_v2_splice/ios.zig

printf '\n== wasm.zig slice ==\n'
sed -n '1,240p' src/codegen/manifest_v2_splice/wasm.zig

printf '\n== common helper search ==\n'
rg -n "pub fn artifactIdent|fn artifactIdent|artifactIdent\\(" src -S

Repository: labelle-toolkit/labelle-assembler

Length of output: 49944


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '\n== common.zig around artifactIdent ==\n'
sed -n '100,170p' src/codegen/manifest_v2_splice/common.zig

printf '\n== manifest artifact name definitions ==\n'
rg -n "artifact.*name|name.*artifact|artifacts" src/manifest_v2.zig src -S

printf '\n== tests mentioning artifactIdent or invalid names ==\n'
rg -n "artifactIdent|glfw-native|123lib|artifact.*ident|invalid.*identifier" src/codegen/manifest_v2_splice -S

Repository: labelle-toolkit/labelle-assembler

Length of output: 9967


Sanitize artifact names before emitting Zig identifiers src/codegen/manifest_v2_splice/android.zig:110-114,158-160
art.name is used verbatim for both the decl and linkLibrary reference. Manifest artifact names are free-form, so glfw-native or 123lib would make the generated Zig invalid; switch these sites to common.artifactIdent (same fix is needed in ios.zig and wasm.zig).

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/codegen/manifest_v2_splice/android.zig` around lines 110 - 114, Artifact
names are being emitted verbatim as Zig identifiers in the android manifest
splice, which can generate invalid code for free-form names like hyphenated or
numeric artifacts. Update the generation in android.zig to use
common.artifactIdent for both the const declaration and the later
linkLibrary/artifact reference sites, and apply the same identifier sanitization
in the matching ios.zig and wasm.zig generation paths.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant