Skip to content

Instantly share code, notes, and snippets.

@truedat101
Forked from conoro/cross-compile-go-arm64.md
Last active July 17, 2020 12:40
Show Gist options
  • Save truedat101/5898604b1f7a1ec42d65a75fa6a0b802 to your computer and use it in GitHub Desktop.
Save truedat101/5898604b1f7a1ec42d65a75fa6a0b802 to your computer and use it in GitHub Desktop.
Cross-compiling Golang for ARM64 (aarch64) e.g. Pine64 on Fedora AMD64
  • Install Go for Linux the usual way on your main Linux box:
cd
wget https://storage.googleapis.com/golang/go1.8.linux-amd64.tar.gz
tar -zxvf go1.8.linux-amd64.tar.gz
sudo mv go /usr/local/
export GOROOT=/usr/local/go
mkdir -p ~/.gitwork/go/src
mkdir ~/.gitwork/go/bin
mkdir ~/.gitwork/go/pkg
export GOPATH=~/.gitwork/go
export PATH=$PATH:$GOROOT/bin
go version
  • Cross-compile Go for ARM64
mkdir gobuild
cd gobuild/
git clone https://go.googlesource.com/go
cd go
git checkout go1.8
cd src
export GOARCH=arm64
export GOROOT_BOOTSTRAP=/usr/local/go
export GOOS=linux
./make.bootstrap
  • This will create a bootstrap release under: ../../go-linux-arm64-bootstrap.tbz

  • Use sftp or scp on the ARM64 device to get the tar.gz file

  • Then install and set it up on ARM64:

TODO

update instructions below for building using the bootstrap toolchain

tar -zxvf go1.8.linux-arm64.tar.gz
sudo mv go /usr/local/
cd /usr/local/go/bin/linux_arm64
sudo cp * ..
cd
export GOROOT=/usr/local/go
mkdir -p ~/.gitwork/go/src
mkdir ~/.gitwork/go/bin
mkdir ~/.gitwork/go/pkg
export GOPATH=~/.gitwork/go
go version
export PATH=$PATH:$GOROOT/bin
@truedat101
Copy link
Author

The only thing missing is removal of .git directory before taring the build. The package is much larger than I was expecting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment