Build from source
This page details how to build TinyGo from source. If you would like to install a pre-built binary release, please see our quick install guide.
Start with getting the source code. On Windows, you might want to install the build dependencies first.
git clone --recursive https://github.com/tinygo-org/tinygo.git cd tinygo
If you want to use the latest version of LLVM instead of the latest release, please switch over to the dev branch:
git checkout dev git submodule update --init
A major dependency of TinyGo is LLVM. You can either use a version of LLVM already on your system or build LLVM manually. Building manually takes a long time (around an hour depending on how fast your system is) so it is recommended to use a version of LLVM already on your system if that’s possible.
You need to build LLVM manually in the following cases:
- You would like to use it for the ESP8266 or ESP32 chips.
- You are using Windows.
- Your Linux distribution (if you use Linux) does not ship the right LLVM version.
With system-installed LLVM
Using a system-installed version of LLVM depends on your system, of course.
For Debian or Ubuntu you can install LLVM by adding a new apt repository. For more information about this method, see apt.llvm.org. Before copying the command below, please replace
xxxxx with your distribution’s codename.
echo 'deb http://apt.llvm.org/xxxxx/ llvm-toolchain-xxxxx-11 main' | sudo tee /etc/apt/sources.list.d/llvm.list
After adding the apt repository for your distribution you may install the LLVM toolchain packages:
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add - sudo apt-get update sudo apt-get install clang-11 llvm-11-dev lld-11 libclang-11-dev
For MacOS, you can install LLVM through Homebrew. The Clang/LLVM version from Apple is not supported by TinyGo.
brew install llvm@11
After LLVM has been installed, installing TinyGo should be as easy as running the following command (cgo must be enabled so that the compile does not fail):
CGO_ENABLED=1 go install
Note that you should not use
make when you want to build using a system-installed LLVM, just use the Go toolchain.
make is used when you want to use a self-built LLVM, as in the next section.
If you have gotten this far, please skip over to Additional requirements below to further set up TinyGo.
With a self-built LLVM
You can also manually build LLVM. This is a long process which takes at least one hour on most machines. In many cases you can build TinyGo using a system-installed LLVM, see above.
You will need a few extra tools that are required during the build of LLVM, depending on your OS.
Debian and Ubuntu users can install all required tools this way:
sudo apt-get install build-essential git cmake ninja-build
On MacOS you can install these tools using Homebrew:
brew install cmake ninja
On Windows you can install them using Chocolatey. Install Chocolatey first, then run the following in a command prompt or PowerShell with administrative privileges:
choco install --confirm git golang mingw make cmake ninja python
The following command takes care of downloading and building LLVM. It places the source code in
llvm-project/ and the build output in
llvm-build/. It only needs to be done once until the next LLVM release (every half year).
Once this is finished, you can build TinyGo against this manually built LLVM:
This results in a
tinygo binary in the
$ ./build/tinygo version tinygo version 0.22.0 linux/amd64 (using go version go1.17 and LLVM version 13.0.0)
You have successfully built TinyGo from source. Congratulations!
We’re not done yet. Some extra things need to be built before you can start using TinyGo.
To be able to use TinyGo on a bare-metal target, you need to generate some files first:
To be able to use TinyGo to build WebAssembly binaries, you will need to compile wasi-libc:
These command may need to be re-run after some updates in TinyGo.
There are also some extra tools you will need to install, depending on your operating system. These tools are gcc-avr, avr-libc, avrdude, and openocd. Check the additional requirements for your operating system: