macOS

This page has information on how to install and use TinyGo on macOS.

If you want to use TinyGo to compile your own or sample code, you can install the release version directly on your machine by following the “Quick Install” instructions below.

You can also install the full source code to the TinyGo compiler itself, generally for people who wish to contribute to the project or want to build the compiler from sources directly.

The third option is to use the Docker image. This has the benefit of making no changes to your system but has a large download and installation size. For instructions on using the Docker image, please see the page here.

Quick Install

You must have Go v1.12+ already installed on your machine in order to install TinyGo.

You can use Homebrew to install TinyGo using the following commands:

  1. brew tap tinygo-org/tools
  2. brew install tinygo

You can test that the installation is working properly by running this code which should display the version number:

  1. $ tinygo version
  2. tinygo version 0.12.0 darwin/amd64

If you are only interested in compiling TinyGo code for WebAssembly then you are done with the installation.

Otherwise, please continue with the installation of the additional requirements for your desired microcontroller.

Additional Requirements for Microcontrollers

Some boards require a special flashing tool for that particular chip, like openocd or nrfjprog. See the documentation page for your board as listed here to see which flashing tool is required for your target board.

If you are only interested in compiling TinyGo code for ARM microcontrollers then you are now done with the installation.

AVR (e.g. Arduino Uno)

To compile and flash TinyGo programs for AVR based processors such as the original Arduino Uno you must install some extra tools:

  1. brew tap osx-cross/avr
  2. brew install avr-gcc
  3. brew install avrdude

You are now done with the TinyGo “Quick Install” for macOS

Source Install

If you have already followed the “Quick Install” instructions above, you do not need to perform a source install. You are now done with the needed installation. The “Source Install” is for when you want to contribute to TinyGo.

Make sure that you first turn on Go modules support, like this:

  1. export GO111MODULE=on

Now, obtain the TinyGo source code, which should also obtain the various needed dependencies:

  1. go get -d -u github.com/tinygo-org/tinygo
  2. cd $GOPATH/src/github.com/tinygo-org/tinygo

You now have two options: build LLVM manually or use LLVM from Homebrew. Theadvantage of a manual build is that it includes all supported targets (includingAVR) while Homebrew includes only stable targets. Unless you want to compile forAVR-based boards, you can use Homebrew.

With LLVM from Homebrew

The easiest way to install LLVM on macOS is throughHomebrew. Make sure you install LLVM 8:

  1. brew install llvm

Installing TinyGo should now be as easy as:

  1. go install

Note that you should not use make when you want to build using asystem-installed LLVM, just use the Go toolchain. make is used when you wantto use a self-built LLVM.

With a self-built LLVM

You can also manually build LLVM. This is a long process which takes at leastone hour on most machines. In most cases you can build TinyGo using LLVM fromHomebrew. However, the Homebrew build does not support the experimental AVRtarget so you’ll have to build from source if you want to use TinyGo for theArduino Uno.

You will need a few extra tools that are required during the build of LLVM:

  1. brew install cmake ninja

The following command takes care of downloading and building LLVM. It places thesource code in llvm-build/ and the build output in llvm/. It only needs tobe done once until the next LLVM release.

  1. make llvm-build

Once this is finished, you can build TinyGo against this manually built LLVM:

  1. make

This results in a tinygo binary in the build directory:

  1. $ ./build/tinygo version
  2. tinygo version 0.12.0 darwin/amd64

Additional Requirements for Microcontrollers

Before anything can be built for a bare-metal target, you need to generate somefiles first:

  1. make gen-device

This will generate register descriptions, interrupt vectors, and linker scriptsfor various devices. Also, you may need to re-run this command after updates,as some updates cause changes to the generated files.

The same additional requirements to compile TinyGo programs that can run on microcontrollers must be fulfilled when installing TinyGo from source. Please follow these instructions above.

Docker Install

For instructions on using the Docker image, please see the page here.