go-gui sdl2 shim - #1
Draft
cataggar wants to merge 3 commits into
Draft
Conversation
Add gosdl3/, a cgo Go binding for SDL3 generated from the SDL3 headers, with zig build gentc / zig build gensdl3 steps in build.zig: gentc runs translate-c -> gosdl3/cimport.zig (function signatures with C typedef/enum names preserved); gensdl3 builds gosdl3/gen.zig (@cImport for consts/type-aliases + @embedfile cimport.zig to parse fn signatures) and writes gosdl3/sdl3/sdl3.go. Also ignore the zig-out-static/ build output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add go-sdl2-sdl3/, a self-contained cgo package (module github.com/veandco/go-sdl2) that implements the subset of the go-sdl2 sdl API used by go-gui's SDL renderer and OpenGL backends, the sdlkey helper, and the go-glyph SDL backend, directly on SDL3. It lets go-gui target SDL3 without sdl2-compat. Linkage is build-tag selectable: dynamic by default (SDL3.dll) or static via -tags sdl3static (single DLL-free exe). cgo paths reference the repo's zig-out / zig-out-static SDL3 build outputs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add a mix package (github.com/veandco/go-sdl2/mix) plus sdl audio helpers (INIT_AUDIO, InitSubSystem/QuitSubSystem, RWFromMem/RWops) so go-gui's gui/audio builds on SDL3. SDL3 does not bundle SDL_mixer, so this is a small mixing engine on SDL3's audio API: one logical device with per-channel auto-mixed SDL_AudioStreams plus a music stream; looping/fades via a pure-C get-callback; volume via per-stream gain. WAV is decoded natively by SDL3; MP3 and OGG via vendored public-domain decoders (dr_mp3, stb_vorbis). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Go interop layers on top of this Zig-built SDL3 so go-gui (and downstream apps) can target SDL3 directly — no
sdl2-compat, no MSYS2/MinGW — and produce single-shared-library or fully static builds.Three independent pieces, on top of the
release-3.4.xSDL 3.4.10 base:1.
go-sdl2-sdl3/sdl— go-sdl2 API shim on SDL3A cgo drop-in replacement for the subset of
github.com/veandco/go-sdl2/sdlthat go-gui actually uses (SDL renderer backend, OpenGL backend,sdlkey, and the go-glyph SDL backend). It is published asmodule github.com/veandco/go-sdl2so consumers enable it with a singlereplace github.com/veandco/go-sdl2 => ../SDL/go-sdl2-sdl3.convertEventfolds SDL3's distinct window event types back into SDL2-styleWindowEventsubtypes; an//exportevent-watch is registered once and dispatched through a Go registry (watch.go).link_dynamic.go(-lSDL3fromzig-out) andlink_static.go(-tags sdl3static, fromzig-out-static) select linkage.2.
go-sdl2-sdl3/mix— SDL_mixer-compatible audio on SDL3A small SDL_mixer-API-compatible engine built directly on SDL3's audio API (per-channel auto-mixed
SDL_AudioStreams + a music stream), so go-gui'sgui/audiobuilds on SDL3 without SDL_mixer. WAV decodes natively; MP3/OGG via vendoreddr_mp3/stb_vorbis.3.
gosdl3— generated cgo SDL3 bindings (experimental)A Zig-comptime bindgen that emits full cgo SDL3 Go bindings (
gosdl3/sdl3/sdl3.go) from the SDL3 headers:zig build gentc→ translate-c, thenzig build gensdl3→ consts + type aliases + function wrappers. Separate from the hand-written shim in (1); useful as a complete generated surface.Plus supporting
build.zigsteps and.gitignoreentries.Build / usage
In the consumer (e.g. go-gui):
replace github.com/veandco/go-sdl2 => ../SDL/go-sdl2-sdl3.How to use it (with go-gui)
Consuming this is a single-line
go.modchange on the app side — no go-gui source changes are required. See the companion PR for the exact diff:→ go-gui/pull/1 changes: https://github.com/cataggar/go-gui/pull/1/changes
Steps:
go.mod, point the go-sdl2 dependency at the shim (this is the entire change in build: render and play audio on SDL3 via the go-sdl2-sdl3 shim go-gui#1):CC="zig cc". The SDL renderer backend, OpenGL backend,sdlkey, andgui/audiothen compile and run unchanged on SDL3.Notes
go-sdl2-sdl3/andgosdl3/.