Skip to content

go: bootstrap via Rosetta 2 on Apple Silicon #66166

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

go: bootstrap via Rosetta 2 on Apple Silicon #66166

wants to merge 1 commit into from

Conversation

FiloSottile
Copy link
Contributor

@FiloSottile FiloSottile commented Dec 3, 2020

  • Have you followed the guidelines for contributing?
  • Have you checked that there aren't other open pull requests for the same formula update/change?
  • Have you built your formula locally with brew install --build-from-source <formula>, where <formula> is the name of the formula you're submitting?
  • Is your test running fine brew test <formula>, where <formula> is the name of the formula you're submitting?
  • Does your build pass brew audit --strict <formula> (after doing brew install <formula>)?

Go can easily cross-compile an arm64 toolchain running on Rosetta 2,
which lets us build HEAD without starting from arm64 binaries.

Had to update the bootstrap compiler to Go 1.15 since Go 1.7 segfaults
on Rosetta 2 (or maybe on Big Sur, haven't checked).

This enables building --HEAD and then Formulae that depend on go.

@bayandin
Copy link
Member

bayandin commented Dec 3, 2020

Please see #65696 (comment)

@FiloSottile
Copy link
Contributor Author

FiloSottile commented Dec 3, 2020

Hmm, I understand not wanting to carry Rosetta 2 builds, but this would enable testing all Go Formulae on Apple Silicon before February, which seems worthwhile. Otherwise, once Go 1.16 comes out there's going to be still a lot of work left to do to support the entire tree that depends on go.

Note that unlike #65696, this PR builds a native toolchain.

Go can easily cross-compile an arm64 toolchain running on Rosetta 2,
which lets us build HEAD without starting from arm64 binaries.

Had to update the bootstrap compiler to Go 1.15 since Go 1.7 segfaults
on Rosetta 2 (or maybe on Big Sur, haven't checked).

This enables building --HEAD and then Formulae that depend on go.
@felixbuenemann
Copy link
Contributor

The ENV["GODEBUG"] = "asyncpreemptoff=1" hack is no longer needed on macOS 11.1 Beta 20C5061b.

@nauxliu
Copy link

nauxliu commented Dec 7, 2020

Receiving an error when trying to install this modified formula

wget https://raw.githubusercontent.com/Homebrew/homebrew-core/51becf3204f16cd837509803ce7ab636c6b12814/Formula/go.rb
brew install go.rb
2020-12-07 14:38:51 +0800

arch
-x86_64
./make.bash
--no-clean

Building Go cmd/dist using /private/tmp/go-20201207-23655-9o1m2c/go/gobootstrap. (go1.15 darwin/amd64)
Building Go toolchain1 using /private/tmp/go-20201207-23655-9o1m2c/go/gobootstrap.
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 host, darwin/amd64.
Building packages and commands for target, darwin/arm64.
# cmd/addr2line
/private/tmp/go-20201207-23655-9o1m2c/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file /private/tmp/go-link-771027544/go.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

# cmd/buildid
/private/tmp/go-20201207-23655-9o1m2c/go/pkg/tool/darwin_amd64/link: running clang failed: exit status 1
ld: warning: ignoring file /private/tmp/go-link-677567981/go.o, building for macOS-x86_64 but attempting to link with file built for unknown-arm64
Undefined symbols for architecture x86_64:
  "_main", referenced from:
     implicit entry/start for main executable
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

// ...

go tool dist: FAILED: /private/tmp/go-20201207-23655-9o1m2c/go/pkg/tool/darwin_amd64/go_bootstrap install -gcflags=all= -ldflags=all= std cmd: exit status 2

HOMEBREW_VERSION: 2.6.0-104-g24f7898
ORIGIN: https://github.com/Homebrew/brew
HEAD: 24f7898606b0d41e74fa199032bac7bf97cf91dd
Last commit: 26 hours ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: b99dd94410c06d7e491a073ee94f0059e4581421
Core tap last commit: 4 hours ago
Core tap branch: master
HOMEBREW_PREFIX: /opt/homebrew
HOMEBREW_REPOSITORY: /opt/homebrew
HOMEBREW_CASK_OPTS: []
HOMEBREW_MAKE_JOBS: 8
Homebrew Ruby: 2.6.3 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: octa-core 64-bit arm_firestorm_icestorm
Clang: 12.0 build 1200
Git: 2.29.2 => /opt/homebrew/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 11.0.1-arm64
CLT: 12.2.0.0.1.1604076827
Xcode: 12.2
Rosetta 2: false

HOMEBREW_CC: clang
HOMEBREW_CXX: clang++
MAKEFLAGS: -j8
CMAKE_PREFIX_PATH: /opt/homebrew
CMAKE_INCLUDE_PATH: /Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Headers
CMAKE_LIBRARY_PATH: /Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk/System/Library/Frameworks/OpenGL.framework/Versions/Current/Libraries
PKG_CONFIG_LIBDIR: /usr/lib/pkgconfig:/opt/homebrew/Library/Homebrew/os/mac/pkgconfig/11.0
HOMEBREW_GIT: git
HOMEBREW_SDKROOT: /Library/Developer/CommandLineTools/SDKs/MacOSX11.0.sdk
ACLOCAL_PATH: /opt/homebrew/share/aclocal
PATH: /opt/homebrew/Library/Homebrew/shims/mac/super:/usr/bin:/bin:/usr/sbin:/sbin

@nauxliu
Copy link

nauxliu commented Dec 7, 2020

Fixed by install with --HEAD

@jimtut
Copy link
Contributor

jimtut commented Dec 17, 2020

Not an open-source newbie, but totally new to Go. Would like to install it for some other brews that require it, but I'm on Apple Silicon. Is there a way to install Go with ONLY having an ARM-based homebrew installation? I really don't want to pollute this new Mac with x86 homebrew/builds.

@SMillerDev
Copy link
Member

No, not until there is a Go version that supports it probably

@abarisain
Copy link

Follow golang/go#42684 (comment)

@FiloSottile
Copy link
Contributor Author

Not an open-source newbie, but totally new to Go. Would like to install it for some other brews that require it, but I'm on Apple Silicon. Is there a way to install Go with ONLY having an ARM-based homebrew installation? I really don't want to pollute this new Mac with x86 homebrew/builds.

That's what this PR does. You can cherry-pick it and then brew install go --HEAD.

@jimtut
Copy link
Contributor

jimtut commented Dec 17, 2020

That's what this PR does. You can cherry-pick it and then brew install go --HEAD.

How do I do that? Regular brew commands, or do I need to git-clone the repo separately and switch to this branch?

@Tenzer
Copy link
Contributor

Tenzer commented Dec 18, 2020

The first beta release of Go 1.16 is now out, and it adds support for macOS ARM64: https://tip.golang.org/doc/go1.16.

I managed to get it installed natively:

jeppe@armbook ~ % go version
go version go1.16beta1 darwin/arm64

These were the changes I made to go.rb:

diff --git a/Formula/go.rb b/Formula/go.rb
index 7e7beada8d..25f0e97588 100644
--- a/Formula/go.rb
+++ b/Formula/go.rb
@@ -4,14 +4,13 @@ class Go < Formula
   license "BSD-3-Clause"

   stable do
-    url "https://golang.org/dl/go1.15.5.src.tar.gz"
-    mirror "https://fossies.org/linux/misc/go1.15.5.src.tar.gz"
-    sha256 "c1076b90cf94b73ebed62a81d802cd84d43d02dea8c07abdc922c57a071c84f1"
+    url "https://golang.org/dl/go1.16beta1.src.tar.gz"
+    sha256 "48e032c8cf71af4dc8119a29ee829c4fbd5265e32fd012564d4a70bb207695c1"

     go_version = version.major_minor
     resource "gotools" do
       url "https://go.googlesource.com/tools.git",
-          branch: "release-branch.go#{go_version}"
+          branch: "release-branch.go1.15"
     end
   end

@@ -38,8 +37,8 @@ class Go < Formula
   # Don't update this unless this version cannot bootstrap the new version.
   resource "gobootstrap" do
     on_macos do
-      url "https://storage.googleapis.com/golang/go1.7.darwin-amd64.tar.gz"
-      sha256 "51d905e0b43b3d0ed41aaf23e19001ab4bc3f96c3ca134b48f7892485fc52961"
+      url "https://storage.googleapis.com/golang/go1.16beta1.darwin-arm64.tar.gz"
+      sha256 "fd57f47987bb330fd9b438e7b4c8941b63c3807366602d99c1d99e0122ec62f1"
     end

     on_linux do

and then I installed it with brew install --build-from-source go.

Note: There was no 1.16 branch on the gotools repository so I pointed it at the 1.15 branch instead.

@fxcoudert
Copy link
Member

Let's move to the beta version instead, indeed of using Rosetta 2.

@fxcoudert fxcoudert closed this Dec 19, 2020
@BrewTestBot BrewTestBot added the outdated PR was locked due to age label Jan 19, 2021
@Homebrew Homebrew locked as resolved and limited conversation to collaborators Jan 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.