11# Building TinyGo
22
3- TinyGo depends on LLVM and libclang, which are both big C++ libraries. There are
4- two ways these can be linked: dynamically and statically. The default is dynamic
5- linking because it is fast and works almost out of the box on Debian-based
6- systems with the right libraries installed.
3+ TinyGo depends on LLVM and libclang, which are both big C++ libraries. It can
4+ also optionally use a built-in lld to ease cross compiling. There are two ways
5+ these can be linked: dynamically and statically. The default is dynamic linking
6+ because it is fast and works almost out of the box on Debian-based systems with
7+ the right libraries installed.
78
8- This guide describes how to statically link TinyGo against LLVM and libclang so
9- that the binary can be easily moved between systems.
9+ This guide describes how to statically link TinyGo against LLVM, libclang and
10+ lld so that the binary can be easily moved between systems.
1011
1112## Dependencies
1213
13- LLVM and Clang are both quite light on dependencies, requiring only standard
14+ LLVM, Clang and LLD are quite light on dependencies, requiring only standard
1415build tools to be built. Go is of course necessary to build TinyGo itself.
1516
1617 * Go (1.11+)
@@ -30,14 +31,15 @@ The first step is to get the source code. Place it in some directory, assuming
3031
3132 git clone -b release_70 https://github.com/llvm-mirror/llvm.git $HOME/src/llvm
3233 git clone -b release_70 https://github.com/llvm-mirror/clang.git $HOME/src/llvm/tools/clang
34+ git clone -b release_70 https://github.com/llvm-mirror/lld.git $HOME/src/llvm/tools/lld
3335 go get -d github.com/tinygo-org/tinygo
3436 cd $HOME/go/src/github.com/tinygo-org/tinygo
3537 dep ensure -vendor-only # download dependencies
3638
37- Note that Clang must be placed inside the tools subdirectory of LLVM to be
38- automatically built with the rest of the system.
39+ Note that Clang and LLD must be placed inside the tools subdirectory of LLVM to
40+ be automatically built with the rest of the system.
3941
40- ## Build LLVM and Clang
42+ ## Build LLVM, Clang, LLD
4143
4244Building LLVM is quite easy compared to some other software packages. However,
4345the default configuration is _ not_ optimized for distribution. It is optimized
@@ -86,10 +88,10 @@ This can take over an hour depending on the speed of your system.
8688## Build TinyGo
8789
8890Now that you have a working version of LLVM, build TinyGo using it. You need to
89- specify the directories to the LLVM build directory and to the Clang source.
91+ specify the directories to the LLVM build directory and to the Clang and LLD source.
9092
9193 cd $HOME/go/src/github.com/tinygo-org/tinygo
92- make static LLVM_BUILDDIR=$HOME/src/llvm-build CLANG_SRC=$HOME/src/llvm/tools/clang
94+ make static LLVM_BUILDDIR=$HOME/src/llvm-build CLANG_SRC=$HOME/src/llvm/tools/clang LLD_SRC=$HOME/src/llvm/tools/lld
9395
9496## Verify TinyGo
9597
@@ -98,7 +100,7 @@ Try running TinyGo:
98100 ./build/tinygo help
99101
100102Also, make sure the ` tinygo ` binary really is statically linked. Check this
101- using ` ldd ` :
103+ using ` ldd ` (not to be confused with ` lld ` ) :
102104
103105 ldd ./build/tinygo
104106
0 commit comments