无法从其他标签的源代码构建和安装 Go 语言。

huangapple go评论67阅读模式
英文:

Cannot build and install go from source code from another tag

问题

我正在尝试使用这个文档中的源代码构建和安装Go。当我按照以下步骤进行时,一切都正常:

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

这里我从主分支安装了Go。但是当我切换到另一个标签并尝试执行以下命令时:

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

这会给我带来以下错误:

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

我尝试按照错误消息的指示执行go mod init,但是它给我带来另一个错误,如下所示:

go: cannot determine module path for source directory /home/usr/goroot (outside GOPATH, module path must be specified)
英文:

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)

答案1

得分: 2

文档已过时。


从源代码安装Go,适用于Go 1.4到Go 1.20和devel go1.21。

Go1.4 make.bash使用C - gcc和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
使用/home/rocka2q/go1.4构建Go工具链1。
在/home/rocka2q/go1.17.13中安装了适用于linux/amd64的Go
在/home/rocka2q/go1.17.13/bin中安装了命令

$ git clone https://github.com/golang/go ~/goroot
$ cd ~/goroot/src && git checkout master
已经在'master'分支上
您的分支是与'origin/master'同步的。
$ cd ~/goroot/src && ./make.bash
使用/home/rocka2q/go1.17.13构建Go工具链1。
在/home/rocka2q/goroot中安装了适用于linux/amd64的Go
在/home/rocka2q/goroot/bin中安装了命令
$ ~/goroot/bin/go version
go版本devel go1.21-0853f8caec Fri Apr 14 20:24:18 2023 +0000 linux/amd64

检出另一个标签。

$ cd ~/goroot/src && git checkout go1.12
HEAD现在位于05e77d4191 [release-branch.go1.12] go1.12
$ cd ~/goroot/src && ./make.bash
使用/home/rocka2q/go1.4构建Go工具链1。
在/home/rocka2q/goroot中安装了适用于linux/amd64的Go
在/home/rocka2q/goroot/bin中安装了命令
$ ~/goroot/bin/go version
go版本go1.12 linux/amd64

英文:

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

答案2

得分: -1

当关闭模块mod时,我可以使用go1.20.3构建go1.12:

$ 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.

(尽管我遇到了一些测试失败)


我尝试使用"go1.20.3 linux/amd64"将go1.20构建回1.6:

  • go1.20 ~ go1.13:./make.bash
  • go1.12 ~ go1.10:
    • 首先关闭模块mod:go env -w GO111MODULE=off
    • ./make.bash
  • go1.9 ~ go1.6:
    • 首先关闭模块mod:go env -w GO111MODULE=off
    • 指定GOROOT_BOOTSTRAP并构建(我的go是使用snap安装的):GOROOT_BOOTSTRAP=/snap/go/current ./make.bash
  • go1.5:
    • go env -w GO111MODULE=off
    • GOROOT_BOOTSTRAP=/snap/go/current ./make.bash

我遇到了以下错误,所以放弃了:

# runtime/cgo
/usr/bin/ld: -r and -pie may not be used together
collect2: error: ld returned 1 exit status
英文:

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
      

huangapple
  • 本文由 发表于 2023年4月17日 02:05:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76029504.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定