go: cmd/dist: make.bash throws undefined error when building from source

What version of Go are you using (go version)?

go version go1.16.3 darwin/amd64

Does this issue reproduce with the latest release?

It does not related to the version.

What operating system and processor architecture are you using (go env)?

go env Output
GO111MODULE="on"
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/furkan.turkal/Library/Caches/go-build"
GOENV="/Users/furkan.turkal/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/furkan.turkal/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/furkan.turkal/go"
GOPRIVATE=""
GOPROXY="direct"
GOROOT="/usr/local/Cellar/go/1.16.3/libexec"
GOSUMDB="off"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.16.3/libexec/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.16.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/furkan.turkal/src/public/go/src/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/nq/vxjjn3311fg4q263qsxrghpcpzgp66/T/go-build71174443=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

  1. $ git clone https://go.googlesource.com/go

  2. $ cd go/src

  3. $ ./make.bash # OK

  4. Play with the source code (i.e. define a new constant variable, and just use it somewhere)

  5. Run the ./make.bash again

What did you expect to see?

It should be built successfully? 🤔

What did you see instead?

  1. See the error:
Building Go cmd/dist using /usr/local/Cellar/go/1.16.3/libexec. (go1.16.3 darwin/amd64)
Building Go toolchain1 using /usr/local/Cellar/go/1.16.3/libexec.
# bootstrap/go/constant
/Users/furkan.turkal/src/public/go/src/go/constant/value.go:1003: undefined: token.TEST
go tool dist: FAILED: /usr/local/Cellar/go/1.16.3/libexec/bin/go install -gcflags=-l -tags=math_big_pure_go compiler_bootstrap bootstrap/cmd/...: exit status 2

undefined: token.TEST: But it’s already defined in the cloned repo. Bootstrap throws this error because it was not defined in /usr/local/Cellar/go/1.16.3/libexec/src/go/token/token.go file, and $GOROOT_BOOTSTRAP lookup that directory.

But I could not figure out how to make the GOROOT_BOOTSTRAP env to look at the source directory when compiling. It uses my /usr/local path which I’ve installed with Brew.

If I run the following command in ./src:

$ GOROOT_BOOTSTRAP="/Users/furkan.turkal/src/public/go" ./make.bash

It’s failing:

Building Go cmd/dist using /Users/furkan.turkal/src/public/go. (devel go1.17-fe26dfadc3 Tue Apr 20 02:42:23 2021 +0000 darwin/amd64)
ERROR: $GOROOT_BOOTSTRAP must not be set to $GOROOT
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.

I have followed the exact same steps when I was working with Go 1.16. Is this because Go 1.17 has some kind of behavioral change? Or am I missing something important here?

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 19 (16 by maintainers)

Most upvoted comments

Some packages support build tags for building simplified variants during bootstrap. E.g., math/big has math_big_pure_go and strconv and math/bits have compiler_bootstrap. It might be possible to do something similar for go/constant, if you’re particularly pressed for this to work today.

But I think like @ianlancetaylor points out, waiting for #44505 seems like the simplest/surest solution.

I agree that it’s a bit awkward that we’ve locked ourselves into a place where it’s hard to add a new parsing token that is referenced by go/constant, but that seems to be where we are. Everything does work, even if you can’t make certain kinds of changes. And I think that #44505 does give us a path to fix it, fairly soon. So I don’t think there is anything to do here.