fix: make X11/Wayland backends Linux-only so GOOS=windows builds clean - #5
Merged
Conversation
The internal/x11 and internal/wayland backend packages leaked unix-only
syscalls (syscall.UnixRights, unix.CmsgSpace, Mmap/Munmap, socket/memfd/shm
calls) into every build. With `go build ./...` compiling all packages,
GOOS=windows failed:
internal/wayland/transport.go:31: undefined: syscall.CmsgSpace
internal/wayland/seat.go:298: undefined: syscall.Mmap
internal/x11/conn.go:232: undefined: syscall.UnixRights
internal/x11/shmbuf.go:63: undefined: syscall.Mmap
... (cannot use fd int as syscall.Handle, etc.)
The top-level `window` package already stubbed non-Linux via
open_linux.go/open_other.go, but the internal backends were unguarded.
Fix: extract only the OS-specific primitives into build-tagged files,
keeping every protocol/codec type and all transport-agnostic logic
cross-platform (so their unit tests still build and run on every GOOS,
mirroring the design described in open_other.go):
- internal/x11: syscalls_{linux,other}.go (anon file, mmap/munmap/close),
conn_linux.go (unixRW SCM_RIGHTS fd passing)
- internal/wayland: syscalls_{linux,other}.go (anon file, mmap, keymap mmap),
transport_linux.go (unixTransport SCM_RIGHTS),
conn_linux.go (New over *net.UnixConn)
The shared-memory syscalls now sit behind package-var indirection (real on
Linux, ErrUnsupported stubs off Linux); no live Linux behavior changes.
Test harnesses that need a real socketpair/mmap are tagged //go:build linux
(wayland helpers split into helpers_test.go + helpers_linux_test.go); the
socket-free codec/protocol tests stay cross-platform.
CI: coverage gate is now Linux-only (backends are Linux-only); macOS lane
proves the codec + ErrUnsupported stub build/pass off Linux; new cross-build
matrix compiles windows/amd64, darwin/{arm64,amd64} and all six 64-bit Linux
arches so this can't regress.
Verified: `go build ./...` clean on windows/amd64, darwin/{arm64,amd64} and
linux/{amd64,arm64,riscv64,loong64,ppc64le,s390x}; `go test ./...` green on
linux with 100.0% coverage on internal/x11 and internal/wayland.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.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.
Problem
The module did not compile for
GOOS=windows(or any non-unix GOOS).internal/x11andinternal/waylandused unix-only syscalls that were not build-guarded, sogo build ./...compiled them everywhere and failed:The top-level
windowpackage already stubbed non-Linux (open_linux.go/open_other.go→ErrUnsupported), but the internal backends leaked unix syscalls into the windows build.Fix
Extract only the OS-specific primitives into build-tagged files, keeping every protocol/codec type and all transport-agnostic logic cross-platform (so their unit tests still build/run on every GOOS — the design already described in
open_other.go):syscalls_{linux,other}.go(anon file + mmap/munmap/close),conn_linux.go(unixRWSCM_RIGHTS fd passing)syscalls_{linux,other}.go(anon file + shm mmap + keymap mmap),transport_linux.go(unixTransportSCM_RIGHTS),conn_linux.go(Newover*net.UnixConn)Shared-memory syscalls now sit behind package-var indirection: real on Linux,
ErrUnsupportedstubs off Linux. No live Linux behavior changes. Test harnesses needing a real socketpair/mmap are tagged//go:build linux(wayland helpers split intohelpers_test.go+helpers_linux_test.go); socket-free codec/protocol tests stay cross-platform.CI
ErrUnsupportedstub build/vet/test off Linux.cross-buildmatrix compileswindows/amd64,darwin/{arm64,amd64}and all six 64-bit Linux arches — the regression guard.Verification (run, not asserted)
go build ./...clean: windows/amd64, darwin/{arm64,amd64}, linux/{amd64,arm64,riscv64,loong64,ppc64le,s390x}CGO_ENABLED=0 go test ./...green on real linux/arm64 (Debian VM)internal/x11andinternal/waylandgo vet ./...clean on windows, darwin and linux (incl.-tags=integration)🤖 Generated with Claude Code