Skip to content

fix: support OpenGL renderer in Linux lib (embedded) builds - #95

Open
ddaydroid wants to merge 2 commits into
manaflow-ai:mainfrom
ddaydroid:linux-embedded-lib
Open

fix: support OpenGL renderer in Linux lib (embedded) builds#95
ddaydroid wants to merge 2 commits into
manaflow-ai:mainfrom
ddaydroid:linux-embedded-lib

Conversation

@ddaydroid

@ddaydroid ddaydroid commented Jul 9, 2026

Copy link
Copy Markdown

Building libghostty on Linux with -Dapp-runtime=none previously failed:

  • glad was only compiled into non-lib artifacts, leaving
    gladLoaderLoadGLContext/gladLoaderUnloadGLContext undefined in the
    shared lib. Compile glad for Linux lib artifacts too.
  • renderer/OpenGL.zig displayRealized had a comptime guard allowing only
    the GTK apprt. Allow the embedded apprt with the same contract: the
    host realizes the GL display and makes the context current before
    calling in.

View with Codesmith Autofix with Codesmith
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.


Summary by cubic

Fixes OpenGL renderer support for Linux embedded libghostty builds. Compiles glad for Linux lib targets when using the OpenGL renderer and lets the embedded runtime call displayRealized with the same GL-context contract as GTK.

  • Bug Fixes
    • Compile glad into Linux lib artifacts on Linux when renderer is .opengl to provide gladLoader* symbols.
    • Allow apprt.embedded in renderer/OpenGL.zig so hosts pre-create and bind the GL context before calling in.

Written for commit 99256d2. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • OpenGL rendering is now supported in embedded Linux builds in addition to the standard desktop app.
    • The app prepares the graphics context during display setup for both runtime modes.
  • Bug Fixes

    • Improved build behavior to include required OpenGL/GL loader sources only when needed, including for Linux library builds.
    • Updated runtime handling to accept both GTK and embedded callers, avoiding invalid-caller errors during display realization.

Building libghostty on Linux with -Dapp-runtime=none previously failed:

- glad was only compiled into non-lib artifacts, leaving
  gladLoaderLoadGLContext/gladLoaderUnloadGLContext undefined in the
  shared lib. Compile glad for Linux lib artifacts too.
- renderer/OpenGL.zig displayRealized had a comptime guard allowing only
  the GTK apprt. Allow the embedded apprt with the same contract: the
  host realizes the GL display and makes the context current before
  calling in.
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Build configuration now compiles vendored glad OpenGL sources for Linux library builds in addition to non-library builds, via a new needs_glad condition. The OpenGL renderer's displayRealized function also handles embedded runtimes alongside GTK.

Changes

Glad and embedded runtime OpenGL support

Layer / File(s) Summary
Conditional glad compilation
src/build/SharedDeps.zig
Adds needs_glad, true for non-library steps or Linux OpenGL library steps, gating the vendored glad include path and gl.c compilation.
Embedded apprt display realization
src/renderer/OpenGL.zig
displayRealized handles both apprt.gtk and apprt.embedded, calling prepareContext(null) for either and updating the default-case error message.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: enabling OpenGL renderer support for Linux embedded library builds.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 9, 2026

Copy link
Copy Markdown

Greptile Summary

This PR fixes two gaps that prevented libghostty from building on Linux with -Dapp-runtime=none: glad was not compiled into lib artifacts, and displayRealized in the OpenGL renderer rejected the embedded apprt at compile time.

  • SharedDeps.zig: Introduces a needs_glad flag that compiles glad for all non-lib builds (unchanged) and now also for Linux lib builds, supplying the missing gladLoaderLoadGLContext/gladLoaderUnloadGLContext symbols.
  • OpenGL.zig: Extends the displayRealized switch to accept apprt.embedded under the same contract as apprt.gtk — the host is responsible for making the GL context current before invoking the function.

Confidence Score: 4/5

Safe to merge — the changes are narrowly scoped to the Linux lib build path and a compile-time switch extension; no existing build configurations are affected.

Both changes are small and targeted. The OpenGL renderer change is a clean symmetrical extension. The only open question is whether needs_glad should also check the renderer configuration rather than keying on the OS alone, but in practice this is harmless since glad is a lightweight C file and Linux lib builds are currently only used with the OpenGL renderer.

src/build/SharedDeps.zig — the needs_glad condition is slightly broader than the stated intent; worth a second look if additional renderer backends are ever added for Linux lib builds.

Important Files Changed

Filename Overview
src/build/SharedDeps.zig Extracts glad compilation into a separate needs_glad gate that fires for all non-lib builds (unchanged) and now also for any Linux lib build, fixing the missing glad symbols in libghostty on Linux.
src/renderer/OpenGL.zig Adds apprt.embedded alongside apprt.gtk in the displayRealized switch, allowing the embedded host to call this function after making the GL context current — symmetric treatment, no new code path.

Sequence Diagram

%%{init: {'theme': 'neutral'}}%%
sequenceDiagram
    participant Host as Embedded Host (cmux)
    participant Lib as libghostty (Linux)
    participant GL as OpenGL Renderer
    participant Glad as glad (gl.c)

    Host->>Lib: initialize libghostty
    Note over Lib,Glad: glad now compiled into Linux lib builds
    Host->>Host: "create GL context & make current"
    Host->>Lib: call displayRealized()
    Lib->>GL: displayRealized() [apprt.embedded]
    GL->>Glad: prepareContext(null)
    Glad-->>GL: GL function pointers loaded
    GL-->>Lib: ok
    Lib-->>Host: display ready
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
sequenceDiagram
    participant Host as Embedded Host (cmux)
    participant Lib as libghostty (Linux)
    participant GL as OpenGL Renderer
    participant Glad as glad (gl.c)

    Host->>Lib: initialize libghostty
    Note over Lib,Glad: glad now compiled into Linux lib builds
    Host->>Host: "create GL context & make current"
    Host->>Lib: call displayRealized()
    Lib->>GL: displayRealized() [apprt.embedded]
    GL->>Glad: prepareContext(null)
    Glad-->>GL: GL function pointers loaded
    GL-->>Lib: ok
    Lib-->>Host: display ready
Loading

Reviews (1): Last reviewed commit: "fix: support OpenGL renderer in Linux li..." | Re-trigger Greptile

Comment thread src/build/SharedDeps.zig Outdated

@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.

🧹 Nitpick comments (1)
src/renderer/OpenGL.zig (1)

172-176: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Stale TODO in surfaceInit for embedded.

The TODO at line 173 states libghostty is "strictly broken for rendering on this platforms," but displayRealized now actively prepares the GL context for embedded. While surfaceInit and threadEnter still no-op for embedded (by design — the host handles those responsibilities), the "strictly broken" characterization is no longer fully accurate. Consider updating the TODO to reflect the new state.

🤖 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/renderer/OpenGL.zig` around lines 172 - 176, The stale TODO in
surfaceInit’s apprt.embedded branch no longer matches the current embedded GL
flow, since displayRealized now prepares the context. Update the comment near
surfaceInit to reflect that embedded rendering setup is now partially handled by
displayRealized while surfaceInit and threadEnter remain intentional no-ops, and
remove the “strictly broken” wording.
🤖 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.

Nitpick comments:
In `@src/renderer/OpenGL.zig`:
- Around line 172-176: The stale TODO in surfaceInit’s apprt.embedded branch no
longer matches the current embedded GL flow, since displayRealized now prepares
the context. Update the comment near surfaceInit to reflect that embedded
rendering setup is now partially handled by displayRealized while surfaceInit
and threadEnter remain intentional no-ops, and remove the “strictly broken”
wording.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 013b4044-a6a9-4c7f-9f1e-4dccd70ca777

📥 Commits

Reviewing files that changed from the base of the PR and between 8495e58 and c8bb0e8.

📒 Files selected for processing (2)
  • src/build/SharedDeps.zig
  • src/renderer/OpenGL.zig

Co-authored-by: greptile-apps[bot] <165735046+greptile-apps[bot]@users.noreply.github.com>
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