Robotgo provides experimental pure-Go (Cgo-free) backends. These allow you to build without GCC, MinGW, Xcode, or X11 headers by setting CGO_ENABLED=0 and using specific build tags. This is useful for cross-compilation.
Available Backends and Tags
| Backend | Build tag | Go package |
|---|
| Windows (Cgo-free) | win | github.com/go-vgo/robotgo/win |
| macOS (Quartz via purego) | mac | github.com/go-vgo/robotgo/darwin |
| X11 (Linux, pure-Go X protocol) | x11 | github.com/go-vgo/robotgo/x11 |
| Wayland (Linux, wlroots) | wayland | github.com/go-vgo/robotgo/wayland |
| libei (Linux, GNOME/KDE portal) | libei | github.com/go-vgo/robotgo/libei |
| Pure-Go default (all platforms) | purego | (selects mac/win/wayland above) |
Build Examples
Cross-compile for Linux (X11) without Cgo:
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags "purego,x11" .
Build for Windows without Cgo/MinGW:
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags win .
Build for macOS (Quartz via purego) without Xcode:
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -tags mac .
Build for Wayland (wlroots-based compositor):
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags wayland .
Build for GNOME/KDE (via libei):
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags libei .
The purego shortcut:
Using -tags purego automatically selects the best pure-Go backend for the target OS: mac on macOS, win on Windows, and wayland on Linux.
go build -tags purego .
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags "purego,x11" .
CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags win .
CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -tags mac .
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags wayland .
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags libei .