Cross Platform Builds With Go And Fyne
I’ve been working on a GUI app that uses the Fyne1 framework and Go. An interesting thing I thought I’ll tackle was to have a keyboard shortcut registered system-wide that would pop the app whenever you pressed it. Furthermore, it should work on Linux, Windows and Mac.
The main options that I found for cross-compiling:
- use
go build
- if you don’t depend on external C libraries - use
fyne-cross
- use
zig
Note: When compiling for darwin, you will need the MacOS SDK on your VM.
You can get the MacOS SDK:
- from apple’s website
- programatically
From these options, the problem that I usually encountered after building the
binaries was related to the hotkeys. They were not registered correctly. In the
go files, I used the go:build
tag in order to target different systems. The
configuration was not properly taken into account when using fyne-cross
.
Therefore, I had to resort to another option.
Zig worked brilliantly2. You could
easily put a Zig application into a Dockerfile and directly use FROM scratch
.
Really portable that way. That’s because it provides a zero-dependency,
drop-in C/C++ compiler that supports cross-compilation out-of-the-box.
References: