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. There are different tools that can be used. The tool recommended by the Fyne developers is fyne-cross. It has been inspired by xgo and uses a docker image built on top of the golang-cross image, that includes the MinGW compiler for windows, and a macOS SDK, along with the Fyne requirements.
Supported targets are:
go get github.com/lucor/fyne-cross
fyne-cross --targets=linux/amd64,windows/amd64,darwin/amd64 package
fyne-cross helpfor more informations
The example below cross build the fyne examples application
git clone https://github.com/fyne-io/examples.git cd examples fyne-cross --targets=linux/amd64,windows/amd64,darwin/amd64 github.com/fyne-io/examples
Builds for the specified targets will be available under the
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.