4

I am trying to build and install go from source code using this documentation. This works fine when I do like the following:

 $ git clone https://go.googlesource.com/go goroot
 $ cd goroot
 $ git checkout master
 $ cd src
 $ ./all.bash`

Here I installed go from master branch. But when I checkout to another tag and try to execcute ./all.bash like following:

 $ git clone https://go.googlesource.com/go goroot
 $ cd goroot
 $ git checkout go1.12
 $ cd src
 $ ./all.bash`

this gives me the folowing error:

    go: cannot find main module, but found .git/config in /home/usr/goroot
    to create a module there, run:
    cd .. && go mod init`

I tried to do as the error message instructed i.e. go mod init , it gives me another error like the followig:

go: cannot determine module path for source directory /home/usr/goroot (outside GOPATH, module path must be specified)
erik258
  • 14,701
  • 2
  • 25
  • 31

2 Answers2

2

The documentation is out of date.


Installing Go from source for Go 1.4 through Go 1.20 and devel go1.21.

# Go1.4 make.bash uses C - gcc and libc6-dev
$ git clone https://github.com/golang/go -b release-branch.go1.4 --depth 1 ~/go1.4
$ cd ~/go1.4/src && ./make.bash 2>/dev/null

$ git clone https://github.com/golang/go -b release-branch.go1.17 --depth 1 ~/go1.17.13
$ cd ~/go1.17.13/src && ./make.bash
Building Go toolchain1 using /home/rocka2q/go1.4.
Installed Go for linux/amd64 in /home/rocka2q/go1.17.13
Installed commands in /home/rocka2q/go1.17.13/bin

$ git clone https://github.com/golang/go ~/goroot
$ cd ~/goroot/src && git checkout master
Already on 'master'
Your branch is up to date with 'origin/master'.
$ cd ~/goroot/src && ./make.bash
Building Go toolchain1 using /home/rocka2q/go1.17.13.
Installed Go for linux/amd64 in /home/rocka2q/goroot
Installed commands in /home/rocka2q/goroot/bin
$ ~/goroot/bin/go version 
go version devel go1.21-0853f8caec Fri Apr 14 20:24:18 2023 +0000 linux/amd64

Checkout another tag.

$ cd ~/goroot/src && git checkout go1.12
HEAD is now at 05e77d4191 [release-branch.go1.12] go1.12
$ cd ~/goroot/src && ./make.bash
Building Go toolchain1 using /home/rocka2q/go1.4.
Installed Go for linux/amd64 in /home/rocka2q/goroot
Installed commands in /home/rocka2q/goroot/bin
$ ~/goroot/bin/go version 
go version go1.12 linux/amd64
rocka2q
  • 2,473
  • 4
  • 11
-1

I can build go1.12 with go1.20.3 when the module mod is turned off:

$ go version
go version go1.20.3 linux/amd64
$ go env -w GO111MODULE=off
$ git checkout go1.12
$ cd src
$ ./all.bash
Building Go cmd/dist using /snap/go/current.
Building Go toolchain1 using /snap/go/current.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
go_asm.h:493:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:494:39: 'p' exponent requires hexadecimal mantissa
go_asm.h:493:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:494:39: 'p' exponent requires hexadecimal mantissa
go_asm.h:493:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:494:39: 'p' exponent requires hexadecimal mantissa
go_asm.h:493:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:494:39: 'p' exponent requires hexadecimal mantissa
Building Go toolchain2 using go_bootstrap and Go toolchain1.
# runtime
go_asm.h:493:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:494:39: 'p' exponent requires hexadecimal mantissa
# runtime
go_asm.h:493:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:494:39: 'p' exponent requires hexadecimal mantissa
# runtime
go_asm.h:493:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:494:39: 'p' exponent requires hexadecimal mantissa
# runtime
go_asm.h:493:33: 'p' exponent requires hexadecimal mantissa
go_asm.h:494:39: 'p' exponent requires hexadecimal mantissa
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for linux/amd64.

(I got some test failures though)


I have tried to build go1.20 back to 1.6 with "go1.20.3 linux/amd64":

  • go1.20 ~ go1.13: ./make.bash
  • go1.12 ~ go1.10:
    • turn off module mod first:go env -w GO111MODULE=off
    • ./make.bash
  • go1.9 ~ go 1.6:
    • turn off module mod first:go env -w GO111MODULE=off
    • specify GOROOT_BOOTSTRAP and build (my go is installed with snap): GOROOT_BOOTSTRAP=/snap/go/current ./make.bash
  • go1.5:
    • go env -w GO111MODULE=off

    • GOROOT_BOOTSTRAP=/snap/go/current ./make.bash

      I got this error so I gave up:

      # runtime/cgo
      /usr/bin/ld: -r and -pie may not be used together
      collect2: error: ld returned 1 exit status
      
Zeke Lu
  • 6,349
  • 1
  • 17
  • 23
  • 1
    Don't install from Snap. Use the official source. You have to go forward before you can go back. – rocka2q Apr 17 '23 at 01:35