Skip to content

Fix cross-compilation for md2view in GoReleaser - #55

Merged
arran4 merged 2 commits into
mainfrom
fix-goreleaser-md2view-cgo-190396788692862196
Jul 14, 2026
Merged

Fix cross-compilation for md2view in GoReleaser#55
arran4 merged 2 commits into
mainfrom
fix-goreleaser-md2view-cgo-190396788692862196

Conversation

@arran4

@arran4 arran4 commented Jul 13, 2026

Copy link
Copy Markdown
Owner

Set CGO_ENABLED=0 for the md2view binary in .goreleaser.yaml to fix cross-compilation errors on CI (e.g., linux_arm64).


PR created automatically by Jules for task 190396788692862196 started by @arran4

Set CGO_ENABLED=0 in .goreleaser.yaml for the md2view binary to
prevent cross-compilation failures on targets like linux_arm64.
Since we don't have C cross-compilers set up in the GoReleaser
environment, static compilation with pure Go is required.

Co-authored-by: arran4 <[email protected]>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown

Documentation previews

The rendered README and example images are available as workflow artifacts.

  • readme.png
  • examples/light-example.png
  • examples/dark-example.png

@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 disables CGO (CGO_ENABLED=0) in the GoReleaser configuration for the md2view binary. The review feedback correctly points out that disabling CGO will break this GUI application, as its dependencies (such as GLFW and Metal) require CGO to interface with native graphics APIs. It is recommended to use a cross-compilation toolchain instead of disabling CGO.

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.

Comment thread .goreleaser.yaml Outdated
gobinary: go
env:
- CGO_ENABLED=1
- CGO_ENABLED=0

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

Disabling CGO (CGO_ENABLED=0) for md2view will likely break the application on platforms that require native graphics APIs. md2view is a GUI application using golang.org/x/exp/shiny/driver and dependencies like GLFW and Metal, which rely on CGO to interface with the host's windowing and graphics systems. While setting CGO_ENABLED=0 bypasses cross-compilation errors on CI, it will result in either compilation failures or non-functional/broken binaries on target platforms (especially macOS). To properly cross-compile with CGO enabled, you should use a cross-compilation toolchain (such as Zig as a C compiler or goreleaser-cross).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

high

Disabling CGO (CGO_ENABLED=0) for md2view will likely break the application on platforms that require native graphics APIs. md2view is a GUI application using golang.org/x/exp/shiny/driver and dependencies like GLFW and Metal, which rely on CGO to interface with the host's windowing and graphics systems. While setting CGO_ENABLED=0 bypasses cross-compilation errors on CI, it will result in either compilation failures or non-functional/broken binaries on target platforms (especially macOS). To properly cross-compile with CGO enabled, you should use a cross-compilation toolchain (such as Zig as a C compiler or goreleaser-cross).

@jules are there any workarounds?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're absolutely right. I verified that setting CGO_ENABLED=0 allowed it to compile, but looking deeper into golang.org/x/exp/shiny, its macOS implementation (gldriver via cocoa.go) explicitly imports "C" for interacting with the Cocoa/OpenGL APIs. A statically linked md2view on macOS won't be able to open a window.

Since this is a markdown renderer meant to also act as a GUI viewer on local machines, CGO is fundamentally required on some OSs (like macOS and potentially X11/Linux, though X11 driver sometimes has pure Go implementations like github.com/jezek/xgb, the macOS Cocoa one definitively uses CGO).

If we strictly need to distribute md2view via GoReleaser on GitHub Actions and lack a cross-compiler (like Zig) in the runner, a workaround is to skip building md2view for cross-platform targets (like linux_arm64 when on ubuntu-latest) or skip it entirely in GoReleaser and let users go install it natively. Another approach is to set up a docker image with cross-compilers in the GoReleaser pipeline, or use zig cc.

I will revert CGO_ENABLED=0 to CGO_ENABLED=1 in my PR to avoid breaking the binaries, and investigate skipping failing architectures or configuring zig cc. Let me know if you prefer a specific approach (e.g. limiting md2view to native builds only).

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@jules okay let's enable cgo on JUST md2view but also make it linux only

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have restricted md2view to CGO_ENABLED=1 and set it to only compile for linux amd64 (since linux_arm64 cross compilation is what caused the CI pipeline to fail). This avoids breaking the target binary on platforms without cross-compilation support in this GoReleaser environment. It will now only be distributed for Linux x86_64 where it can be natively built. The CI pipeline will pass successfully.

GoReleaser CI fails when cross-compiling the CGO-dependent `md2view`
binary for non-native targets (like linux_arm64, darwin, windows)
because it lacks proper C cross-compilers in the ubuntu-latest runner.
This restricts the md2view build strictly to linux/amd64 where CGO
can safely build natively, allowing the pipeline to pass.

Co-authored-by: arran4 <[email protected]>
@arran4
arran4 merged commit 8782aba into main Jul 14, 2026
11 checks passed
@arran4
arran4 deleted the fix-goreleaser-md2view-cgo-190396788692862196 branch July 14, 2026 02:39
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