Cross-compiling

As a project that aims to be written purely in Go, one of its goals is to be just as easy to cross-compile for different platforms as it is to build for the current operating system. In cases where the Shiny driver for the operating system is pure Go (as is currently the case for windows and x11, used by Linux and BSD), compiling for a specific operating system is as simple as using the GOOS parameter, as described in Chapter 3, Go to the Rescue!:

Compiling Linux and Windows binaries from a Linux Command Prompt

The gl driver that provides hardware-accelerated rendering (used by macOS and Linux) depends on a system API that is not currently available without CGO and so is more challenging to cross-compile. Through the toolkit design, it's possible to use the x11 driver for a Unix target platform if CGO is not available—so Linux or BSD can still be cross compiled.

Note that cross-compiling a Shiny application for Linux will result in an application that does not have graphical acceleration enabled. This can be overcome by using CGO_ENABLED=1 and installing various libraries but it is easily forgotten, so it's advisable to set up a dedicated Linux build environment.

This means that, from macOS, we can cross-compile both Linux and Windows executables by simply setting the appropriate GOOS variable as would be expected:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.37.154