前置条件:安装 java、go、xcode、bazel、vscode、beego,安装过程略。
笔者环境如下:
Microsoft Windows [版本 10.0.17134.228]
- - -
go version go1.11.1 windows/amd64
- - -
Python 2.7.15 (v2.7.15:ca079a3ea3, Apr 30 2018, 16:30:26) [MSC v.1500 64 bit (AMD64)] on win32
- - -
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)
- - -
bazel version
Build label: 0.19.0
Build target: bazel-out/x64_windows-opt/bin/src/main/java/com/google/devtools/build/lib/bazel/BazelServer_deploy.jar
Build time: Mon Oct 29 14:35:48 2018 (1540823748)
Build timestamp: 1540823748
Build timestamp as int: 1540823748
- - -
Visual Studio Code - Insiders
版本: 1.30.0-insider (system setup)
提交: 5fc60ec67950234cdf82ea455013617adf00e7b6
日期: 2018-11-14T06:20:26.830Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
架构: x64
首先,我们拿 Beego
来练手,先在本地新建一个 Begoo
项目跑起来:
git clone -b bazel https://gitlab.com/higkoohk/Mash && cd Mash
govendor init
govendor add +external
cp -rfv conf views tests/
在Gitlab上配置CI/CD后提交代码触发自动构建,成功:
接下来体验一下 Bazel
的效果:
#使用Gazelle自动生成Bazel配置文件
go get -u github.com/bazelbuild/bazel-gazelle/cmd/gazelle
gazelle -go_prefix gitlab.com/higkoohk/Mash
#或者用Bazel来驱动Gazelle来生成编译配置
cat << _EOF > BUILD.bazel
load("@bazel_gazelle//:def.bzl", "gazelle")
# gazelle:prefix gitlab.com/higkoohk/Mash
gazelle(name = "gazelle")
_EOF
bazel run //:gazelle
生成 gitlab.com/higkoohk/Mash/BUILD.bazel 文件如下:
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
name = "go_default_library",
srcs = ["main.go"],
importpath = "gitlab.com/higkoohk/Mash",
visibility = ["//visibility:private"],
deps = [
"//vendor/github.com/astaxie/beego:go_default_library",
"//routers:go_default_library",
],
)
go_binary(
name = "Mash",
embed = [":go_default_library"],
visibility = ["//visibility:public"],
)
成功开启build //...
模式:
附加信息:
苹果系统开启vscode之go的debug功能需要xcode的命令行工具,使用 xcode-select --install
可能由于网络原因执行失败:
可以通过苹果的开发者网站 https://developer.apple.com/download/more/ 下载,手动安装: