Whats the right way to compile go compiler locally and run my code?

I am trying to understand how to make changes to compiler so that I can contribute to it.

I got the source code locally, then ran ./all.bash, got the compiler binary. when I got these errors:

./bin/go build main.go
# internal/race
compile: version "go1.16.3" does not match go tool version "go1.16.6"
# unicode/utf8
compile: version "go1.16.3" does not match go tool version "go1.16.6"
# internal/unsafeheader
compile: version "go1.16.3" does not match go tool version "go1.16.6"
# math/bits
compile: version "go1.16.3" does not match go tool version "go1.16.6"
# runtime/internal/sys
compile: version "go1.16.3" does not match go tool version "go1.16.6"
# unicode
compile: version "go1.16.3" does not match go tool version "go1.16.6"
# runtime/internal/atomic
compile: version "go1.16.3" does not match go tool version "go1.16.6"
# sync/atomic
compile: version "go1.16.3" does not match go tool version "go1.16.6"
# internal/cpu
compile: version "go1.16.3" does not match go tool version "go1.16.6"

Do I need to change my GOPATH or GOROOT? they are currently set to:

GOPATH="/Users/john/.go"
GOROOT="/usr/local/opt/go/libexec"

@python I think you get that error if the go program you’re running isn’t the same version as the go program in $GOROOT. I haven’t tried this, but maybe changing the GOROOT before your command runs will work. Try GOROOT=./bin ./bin/go build main.go I also see that you might be able to use your existing go installation to invoke your newly-compiled go tool with this: go build --go ./bin/go main.go (I might have the argument order mixed up, but that might help get you started).

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.