Objective
Set up bootstrapping. Build the latest version of the Go compiler with C bridge mode support from it's sources.
Motivation
By coincidence, I stumbled over this interesting tutorial about the programming language Go.
Since i was always interested to play around with that language, I took the opportunity, to try it out. As I usually want to use the latest compiler-version, I thought, it would be a good idea, that I do not use the Go-Installer, but compile the sources by myself from scratch. Unfortunately, the latest Go compiler, cannot be compiled with C support, when there is not already a Go compiler installed in the system. Therefore I also had to install an older Go compiler for booststrapping first.
Prerequisites
- Linux Mint 18.3 Sylvia - Cinnamon (64 Bit)
- GCC 7.3.0 (build essential or update-alternatives)
Solution
I decided to do the whole build and temporary stuff within the
"Downloads"
folder in my home account.The boostrap toolchain will reside in the sub-directory
"gobootstrap"
within the "Downloads"
folder.Setup the bootstrap toolchain
Open a terminal. Download and install the latest Go bootstrap toolchain.
$> mkdir -p Downloads/goboostrap
$> cd Downloads/gobootstrap
$> wget https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz
$> cd Downloads/gobootstrap
$> wget https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz
you'll see some output similar to this:
--2018-06-23 17:58:49-- https://dl.google.com/go/go1.4-bootstrap-20171003.tar.gz
Resolving dl.google.com (dl.google.com)... 216.58.207.46, 2a00:1450:4001:824::200e
Connecting to dl.google.com (dl.google.com)|216.58.207.46|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11009739 (10M) [application/octet-stream]
Saving to: ‘go1.4-bootstrap-20171003.tar.gz.1’
go1.4-bootstrap-20171003.tar.gz.1 100%[==========================================================================>] 10,50M 5,23MB/s in 2,0s
2018-06-23 17:58:51 (5,23 MB/s) - ‘go1.4-bootstrap-20171003.tar.gz.1’ saved [11009739/11009739]
Resolving dl.google.com (dl.google.com)... 216.58.207.46, 2a00:1450:4001:824::200e
Connecting to dl.google.com (dl.google.com)|216.58.207.46|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 11009739 (10M) [application/octet-stream]
Saving to: ‘go1.4-bootstrap-20171003.tar.gz.1’
go1.4-bootstrap-20171003.tar.gz.1 100%[==========================================================================>] 10,50M 5,23MB/s in 2,0s
2018-06-23 17:58:51 (5,23 MB/s) - ‘go1.4-bootstrap-20171003.tar.gz.1’ saved [11009739/11009739]
Now you have to unpack the downloaded toolchain package:
$> tar -xvzf go1.4-bootstrap-20171003.tar.gz
The whole stuff is unpacked into a new sub-directory
"go"
go/.gitattributes
go/.gitignore
[...]
go/src/cmd/5g/gg.h
go/src/cmd/5g/ggen.c
go/src/cmd/5g/gobj.c
go/src/cmd/5g/gsubr.c
[...]
go/test/varerr.go
go/test/varinit.go
go/test/zerodivide.go
go/.gitignore
[...]
go/src/cmd/5g/gg.h
go/src/cmd/5g/ggen.c
go/src/cmd/5g/gobj.c
go/src/cmd/5g/gsubr.c
[...]
go/test/varerr.go
go/test/varinit.go
go/test/zerodivide.go
Change directory into the
"./go/src"
and build the bootstrap toolchain.Observe: This step requires you to have already a functional GCC compiler present on your system.
If not already done: To set-up the GCC 7.3.0 on your system see Install multiple versions of GCC on your system
$> CGO_ENABLED=0 ./make.bash
# Building C bootstrap tool.
cmd/dist
# Building compilers and Go bootstrap tool for host, linux/amd64.
lib9
[...]
# Building packages and commands for linux/amd64.
runtime
errors
sync/atomic
[...]
cmd/pprof
net/rpc
net/http/fcgi
net/rpc/jsonrpc
cmd/dist
# Building compilers and Go bootstrap tool for host, linux/amd64.
lib9
[...]
# Building packages and commands for linux/amd64.
runtime
errors
sync/atomic
[...]
cmd/pprof
net/rpc
net/http/fcgi
net/rpc/jsonrpc
Finally, the toolchain build is finished.
Compile the Go compiler
Before you compile the compiler, step back to the
"Downloads"
folder and download the latest source of the go compiler.$> cd ~/Downloads
$> wget https://dl.google.com/go/go1.10.3.src.tar.gz
$> wget https://dl.google.com/go/go1.10.3.src.tar.gz
--2018-06-23 18:29:13-- https://dl.google.com/go/go1.10.3.src.tar.gz
Resolving dl.google.com (dl.google.com)... 216.58.207.78, 2a00:1450:4001:825::200e
Connecting to dl.google.com (dl.google.com)|216.58.207.78|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18323736 (17M) [application/octet-stream]
Saving to: ‘go1.10.3.src.tar.gz’
go1.10.3.src.tar.gz 100%[==========================================================================>] 17,47M 5,94MB/s in 2,9s
2018-06-23 18:29:16 (5,94 MB/s) - ‘go1.10.3.src.tar.gz’ saved [18323736/18323736]
Resolving dl.google.com (dl.google.com)... 216.58.207.78, 2a00:1450:4001:825::200e
Connecting to dl.google.com (dl.google.com)|216.58.207.78|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 18323736 (17M) [application/octet-stream]
Saving to: ‘go1.10.3.src.tar.gz’
go1.10.3.src.tar.gz 100%[==========================================================================>] 17,47M 5,94MB/s in 2,9s
2018-06-23 18:29:16 (5,94 MB/s) - ‘go1.10.3.src.tar.gz’ saved [18323736/18323736]
Now, unpack the sources, like it was already done, with the toolchain package.
$> tar -xvzf go1.10.3.src.tar.gz
go/
go/AUTHORS
go/CONTRIBUTING.md
[...]
go/src/runtime/closure_test.go
go/src/runtime/compiler.go
go/src/runtime/complex.go
[...]
go/test/varinit.go
go/test/writebarrier.go
go/test/zerodivide.go
go/AUTHORS
go/CONTRIBUTING.md
[...]
go/src/runtime/closure_test.go
go/src/runtime/compiler.go
go/src/runtime/complex.go
[...]
go/test/varinit.go
go/test/writebarrier.go
go/test/zerodivide.go
Again, step into the
"src"
directory and build the compiler, using the bootstrap toolchain.This step may take a while, depending on the performance of your computer.
$> cd go/src
$> GOROOT_BOOTSTRAP=~/Downloads/gobootstrap/go ./all.bash
$> GOROOT_BOOTSTRAP=~/Downloads/gobootstrap/go ./all.bash
Building Go cmd/dist using /home/cschmidt/Downloads/gobootstrap/go.
Building Go toolchain1 using /home/cschmidt/Downloads/gobootstrap/go.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for linux/amd64.
##### Testing packages.
ok archive/tar 0.051s
ok archive/zip 1.164s
ok bufio 0.186s
ok bytes 0.686s
ok compress/bzip2 0.132s
[...]
ok cmd/vendor/golang.org/x/arch/x86/x86asm 0.213s
ok cmd/vet 3.946s
ok cmd/vet/internal/cfg 0.033s
##### GOMAXPROCS=2 runtime -cpu=1,2,4 -quick
ok runtime 14.067s
##### cmd/go terminal test
PASS
ok _/home/cschmidt/Downloads/go/src/cmd/go/testdata/testterminal18153 0.001s
##### Testing without libgcc.
ok crypto/x509 1.016s
ok net 0.031s
ok os/user 0.038s
[...]
##### API check
Go version is "go1.10.3", ignoring -next /home/cschmidt/Downloads/go/api/next.txt
ALL TESTS PASSED
---
Installed Go for linux/amd64 in /home/cschmidt/Downloads/go
Installed commands in /home/cschmidt/Downloads/go/bin
*** You need to add /home/cschmidt/Downloads/go/bin to your PATH.
Building Go toolchain1 using /home/cschmidt/Downloads/gobootstrap/go.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for linux/amd64.
##### Testing packages.
ok archive/tar 0.051s
ok archive/zip 1.164s
ok bufio 0.186s
ok bytes 0.686s
ok compress/bzip2 0.132s
[...]
ok cmd/vendor/golang.org/x/arch/x86/x86asm 0.213s
ok cmd/vet 3.946s
ok cmd/vet/internal/cfg 0.033s
##### GOMAXPROCS=2 runtime -cpu=1,2,4 -quick
ok runtime 14.067s
##### cmd/go terminal test
PASS
ok _/home/cschmidt/Downloads/go/src/cmd/go/testdata/testterminal18153 0.001s
##### Testing without libgcc.
ok crypto/x509 1.016s
ok net 0.031s
ok os/user 0.038s
[...]
##### API check
Go version is "go1.10.3", ignoring -next /home/cschmidt/Downloads/go/api/next.txt
ALL TESTS PASSED
---
Installed Go for linux/amd64 in /home/cschmidt/Downloads/go
Installed commands in /home/cschmidt/Downloads/go/bin
*** You need to add /home/cschmidt/Downloads/go/bin to your PATH.
As I didn't want to have the Go compiler installed in my
"Downloads"
folder I simply move it directly into my home-account.$> cd ~/Downloads
$> mv go ~/
$> mv go ~/
Let's try to call the Go compiler
$> go
The program 'go' is currently not installed. You can install it by typing:
sudo apt install golang-go
sudo apt install golang-go
Ouwww! What went wrong? -- Nothing!
I forgot to extend the
PATH
variable of my environment as mentioned by the hint, given after compilation.To do so, I add the following line to my "~/.bashrc".
$> echo 'PATH=$PATH:$HOME/go/bin # Add go compiler' >> ~/.bashrc
Observe: Double-check, you use single quotes instead of double quotes here, otherwise, the
bash
will already expand the "$PATH"
variable here and append it's content to your "~/.bashrc"
. Once, again:
$> go
Go is a tool for managing Go source code.
Usage:
go command [arguments]
[...]
Usage:
go command [arguments]
[...]
Yeah, finally done.
Just to clean up the mess within the
"Downloads"
directory by just deleting everything, I do not need anymore.