1.下载代码以及依赖环境
1) 由于github.com国内访问较慢,克隆gitee的镜像
cd /media/lynn/disk_d/codes/database/cockroach
mkdir -p src/github.com/cockroachdb/
mv CockroachDB cockroach
git clone https://gitee.com/mirrors/CockroachDB.git
2)下载golang-1.15
下载地址
mv go1.15.linux-amd64.tar.gz /usr/lib
tar -zxvf go1.15.linux-amd64.tar.gz
2. 下载子模块
1) 修改子模块地址: .gitmodules
[submodule "vendor"]
path = vendor
url = https://gitee.com/jianyun/vendored.git
[submodule "c-deps/jemalloc"]
path = c-deps/jemalloc
url = https://gitee.com/jianyun/jemalloc.git
[submodule "c-deps/protobuf"]
path = c-deps/protobuf
url = https://gitee.com/jianyun/protobuf.git
[submodule "pkg/ui/yarn-vendor"]
path = pkg/ui/yarn-vendor
url = https://gitee.com/jianyun/yarn-vendored.git
[submodule "c-deps/krb5"]
path = c-deps/krb5
url = https://gitee.com/jianyun/krb5.git
[submodule "c-deps/libedit"]
path = c-deps/libedit
url = https://gitee.com/lynninspur/libedit.git
[submodule "c-deps/geos"]
path = c-deps/geos
url = https://gitee.com/lynninspur/geos.git
[submodule "c-deps/proj"]
path = c-deps/proj
url = https://gitee.com/jianyun/PROJ.git
执行指令
cd /media/lynn/disk_d/codes/database/cockroach/src/github.com/cockroachdb/cockroach
git submodule init
git submodule update
git submodule sync
2) 修改c-deps/protobuf的子模块地址(c-deps/protobuf/.gitmodules)
[submodule "third_party/benchmark"]
path = third_party/benchmark
url = https://gitee.com/lynninspur/benchmark.git
[submodule "third_party/googletest"]
path = third_party/googletest
url = https://gitee.com/lynninspur/googletest.git
ignore = dirty
3. 设置环境变量,下载依赖包
export GOPATH=/media/lynn/disk_d/codes/database/cockroach
cd /media/lynn/disk_d/codes/database/cockroach/src/github.com/cockroachdb/cockroach
export GOPROXY=https://goproxy.io
export GO111MODULE=on
export GO_HOME=/usr/lib/go-1.15/
export PATH=/usr/lib/go-1.15/bin:$PATH
#下载Go依赖packages
go mod tidy
go mod vendor
4. 编译
cd /media/lynn/disk_d/codes/database/cockroach/src/github.com/cockroachdb/cockroach
make -j4 build
5. 错误
1) 编译错误
CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
阅读Makefile (139行)
pkg/ui/distccl/bindata.go: $(UI_CCL_DLLS) $(UI_CCL_MANIFESTS) $(UI_JS_CCL) $(shell find pkg/ui/ccl -type f)
pkg/ui/distoss/bindata.go: $(UI_OSS_DLLS) $(UI_OSS_MANIFESTS) $(UI_JS_OSS)
pkg/ui/dist%/bindata.go: pkg/ui/webpack.app.js $(shell find pkg/ui/src pkg/ui/styl -type f) | bin/.bootstrap
find pkg/ui/dist$* -mindepth 1 -not -name dist$*.go -delete
set -e; shopt -s extglob; for dll in $(notdir $(filter %.dll.js,$^)); do \
ln -s ../dist/$$dll pkg/ui/dist$*/$${dll/@(.ccl|.oss)}; \
done
$(NODE_RUN) -C pkg/ui $(WEBPACK) --config webpack.app.js --env.dist=$*
go-bindata -pkg dist$* -o $@ -prefix pkg/ui/dist$* pkg/ui/dist$*/...
echo 'func init() { ui.Asset = Asset; ui.AssetDir = AssetDir; ui.AssetInfo = AssetInfo }' >> $@
gofmt -s -w $@
goimports -w $@
出错指令
node ./node_modules/.bin/webpack --config webpack.app.js --env.dist=ccl
手工执行
cd pkg/ui
node --max-old-space-size=4096 ./node_modules/.bin/webpack --config webpack.app.js --env.dist=ccl
重新编译
cd /media/lynn/disk_d/codes/database/cockroach/src/github.com/cockroachdb/cockroach
make -j4 build
2) GoLand Debug时报错
GOROOT=/usr/lib/go-1.15 #gosetup
GOPATH=/media/lynn/disk_d/codes/database/cockroach:/home/lynn/go #gosetup
/usr/lib/go-1.15/bin/go build -o /tmp/___cockroach -gcflags "all=-N -l" github.com/cockroachdb/cockroach/pkg/cmd/cockroach #gosetup
/opt/GoLand-2019.2.3/plugins/go/lib/dlv/linux/dlv --listen=localhost:45269 --headless=true --api-version=2 exec /tmp/___cockroach -- start-single-node --insecure --store=/tmp/crdb --listen-addr=localhost #gosetup
API server listening at: 127.0.0.1:45269
Version of Delve is too old for this version of Go (maximum supported version 1.13, suppress this error with --check-go-version=false)
解决办法
# 下载最新版本dlv
export GOPATH=/media/lynn/disk_d/codes/database/cockroach
go get -u github.com/go-delve/delve/cmd/dlv
# 查找dlv所在位置
lynn@lynn-ubuntu:/opt/GoLand-2019.2.3/plugins/go/lib/dlv/linux$ echo `go env | grep GOPATH | cut -d "\"" -f 2`/bin/dlv
/media/lynn/disk_d/codes/database/cockroach/bin/dlv
#查看版本
lynn@lynn-ubuntu:/opt/GoLand-2019.2.3/plugins/go/lib/dlv/linux$ /media/lynn/disk_d/codes/database/cockroach/bin/dlv version
Delve Debugger
Version: 1.5.1
Build: $Id: bca418ea7ae2a4dcda985e623625da727d4525b5 $
lynn@lynn-ubuntu:/opt/GoLand-2019.2.3/plugins/go/lib/dlv/linux$ /opt/GoLand-2019.2.3/plugins/go/lib/dlv/linux/dlv version
Delve Debugger
Version: 1.3.0
Build: a82e6d69875ed11a0bb3b80d15efba4b4722106e
设置GoLand
在 GoLand 中 Help -> Edit Custom Properties(之前没编辑过会提示新建)
新增一项 dlv.path={你复制的路径},比如我的:
dlv.path=/media/lynn/disk_d/codes/database/cockroach/bin/dlv
重新启动GoLand,即可解决该问题
来源:oschina
链接:https://my.oschina.net/u/4352922/blog/4814600