因项目需要,需要重新编译go。
本文记录使用go编译go自身的流程,方便后面继续修改编译:
如直接自己编译自己,会出现下面的错误:
$ cd /c/go/src
$ ./make.bat
Building Go cmd/dist using C:\Go
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile"
go tool: no such tool "compile"
查看go env发现也没任何错误:
$ go env
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\Mike\AppData\Local\go-build
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\dev\golang
set GORACE=
set GOROOT=c:\go
set GOTMPDIR=
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GCCGO=gccgo
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\Mike\AppData\Local\Temp\go-build976029818=/tmp/go-build -gno-record-gcc-switches
怀疑是其他地方的问题。折腾了半天,后来发现
GOTOOLDIR 为空使用bootstrap源码编译工具链
参考这里的 说明,先下载 go1.4-bootstrap-20171003.tar.gz,使用已经下载的go编译,日志如下:$ GOOS=windows GOARCH=amd64 ./make.bat
# Building C bootstrap tool.
cmd/dist
# Building compilers and Go bootstrap tool.
E:\go\src\lib9\fmt\fltfmt.c: In function '__efgfmt':
E:\go\src\lib9\fmt\fltfmt.c:437:5: warning: this statement may fall through [-Wi mplicit-fallthrough=]
if(ndigits > prec) {
^
E:\go\src\lib9\fmt\fltfmt.c:451:2: note: here
省略大部分日志
---
Installed Go for windows/amd64 in E:\go
Installed commands in E:\go\bin
可以看到,编译时间已经更新:
123
修改GOROOT_BOOTSTRAP,设置为E:\go,重新编译
$ GOOS=windows GOARCH=amd64 ./make.bat
# Building C bootstrap tool.
可以看到,编译时间已经更新: