Cross compiling with Go is designed to be simple - we just set the environment variable
GOOS for the target Operating System (and
GOARCH if targetting a different architecture). Unfortunately when using native graphics calls the use of CGo in Fyne makes this a little harder.
To cross-compile a Fyne application you will also have to set
CGO_ENABLED=1 which tells go to enable the C compiler (this is normally turned off when the target platform is different to the current system). Doing so unfortunately means that you must have a C compiler for the target platform that you are going to compile for.
After installing the appropriate compilers you will also need to set the
CC environment variable to tell Go which compiler to use.
There are many ways to install the required tools - and different tools that can be used. The configuration recommended by the Fyne developers is:
||osxcross||from github.com||You will also need to install the macOS SDK (instructions at the download link)|
||mingw64||package manager||For macOS use homebrew|
||gcc or musl-cross||cygwin or package manager||musl-cross is available from homebrew to provide the linux gcc. You will also need to install X11 and mesa headers for compilation.|
With the environment variables above set you should be able to compile in the usual manner. If further errors occur it is likely to be due to missing packages. Some target platforms require additional libraries or headers to be installed for the compilation to succeed.
As a Linux system is able to cross compile to macOS and Windows easily it can be simpler to use a virtualised environment when you are not developing from Linux. Docker images are a useful tool for a complex build configuration and this works for Fyne as well. Documentation for this process will follow…
We're excited to hear from anyone interested in the project. Whether it's to find out more, provide suggestions or to get involved - drop us a line!
If you would like to join us on slack but are not yet signed up to the golang slack server you can request an invite.