win32: 使用go编译go自身

因项目需要,需要重新编译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.

可以看到,编译时间已经更新:




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值