Skip to content

Share embedded Ghostty runtime state - #141

Open
azooz2003-bit wants to merge 1 commit into
feat/cmux-render-scenefrom
feat/ios-scene-runtime-state
Open

Share embedded Ghostty runtime state#141
azooz2003-bit wants to merge 1 commit into
feat/cmux-render-scenefrom
feat/ios-scene-runtime-state

Conversation

@azooz2003-bit

@azooz2003-bit azooz2003-bit commented Jul 24, 2026

Copy link
Copy Markdown

Summary

  • Preserve the initialized embedded Ghostty process runtime for renderer-side reuse.
  • Keep the iOS scene renderer on the same runtime state as the Mac scene capture path.

Verification

  • zig build test -Dtest-filter=embedded renderer shares the initialized Ghostty process runtime
  • zig fmt --check
  • git diff --check

View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.


Summary by cubic

Shares the embedded Ghostty runtime state with the renderer so both iOS scene rendering and macOS scene capture run on the same initialized runtime.

  • Bug Fixes
    • Select runtime via build_config.scene_renderer_only: use global.zig for embedded, scene_runtime.zig for renderer-only builds.
    • Added test to verify the embedded renderer and process share the same state pointer.

Written for commit 647849e. Summary will update on new commits.

Review in cubic

@coderabbitai

coderabbitai Bot commented Jul 24, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 12369434-e393-42a5-b0ad-9b852c117778

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/ios-scene-runtime-state

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@greptile-apps

greptile-apps Bot commented Jul 24, 2026

Copy link
Copy Markdown

Greptile Summary

This PR changes CApi.zig to select its process-runtime state pointer at comptime: standalone scene_renderer_only builds continue to use the minimal scene_runtime.State, while embedded builds now share the fully-initialized GlobalState from global.zig. A pointer-identity test documents the guarantee for the embedded path.

  • The comptime branch if (build_config.scene_renderer_only) @import("scene_runtime.zig") else @import("global.zig") is the only top-level change; state.alloc is the sole field accessed from either type, so both are structurally compatible with existing call sites.
  • The added test verifies that &runtime.state and &@import("../../global.zig").state resolve to the same address in non-scene-renderer-only builds, which is trivially guaranteed by Zig's module system but clearly documents the invariant.

Confidence Score: 4/5

The change is small and mechanically straightforward — one comptime selection between two well-understood modules — and the only runtime field access (state.alloc) exists in both. Safe to merge with one minor observation addressed.

The comptime branch logic is correct, the field access is compatible across both possible state types, and the test correctly documents the invariant. The only concern is the missing comptime keyword on the test guard, which could trigger analysis of a dead @import in scene-renderer-only builds and produce a compile error in that configuration.

Files Needing Attention: src/renderer/scene/CApi.zig — specifically the test guard condition at the new test block.

Important Files Changed

Filename Overview
src/renderer/scene/CApi.zig Conditionally binds state to either scene_runtime.zig (standalone) or global.zig (embedded) via a comptime branch; adds a pointer-identity test for the non-standalone case. The test guard lacks the comptime keyword, which may cause the dead branch's @import("../../global.zig") to be analyzed in scene-renderer-only builds.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["build_config.scene_renderer_only (comptime bool)"]
    A -->|true| B["@import scene_runtime.zig\n→ scene_runtime.State\n{alloc, resources_dir}"]
    A -->|false| C["@import global.zig\n→ GlobalState\n{gpa, alloc, action, logging, …}"]
    B --> D["const state = &runtime.state"]
    C --> D
    D --> E["newImpl() → state.alloc\n(only field accessed)"]
Loading

Reviews (1): Last reviewed commit: "fix(renderer): share embedded Ghostty ru..." | Re-trigger Greptile

Comment on lines +718 to +719
if (!build_config.scene_renderer_only) {
const global_state = &@import("../../global.zig").state;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 The if guard here lacks the comptime keyword. In Zig, a function-scope if without comptime still causes both branches to be analyzed for type correctness, even when the condition is a comptime-known constant. When building in scene_renderer_only = true mode, the dead branch's @import("../../global.zig") may be analyzed, potentially pulling in global.zig's transitive dependencies (xev, fontconfig, glslang, etc.) that are not available in that build configuration. Adding comptime prevents any analysis of the dead branch and makes the conditional-compilation intent explicit.

Suggested change
if (!build_config.scene_renderer_only) {
const global_state = &@import("../../global.zig").state;
if (comptime !build_config.scene_renderer_only) {
const global_state = &@import("../../global.zig").state;

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