Blog

Since the first Apple silicon-based (M1) machines are shipping there is more and more stuff popping up around the net regarding go on these machines. Folks like Filippo quickly jumped on the bandwagon and started hacking away on getting stuff running. Filippo has a nice document where he keeps track of items working on M1.

Mainline go has not been released for darwin/arm64 yet - so folks having a new, shiny Apple silicon-based machine can take the following steps to get go up and running. Beware - despite that the following steps will give a working go toolchain - there are further bugs. In the go github project these should be labeled with arch-arm64 and OS-Darwin.

You can bootstrap go either on a machine you have at hand or via Rosetta 2. To launch a shell that runs via Rosetta 2:

$ arch -x86_64 zsh

Alternatively have a second machine with go installed. I’ve done these steps on my intel based mac:

fkr@badwater ~> uname -a
Darwin badwater.local 20.2.0 Darwin Kernel Version 20.2.0: Tue Nov 10 21:14:14 PST 2020; root:xnu-7195.60.70.111.1~1/RELEASE_X86_64 x86_64
fkr@badwater ~> go version
go version go1.15.5 darwin/amd64

There I grabbed the latest go from git:

$ git clone git@github.com:golang/go.git

Which will give a clone of the src. Go to the src folder (go/src) and run:

$ GOARCH=arm64 GOOS=darwin ./bootstrap.bash

This will build go for the arm64 architecture for darwin (aka: macOS). The resulting file (go-darwin-arm64-bootstrap.tbz) will be placed outside of the git directory. Copy this to the M1 machine and unpack in /opt, so that you will have /opt/go.

$ sudo mkdir /opt/go
$ sudo tar xzfv go-darwin-arm64-bootstrap.tbz -C /tmp/a --strip-components=1

Because of this bug the resulting binaries need to be code-signed.

$ cd /opt/go/bin
$ ls | xargs -n1 -IFOO codesign -s - FOO
$ cd /opt/go/pkg/tool/darwin_arm64
$ ls | xargs -n1 -IFOO codesign -s - FOO

Be sure to add these paths to your $PATH variable in order to have the commands directly at hand.

fkr@platypus /o/g/p/t/darwin_arm64> uname -a
Darwin platypus.local 20.2.0 Darwin Kernel Version 20.2.0: Tue Nov 10 21:14:10 PST 2020; root:xnu-7195.60.70.111.1~1/RELEASE_ARM64_T8101 arm64
fkr@platypus /o/g/p/t/darwin_arm64> go version
go version devel +f0ff6d4a67 Thu Nov 26 05:00:21 2020 +0000 darwin/arm64