英文:
Install Bazel for Golang build applications in VScode
问题
如何在VScode中为Golang应用程序构建安装Bazel?
英文:
How to install bazel for golang application building in VScode?
答案1
得分: 3
目前还没有直接支持Bazel的功能,根据golang/go
issue 37205("x/tools/gopls
: support for bazel-based projects"),还没有对Bazel提供直接支持。
bazelbuild/rules_go
wiki/Editor-and-tool-integration中有一个用于构建编辑器和工具集成的设计文档:一个新的gopackagesdriver
二进制文件,将Bazel+rules_go与golang.org/x/tools/go/packages
集成。但是它还没有完全实现(2022年第一季度)。
在此期间,您可以按照Bazel IDE设置进行操作,包括:
- 创建一个启动脚本,比如tools/gopackagesdriver.sh:
#!/usr/bin/env bash
exec bazel run -- @io_bazel_rules_go//go/tools/gopackagesdriver "${@}"
- 在工作区的
.vscode/settings.json
中添加以下内容:
{
"go.goroot": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/go_sdk",
"go.toolsEnvVars": {
"GOPACKAGESDRIVER": "${workspaceFolder}/tools/gopackagesdriver.sh"
},
"go.enableCodeLens": {
"references": false,
"runtest": false
},
"gopls": {
"build.directoryFilters": [
"-bazel-bin",
"-bazel-out",
"-bazel-testlogs",
"-bazel-mypkg",
],
"formatting.gofumpt": true,
"formatting.local": "github.com/my/mypkg",
"ui.completion.usePlaceholders": true,
"ui.semanticTokens": true,
"ui.codelenses": {
"gc_details": false,
"regenerate_cgo": false,
"generate": false,
"test": false,
"tidy": false,
"upgrade_dependency": false,
"vendor": false
},
},
"go.useLanguageServer": true,
"go.buildOnSave": "off",
"go.lintOnSave": "off",
"go.vetOnSave": "off",
}
英文:
There is no direct support for Bazel yet, as per golang/go
issue 37205 ("x/tools/gopls
: support for bazel-based projects")
bazelbuild/rules_go
wiki/Editor-and-tool-integration has a design document for building editor and tool integration: a new gopackagesdriver
binary that integrates Bazel+rules_go with golang.org/x/tools/go/packages
.
But it is not fully implemented yet (Q1 2022).
In the meantime, you can follow Bazel IDE setup, which involves:
- Create a launcher script, say tools/gopackagesdriver.sh:
#!/usr/bin/env bash
exec bazel run -- @io_bazel_rules_go//go/tools/gopackagesdriver "${@}"
- adding in the
.vscode/settings.json
of your workspace:
{
"go.goroot": "${workspaceFolder}/bazel-${workspaceFolderBasename}/external/go_sdk",
"go.toolsEnvVars": {
"GOPACKAGESDRIVER": "${workspaceFolder}/tools/gopackagesdriver.sh"
},
"go.enableCodeLens": {
"references": false,
"runtest": false
},
"gopls": {
"build.directoryFilters": [
"-bazel-bin",
"-bazel-out",
"-bazel-testlogs",
"-bazel-mypkg",
],
"formatting.gofumpt": true,
"formatting.local": "github.com/my/mypkg",
"ui.completion.usePlaceholders": true,
"ui.semanticTokens": true,
"ui.codelenses": {
"gc_details": false,
"regenerate_cgo": false,
"generate": false,
"test": false,
"tidy": false,
"upgrade_dependency": false,
"vendor": false
},
},
"go.useLanguageServer": true,
"go.buildOnSave": "off",
"go.lintOnSave": "off",
"go.vetOnSave": "off",
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论