Compile and Install Go 1.8 in ppc64 Ubuntu Linux Xenial

I started this topic thinking about how to install go in ppc64 arch, at this moment only ppc64 is supported by golang. Im not an expert about cross compiling and go development so I did it only with the unique reason to have go compiled and ready to work to continue working in my new ppc64 g5 computer. All of those steps are part of other link so I did the same steps.

Step 1:
I use my virtual machine with centos7 in order to create the bootstrap package for ppc64 because I had several error in compiling steps in osX so this was my decision to move ahead with a virtual machine as I said before no time to debug why is not working. I tried also with 1.9 and 1.10 but I have some error, with 1.8 works fine.
We need to build first go1.4 in the virtual machine.

[vagrant@localhost ~]$ git clone https://go.googlesource.com/go $HOME/go1.4
[vagrant@localhost ~]$ cd $HOME/go1.4/src
[vagrant@localhost go1.4]$ git checkout release-branch.go1.4
[vagrant@localhost go1.4]$ ./make.bash

Step 2:
Then we need to build go1.8 as a bootstrap package.

[vagrant@localhost ~]$ git clone https://go.googlesource.com/go $HOME/go
[vagrant@localhost ~]$ cd $HOME/go/src
[vagrant@localhost go/src]$ git checkout release-branch.go1.8
[vagrant@localhost go/src]$ env GOROOT_BOOTSTRAP=$HOME/go1.4 ./make.bash

Step 3:
Now we are ready to compile the bootstrap to ppc64. From our go1.8 installed version we can start the process.

[vagrant@localhost ~]$ cd $HOME/go/src
[vagrant@localhost go/src]$env GOOS=linux GOARCH=ppc64 ./bootstrap.bash
...
Bootstrap toolchain for linux/ppc64 installed in /home/vagrant/go-linux-ppc64-bootstrap.
Building tbz.
-rw-rw-r--. 1 vagrant vagrant 55135445 Mar 25 12:57 /home/vagrant/go-linux-ppc64-bootstrap.tbz

Step 4:
Now we need to copy the file to the remote machine and compile it

[vagrant@localhost ~]$ ls -l /home/vagrant/go-linux-ppc64-bootstrap.tbz
-rw-rw-r--. 1 vagrant vagrant 55135445 Mar 25 12:57 /home/vagrant/go-linux-ppc64-bootstrap.tbz
[vagrant@localhost ~]$
[vagrant@localhost ~]$ scp go-linux-ppc64-bootstrap.tbz dalmine@192.168.1.85:/home/dalmine
[vagrant@localhost ~]$ ssh dalmine@192.168.1.85
dalmine@ubuntu:~$
dalmine@ubuntu:~$ tar xjf go-linux-ppc64-bootstrap.tbz
dalmine@ubuntu:~$ git clone https://go.googlesource.com/go $HOME/go
dalmine@ubuntu:~$ cd $HOME/go/src
dalmine@ubuntu:~/go/src$ git checkout release-branch.go1.8
dalmine@ubuntu:~/go/src$ env GOROOT_BOOTSTRAP=$HOME/go-linux-ppc64-bootstrap ./make.bash
---
Installed Go for linux/ppc64 in /home/dalmine/go
Installed commands in /home/dalmine/go/bin

Step 5:
We need to configure go environment now in order to start using go language.
First check we have two important variables GOPATH and GOROOT, I will left the GOROOT in the same place where I did my compilation and set GOPATH in other place.

dalmine@ubuntu:~$ /home/dalmine/go/bin/go env
GOARCH="ppc64"
GOBIN=""
GOEXE=""
GOHOSTARCH="ppc64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/dalmine/violeta/languagues/go"
GORACE=""
GOROOT="/home/dalmine/go"
GOTOOLDIR="/home/dalmine/go/pkg/tool/linux_ppc64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build083414496=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="0"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
dalmine@ubuntu:~$
dalmine@ubuntu:~$ tail -n2 .bashrc
export GOPATH=/home/dalmine/violeta/languagues/go
export GOROOT=$HOME/go
dalmine@ubuntu:~$
dalmine@ubuntu:~$ tail -n3 .bashrc
export GOPATH=/home/dalmine/violeta/languagues/go
export GOROOT=$HOME/go
PATH=$PATH:$GOROOT/bin
dalmine@ubuntu:~$
dalmine@ubuntu:~$ go version
go version go1.8.7 linux/ppc64
dalmine@ubuntu:~$

Step 6:
Now lets try to get a package from GitHub and then build it.

dalmine@ubuntu:~$ go get github.com/villadalmine/go
package github.com/villadalmine/go: no buildable Go source files in /home/dalmine/violeta/languagues/go/src/github.com/villadalmine/go
dalmine@ubuntu:~$
dalmine@ubuntu:~/violeta/languagues/go/src/github.com/villadalmine/go/hello$ pwd
/home/dalmine/violeta/languagues/go/src/github.com/villadalmine/go/hello
dalmine@ubuntu:~/violeta/languagues/go/src/github.com/villadalmine/go/hello$ go build
dalmine@ubuntu:~/violeta/languagues/go/src/github.com/villadalmine/go/hello$ ./hello
Hello linux/ppc64
dalmine@ubuntu:~/violeta/languagues/go/src/github.com/villadalmine/go/hello$

Step 7
We can make cross compiling from our ppc64


dalmine@ubuntu:~/violeta/languagues/go/src/github.com/villadalmine/go/hello$ env GOOS=darwin GOARCH=amd64 go build
dalmine@ubuntu:~/violeta/languagues/go/src/github.com/villadalmine/go/hello$ file hello
hello: Mach-O 64-bit x86_64 executable
dalmine@ubuntu:~/violeta/languagues/go/src/github.com/villadalmine/go/hello$
[I] ~ scp dalmine@192.168.1.85:/home/dalmine/violeta/languagues/go/src/github.com/villadalmine/go/hello/hello .
dalmine@192.168.1.85's password:
hello 100% 1598KB 1.3MB/s 00:01
[I] ~ ./hello
Hello darwin/amd64
[I] ~

Remember all examples are written without a lot expertise in golang and cross compiling stuff so they are a lot of things to do with better methods. Please do not follow it as standard procedures.

Links:
PPC64 How To
Go Binaries
Golang Variables

Leave a Reply