Skip to content

Commit 25a95c8

Browse files
authored
all: add OpenBSD (X11) support (#36)
* all: add OpenBSD (X11) support OpenBSD ships the same X11/Xlib API as Linux, so the existing X11 backend works there with the right cgo include/lib paths (/usr/X11R6). Rename hotkey_linux.* to hotkey_x11.* because the _linux filename suffix carries an implicit linux-only build constraint that a //go:build line cannot widen, then extend the constraints to "linux || openbsd". Also widen mainthread/os.go so mainthread.Init/Call are available on OpenBSD. Adapted from #32 by Simon Dassow (@sdassow). * ci: add OpenBSD VM job exercising the X11 cgo build The CGO_ENABLED=0 cross-build only compiles the nocgo stub for openbsd. Add a vmactions OpenBSD VM that builds and vets with cgo enabled, validating the X11 backend's openbsd cgo flags (/usr/X11R6) and link against libX11.
1 parent 2d3b7a6 commit 25a95c8

6 files changed

Lines changed: 27 additions & 5 deletions

File tree

.github/workflows/hotkey.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,23 @@ jobs:
9999
export GOARCH=${TARGET#*/}
100100
echo "Building for $GOOS/$GOARCH"
101101
CGO_ENABLED=0 go build -v ./...
102+
103+
# Real OpenBSD run inside a VM. This exercises the X11 cgo build/link path
104+
# (libX11 lives under /usr/X11R6 in the OpenBSD base system) that the
105+
# CGO_ENABLED=0 cross-build job cannot validate. The hotkey runtime tests
106+
# need an X server, so here we compile- and vet-check with cgo enabled.
107+
openbsd:
108+
name: openbsd (X11, cgo)
109+
runs-on: ubuntu-latest
110+
steps:
111+
- uses: actions/checkout@v4
112+
- name: Build and vet on OpenBSD
113+
uses: vmactions/openbsd-vm@v1
114+
with:
115+
usesh: true
116+
prepare: |
117+
pkg_add -I go
118+
run: |
119+
go version
120+
CGO_ENABLED=1 go build -v ./...
121+
CGO_ENABLED=1 go vet ./...

hotkey_linux.c renamed to hotkey_x11.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Written by Changkun Ou <changkun.de>
66

7-
//go:build linux
7+
//go:build linux || openbsd
88

99
#include <X11/Xlib.h>
1010
#include <X11/Xutil.h>

hotkey_linux.go renamed to hotkey_x11.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
//
55
// Written by Changkun Ou <changkun.de>
66

7-
//go:build linux
7+
//go:build linux || openbsd
88

99
package hotkey
1010

1111
/*
1212
#cgo LDFLAGS: -lX11
13+
#cgo openbsd CFLAGS: -I/usr/X11R6/include
14+
#cgo openbsd LDFLAGS: -L/usr/X11R6/lib -lX11
1315
1416
#include <stdint.h>
1517
#include <X11/Xlib.h>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Written by Changkun Ou <changkun.de>
66

7-
//go:build linux && cgo
7+
//go:build (linux || openbsd) && cgo
88

99
package hotkey
1010

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Written by Changkun Ou <changkun.de>
66

7-
//go:build linux && cgo
7+
//go:build (linux || openbsd) && cgo
88

99
package hotkey_test
1010

mainthread/os.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55
// Written by Changkun Ou <changkun.de>
66

7-
//go:build windows || linux || (darwin && !cgo)
7+
//go:build windows || linux || openbsd || (darwin && !cgo)
88

99
package mainthread
1010

0 commit comments

Comments
 (0)