Skip to content

Commit 78ce109

Browse files
biohazduckdeadprogram
authored andcommitted
separate build methods so they are more followable
1 parent 9f7c4f7 commit 78ce109

File tree

5 files changed

+217
-200
lines changed

5 files changed

+217
-200
lines changed

content/docs/guides/build.md

Lines changed: 0 additions & 200 deletions
This file was deleted.
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: "Build from source"
3+
weight: 2
4+
description: >
5+
Build a development version of TinyGo from source if you want to help improve TinyGo or want to try the latest features.
6+
---
7+
8+
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](../../../getting-started/install).
9+
10+
A major dependency of TinyGo is [LLVM](https://llvm.org/). 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. The links provided above show how to install LLVM one way or the other.
11+
12+
### Repository cloning (before build)
13+
Start with getting the source code. On Windows, you might want to install the [build dependencies](#build-dependencies) first.
14+
15+
```shell
16+
git clone https://github.com/tinygo-org/tinygo.git
17+
cd tinygo
18+
```
19+
20+
Once cloned, you can can choose which branch to build. The default branch is the latest release, but you can also build the latest development version:
21+
22+
```shell
23+
# If building released version this command is not necessary.
24+
git checkout dev
25+
```
26+
Once the branch is selected, pull submodules:
27+
28+
```shell
29+
git submodule update --init
30+
```
31+
32+
Now you are ready to build TinyGo- but you must choose whether to build with a [manual LLVM install](./manual-llvm.md) or with a [system installed LLVM](./byollvm.md). See the links above.

content/docs/guides/selfbuild/additional-requirements.md

Whitespace-only changes.
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
title: "Build with system-installed LLVM"
3+
weight: 4
4+
description: >
5+
How to build TinyGo with a system-installed version of LLVM.
6+
---
7+
8+
⚠️ Halt! This is the system installed LLVM guide! Please check the following table and make sure you don't need the [manual LLVM install guide](./manual-llvm.md) instead!
9+
10+
11+
| You need to build LLVM manually in the following cases |
12+
|---|
13+
| You would like to use it for the ESP8266 or ESP32 chips |
14+
| You are using Windows. |
15+
| Your Linux distribution (if you use Linux) does not ship the right LLVM version. |
16+
17+
18+
Using a system-installed version of LLVM depends on your system, of course.
19+
20+
For **Debian** or **Ubuntu** you can install LLVM by adding a new apt repository. For more information about this method, see [apt.llvm.org](https://apt.llvm.org/). *Before copying the command below, please replace `xxxxx` with your distribution's codename*.
21+
22+
| Distro | Version | Codename |
23+
|--------|------- |-----------|
24+
| Ubuntu | 18.04 | `bionic` |
25+
| Ubuntu | 20.04 | `focal` |
26+
| Ubuntu | 20.10 | `groovy` |
27+
| Ubuntu | 21.04 | `hirsute` |
28+
| Ubuntu | 22.04 | `jammy` |
29+
| Debian | 10 | `buster` |
30+
| Debian | 11 | `bullseye`|
31+
| Debian | sid | `unstable`|
32+
33+
```shell
34+
echo 'deb http://apt.llvm.org/xxxxx/ llvm-toolchain-xxxxx-16 main' | sudo tee /etc/apt/sources.list.d/llvm.list
35+
```
36+
37+
After adding the apt repository for your distribution you may install the LLVM toolchain packages:
38+
39+
```shell
40+
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
41+
sudo apt-get update
42+
sudo apt-get install clang-16 llvm-16-dev lld-16 libclang-16-dev
43+
```
44+
45+
For **MacOS**, you can install LLVM through [Homebrew](https://formulae.brew.sh/formula/llvm). The Clang/LLVM version from Apple is not supported by TinyGo.
46+
47+
```shell
48+
brew install llvm
49+
```
50+
51+
For **Fedora** users you can install LLVM from the repository. Note that the version of LLVM [varies by Fedora version](https://packages.fedoraproject.org/pkgs/llvm/llvm-libs/), for example Fedora 37 has LLVM 15.
52+
53+
```shell
54+
sudo dnf install llvm-devel lld-libs lld
55+
```
56+
57+
After LLVM has been installed, installing TinyGo should be as easy as running the following command:
58+
59+
```shell
60+
go install
61+
```
62+
63+
You should now have a working TinyGo installation!
64+
65+
If you have gotten this far, please refer to [Additional requirements](./additional-requirements) to further set up TinyGo.
66+
67+
## Final notes
68+
69+
### `go install` command inner workings
70+
The `go install` command will build the `tinygo` executable and store it to your currently set `$GOBIN` directory. A couple environment variables must be set for TinyGo to work after running this:
71+
72+
* Your `GOBIN` should be set to where you want go binaries to be stored to. Below is an example (for linux systems)
73+
```shell
74+
go env -w GOBIN=$HOME/local/bin
75+
```
76+
* The directory should exist! Below is a way to create the directory on linux.
77+
```shell
78+
mkdir -p $HOME/local/bin
79+
```
80+
* Your $PATH environment variable should contain the directory so that you can run `tinygo` from the command line! A reliable way to achieve this can be found at the [Go install page](https://go.dev/doc/install#). For linux it consists of adding the line below to the bottom of your `/etc/profile` file (before the `exit 0`):
81+
```
82+
export PATH=$PATH:$HOME/local/bin
83+
```
84+
85+
86+
### GCC errors
87+
If you are getting an `gcc` or `g++ not found` error you most likely do not have a working C++ build environment. You'll need the `build-essential` package on Debian or `sudo dnf install make automake gcc gcc-c++` for Fedora based systems.
88+
89+
If you are getting a build error like this, LLVM is not installed as expected:
90+
91+
```
92+
# tinygo.org/x/go-llvm
93+
../../../go/pkg/mod/tinygo.org/x/go-llvm@v0.0.0-20221028183034-8341240c0b32/analysis.go:16:10: fatal error: 'llvm-c/Analysis.h' file not found
94+
#include "llvm-c/Analysis.h" // If you are getting an error here you need to build or install LLVM, see https://tinygo.org/docs/guides/build/
95+
^~~~~~~~~~~~~~~~~~~
96+
1 error generated.
97+
```
98+
99+
This can often be fixed by specifying the LLVM version as a build tag, for example `-tags=llvm14` if you have LLVM 14 instead of LLVM 16.
100+
101+
### Additional notes
102+
Note that you should not use `make` when you want to build using a system-installed LLVM, just use the Go toolchain.

0 commit comments

Comments
 (0)