Fix cross-compilation for md2view in GoReleaser - #55
Conversation
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]>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Documentation previewsThe rendered README and example images are available as workflow artifacts.
|
There was a problem hiding this comment.
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.
| gobinary: go | ||
| env: | ||
| - CGO_ENABLED=1 | ||
| - CGO_ENABLED=0 |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
@jules okay let's enable cgo on JUST md2view but also make it linux only
There was a problem hiding this comment.
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]>
Set
CGO_ENABLED=0for themd2viewbinary in.goreleaser.yamlto fix cross-compilation errors on CI (e.g.,linux_arm64).PR created automatically by Jules for task 190396788692862196 started by @arran4