Book Image

Hands-On GUI Application Development in Go

By : Andrew Williams
Book Image

Hands-On GUI Application Development in Go

By: Andrew Williams

Overview of this book

Go is often compared to C++ when it comes to low-level programming and implementations that require faster processing, such as Graphical User Interfaces (GUIs). In fact, many claim that Go is superior to C++ in terms of its concurrency and ease of use. Most graphical application toolkits, though, are still written using C or C++, and so they don't enjoy the benefits of using a modern programming language such as Go. This guide to programming GUIs with Go 1.11 explores the various toolkits available, including UI, Walk, Shiny, and Fyne. The book compares the vision behind each project to help you pick the right approach for your project. Each framework is described in detail, outlining how you can build performant applications that users will love. To aid you further in creating applications using these emerging technologies, you'll be able to easily refer to code samples and screenshots featured in the book. In addition to toolkit-specific discussions, you'll cover more complex topics, such as how to structure growing graphical applications, and how cross-platform applications can integrate with each desktop operating system to create a seamless user experience. By delving into techniques and best practices for organizing and scaling Go-based graphical applications, you'll also glimpse Go's impressive concurrency system. In the concluding chapters, you'll discover how to distribute to the main desktop marketplaces and distribution channels. By the end of this book, you'll be a confident GUI developer who can use the Go language to boost the performance of your applications.
Table of Contents (25 chapters)
Title Page
Copyright and Credits
About Packt
Contributors
Preface
Comparison of GUI Toolkits
Index

Cross compiling for macOS with CGo


When cross compiling for macOS, it's necessary to install the SDK (Software Development Kit) from Apple as well as a suitable compiler. The instructions for Windows (using MSYS2—described in the previous AppendixInstallation Details) and Linux are almost identical; the main work is to install the macOS SDK.

To macOS from Linux or Windows

To prepare for cross compilation to Darwin, we must install the macOS SDK and a build toolchain that can use it. The easiest way to do this is with the osxcross project. This example shows how to download and install the SDK and tools to build for macOS without using a Macintosh computer. This illustration uses Linux but the process is the same for Windows developers using MSYS2 or Cygwin Command Prompts.

 

We'll be using clang rather than gcc as it's more portable by design. For this process to work, you'll need to have clangcmake, and libxml2-dev installed using your package manager:

  • On Linux use: pacman -S clang cmake libxml2-dev (or apt-get or yum, depending on your distribution)
  • On Windows use: pacman -S mingw-w64-x86_64-clang mingw-w64-x86_64-cmake mingw-w64-x86_64-libxml2

Next, we need to download the macOS SDK, which is bundled with Xcode. If you don't already have an Apple developer account, you'll need to sign up and agree to their terms and conditions. Using this account, log in to the download site at https://developer.apple.com/download/more/?name=Xcode%207.3 and download XCode.dmg (7.3.1 is recommended for osxcross).

Then, we can install the osxcross tool—start by downloading it with git clone https://github.com/tpoechtrager/osxcross.git and then change into the downloaded directory. Using these tools, we extract the macOS SDK from the downloaded Xcode.dmg file using the package tool provided, ./tools/gen_sdk_package_darling_dmg.sh <path to Xcode.dmg>. The resulting MacOSX10.11.sdk.tar.xz file should be copied into the tarballs/ directory.

Lastly, we build the osxcross compiler extension by executing ./build.sh. Following this, there should be a new directory named target/bin/, which you should add to your PATH environment variable. The compiler can now be used in CGo builds by setting the environment variable, CC=o32-clang. More details about this process and how to adapt it for other platforms are available on the osxcross project website at https://github.com/tpoechtrager/osxcross.