1.克隆Go源码:
# 克隆代码
git clone https://github.com/golang/go.git
# 切换到1.14分支
git checkout release-branch.go1.14
2.编译:
cd go/src
./all.bash
报错:
./make.bash: line 165: /Users/peakchao/go1.4/bin/go: No such file or directory
Building Go cmd/dist using /Users/peakchao/go1.4. ()
ERROR: Cannot find /Users/peakchao/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
高版本编译需要用到1.4版本,所以先编译1.4:
git checkout release-branch.go1.4
./all.bash
编译完成:
# Building C bootstrap tool.
cmd/dist
# Building compilers and Go bootstrap tool for host, darwin/amd64.
lib9
libbio
liblink
cmd/cc
cmd/gc
cmd/6l
/Users/peakchao/App/go/src/cmd/6l/../ld/dwarf.c:1479:15: warning: implicit conversion from 'int' to 'char' changes value from 156 to -100 [-Wconstant-conversion]
/Users/peakchao/App/go/src/cmd/6l/../ld/dwarf.c:1763:21: warning: implicit conversion from 'int' to 'char' changes value from 144 to -112 [-Wconstant-conversion]
/Users/peakchao/App/go/src/cmd/6l/../ld/lib.h:168:13: note: expanded from macro 'cput'
cmd/6a
cmd/6c
/Users/peakchao/App/go/src/cmd/6c/txt.c:995:28: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
/Users/peakchao/App/go/src/cmd/6c/txt.c:1045:28: warning: shifting a negative signed value is undefined [-Wshift-negative-value]
cmd/6g
runtime
errors
sync/atomic
sync
io
unicode
unicode/utf8
unicode/utf16
bytes
math
strings
strconv
bufio
sort
container/heap
encoding/base64
syscall
time
os
reflect
fmt
encoding
encoding/json
flag
path/filepath
path
io/ioutil
log
regexp/syntax
regexp
go/token
go/scanner
go/ast
go/parser
os/exec
os/signal
net/url
text/template/parse
text/template
go/doc
go/build
cmd/go
# Building packages and commands for darwin/amd64.
runtime
errors
sync/atomic
unicode
unicode/utf8
math
sort
encoding
unicode/utf16
container/list
crypto/subtle
container/ring
image/color
runtime/race
sync
container/heap
image/color/palette
io
syscall
hash
crypto/cipher
hash/crc32
crypto/hmac
hash/adler32
hash/crc64
hash/fnv
bytes
strings
bufio
text/tabwriter
path
html
compress/bzip2
time
strconv
math/rand
math/cmplx
os
reflect
regexp/syntax
crypto
encoding/base64
net/url
crypto/aes
crypto/rc4
encoding/ascii85
encoding/base32
image
crypto/md5
crypto/sha1
crypto/sha256
crypto/sha512
encoding/pem
image/draw
image/jpeg
path/filepath
net
os/signal
io/ioutil
os/exec
regexp
fmt
encoding/binary
cmd/pprof/internal/svg
crypto/des
index/suffixarray
cmd/internal/goobj
cmd/internal/rsc.io/arm/armasm
cmd/internal/rsc.io/x86/x86asm
debug/dwarf
debug/gosym
debug/plan9obj
flag
log
go/token
encoding/json
encoding/xml
text/template/parse
compress/flate
go/scanner
math/big
encoding/hex
mime
go/ast
net/http/internal
runtime/pprof
cmd/pack
debug/elf
debug/macho
debug/pe
compress/gzip
cmd/pprof/internal/tempfile
text/template
archive/tar
archive/zip
compress/lzw
cmd/pprof/internal/profile
crypto/elliptic
encoding/asn1
crypto/rand
crypto/dsa
compress/zlib
crypto/rsa
net/textproto
go/parser
go/printer
database/sql/driver
cmd/internal/objfile
encoding/csv
encoding/gob
database/sql
crypto/ecdsa
crypto/x509/pkix
mime/multipart
image/gif
image/png
log/syslog
crypto/x509
go/doc
html/template
net/mail
os/user
runtime/debug
cmd/addr2line
cmd/nm
cmd/objdump
testing
cmd/pprof/internal/plugin
cmd/pprof/internal/symbolz
testing/iotest
cmd/cgo
go/format
cmd/gofmt
cmd/pprof/internal/symbolizer
go/build
cmd/fix
cmd/yacc
testing/quick
crypto/tls
text/scanner
cmd/pprof/internal/report
cmd/pprof/internal/commands
cmd/pprof/internal/driver
net/http
net/smtp
cmd/go
cmd/pprof/internal/fetch
expvar
net/http/cgi
net/http/cookiejar
net/http/httptest
net/http/httputil
net/http/pprof
net/rpc
cmd/pprof
net/http/fcgi
net/rpc/jsonrpc
Build complete; skipping tests.
To force tests, set GO14TESTS=1 and re-run, but expect some failures.
编译1.14版本:
git checkout release-branch.go1.14
./all.bash
输出:
./make.bash: line 165: /Users/peakchao/go1.4/bin/go: No such file or directory
Building Go cmd/dist using /Users/peakchao/go1.4. ()
ERROR: Cannot find /Users/peakchao/go1.4/bin/go.
Set $GOROOT_BOOTSTRAP to a working Go tree >= Go 1.4.
3.配置1.4环境后重新编译:
# 切换到1.4分支
git checkout release-branch.go1.4
# 复制1.4到提示目录,也可以通过设置$GOROOT_BOOTSTRAP环境变量解决
cp ~/go ~/go1.4 -rf
git checkout release-branch.go1.14
git clean -dfx
./all.bash
输出:
Building Go cmd/dist using /Users/peakchao/go1.4. (go1.4-bootstrap-20170531 darwin/amd64)
Building Go toolchain1 using /Users/peakchao/go1.4.
Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
Building Go toolchain2 using go_bootstrap and Go toolchain1.
Building Go toolchain3 using go_bootstrap and Go toolchain2.
Building packages and commands for darwin/amd64.
##### Testing packages.
ok archive/tar 2.301s
ok archive/zip 1.430s
ok bufio 0.697s
ok bytes 1.212s
ok compress/bzip2 0.441s
ok compress/flate 2.064s
ok compress/gzip 1.699s
ok compress/lzw 0.856s
ok compress/zlib 2.507s
ok container/heap 2.602s
ok container/list 2.875s
ok container/ring 3.123s
ok context 4.684s
ok crypto 3.118s
ok crypto/aes 3.401s
ok crypto/cipher 3.635s
ok crypto/des 4.060s
ok crypto/dsa 4.070s
ok crypto/ecdsa 3.996s
ok crypto/ed25519 4.091s
ok crypto/elliptic 4.078s
ok crypto/hmac 4.347s
ok crypto/internal/subtle 4.103s
ok crypto/md5 4.067s
ok crypto/rand 4.046s
ok crypto/rc4 4.098s
ok crypto/rsa 3.788s
ok crypto/sha1 3.428s
ok crypto/sha256 3.628s
ok crypto/sha512 3.730s
ok crypto/subtle 3.659s
ok crypto/tls 3.761s
ok database/sql 3.194s
ok database/sql/driver 2.565s
ok debug/dwarf 2.370s
ok debug/elf 2.862s
ok debug/gosym 3.074s
ok debug/macho 3.490s
ok debug/pe 3.429s
ok debug/plan9obj 3.514s
ok encoding/ascii85 3.613s
ok encoding/asn1 3.590s
ok encoding/base32 3.316s
ok encoding/base64 3.369s
ok encoding/binary 3.036s
ok encoding/csv 3.109s
ok encoding/gob 3.305s
ok encoding/hex 2.995s
ok encoding/json 2.900s
ok encoding/pem 2.596s
ok encoding/xml 3.124s
ok errors 3.245s
ok expvar 2.893s
ok flag 3.340s
ok fmt 3.839s
ok go/ast 3.802s
ok go/build 4.074s
ok go/constant 3.961s
ok go/doc 3.901s
ok go/format 3.957s
ok go/importer 4.034s
ok go/internal/gccgoimporter 3.581s
ok go/internal/gcimporter 4.276s
ok go/internal/srcimporter 4.417s
ok go/parser 4.256s
ok go/printer 4.138s
ok go/scanner 3.675s
ok go/token 3.636s
ok go/types 4.210s
ok hash 3.195s
ok hash/adler32 3.440s
ok hash/crc32 3.595s
ok hash/crc64 3.903s
ok hash/fnv 3.727s
ok hash/maphash 3.603s
ok html 3.307s
ok html/template 3.223s
ok image 3.095s
ok image/color 3.168s
ok image/draw 3.295s
ok image/gif 3.581s
ok image/jpeg 3.630s
ok image/png 3.274s
ok index/suffixarray 4.200s
ok internal/cpu 1.969s
ok internal/fmtsort 3.679s
ok internal/poll 5.395s
ok internal/reflectlite 5.015s
ok internal/singleflight 1.921s
ok internal/trace 2.298s
ok internal/xcoff 2.101s
ok io 2.529s
ok io/ioutil 2.765s
ok log 4.793s
ok log/syslog 6.720s
ok math 5.257s
ok math/big 6.667s
ok math/bits 5.332s
ok math/cmplx 5.636s
ok math/rand 6.221s
ok mime 6.238s
ok mime/multipart 6.327s
ok mime/quotedprintable 6.212s
ok net 6.088s
ok net/http 11.106s
ok net/http/cgi 2.991s
ok net/http/cookiejar 4.818s
ok net/http/fcgi 4.892s
ok net/http/httptest 5.195s
ok net/http/httptrace 5.599s
ok net/http/httputil 5.249s
ok net/http/internal 5.147s
ok net/http/pprof 8.541s
ok net/internal/socktest 6.019s
ok net/mail 6.866s
ok net/rpc 6.179s
ok net/rpc/jsonrpc 4.474s
ok net/smtp 4.443s
ok net/textproto 6.913s
ok net/url 6.846s
ok os 6.660s
ok os/exec 4.707s
ok os/signal 10.322s
ok os/user 5.406s
ok path 5.345s
ok path/filepath 5.267s
ok plugin 4.175s
ok reflect 6.298s
ok regexp 7.030s
ok regexp/syntax 8.374s
ok runtime 53.213s
ok runtime/debug 6.649s
ok runtime/internal/atomic 7.053s
ok runtime/internal/math 7.320s
ok runtime/internal/sys 6.982s
ok runtime/pprof 20.282s
ok runtime/pprof/internal/profile 7.003s
ok runtime/trace 8.134s
ok sort 5.677s
ok strconv 5.375s
ok strings 4.512s
ok sync 3.606s
ok sync/atomic 3.594s
ok syscall 2.663s
ok testing 3.400s
ok testing/iotest 3.312s
ok testing/quick 3.234s
ok text/scanner 2.783s
ok text/tabwriter 3.180s
ok text/template 2.928s
ok text/template/parse 3.303s
ok time 5.857s
ok unicode 2.978s
ok unicode/utf16 3.199s
ok unicode/utf8 3.957s
ok cmd/addr2line 10.116s
ok cmd/api 5.832s
ok cmd/asm/internal/asm 6.211s
ok cmd/asm/internal/lex 5.494s
ok cmd/compile 2.438s
ok cmd/compile/internal/gc 17.988s
ok cmd/compile/internal/logopt 5.153s
ok cmd/compile/internal/ssa 4.830s
ok cmd/compile/internal/syntax 3.450s
ok cmd/compile/internal/test 2.841s [no tests to run]
ok cmd/compile/internal/types 2.685s
ok cmd/cover 17.359s
ok cmd/doc 5.632s
ok cmd/fix 7.109s
ok cmd/go 71.735s
ok cmd/go/internal/auth 5.069s
ok cmd/go/internal/cache 5.325s
ok cmd/go/internal/generate 7.034s
ok cmd/go/internal/get 6.218s
ok cmd/go/internal/imports 5.004s
ok cmd/go/internal/load 4.997s
ok cmd/go/internal/lockedfile 5.068s
ok cmd/go/internal/lockedfile/internal/filelock 5.217s
ok cmd/go/internal/modconv 4.674s
ok cmd/go/internal/modfetch 4.519s
ok cmd/go/internal/modfetch/codehost 4.824s
ok cmd/go/internal/modfetch/zip_sum_test 5.082s
ok cmd/go/internal/modload 4.560s
ok cmd/go/internal/mvs 4.735s
ok cmd/go/internal/par 4.871s
ok cmd/go/internal/renameio 5.686s
ok cmd/go/internal/search 4.781s
ok cmd/go/internal/txtar 4.713s
ok cmd/go/internal/web 4.387s
ok cmd/go/internal/work 3.345s
ok cmd/gofmt 3.024s
ok cmd/internal/buildid 3.151s
ok cmd/internal/dwarf 3.579s
ok cmd/internal/edit 3.619s
ok cmd/internal/goobj 6.910s
ok cmd/internal/obj 2.667s
ok cmd/internal/obj/arm64 3.026s
ok cmd/internal/obj/riscv 2.690s
ok cmd/internal/obj/x86 6.984s
ok cmd/internal/objabi 2.926s
ok cmd/internal/src 3.032s
ok cmd/internal/test2json 3.279s
ok cmd/link 5.683s
ok cmd/link/internal/ld 9.549s
ok cmd/link/internal/sym 2.120s
ok cmd/nm 6.625s
ok cmd/objdump 6.328s
ok cmd/pack 8.937s
ok cmd/trace 2.387s
ok cmd/vet 9.727s
...
4.配置环境变量:
#go
export GOROOT_BOOTSTRAP=/Users/peakchao/go1.4
export GOROOT=/Users/peakchao/App/go
export GOPATH=/Users/peakchao/App/gopath
export GOBIN=${GOPATH}/bin
export PATH=${PATH}:${GOBIN}:${GOROOT}/bin
5.校验:
go version