英文:
How to use Google APIs with Go in Bazel
问题
我目前正在尝试使用Go从Bazel消费Google APIs(目前仅限于注释选项)。
有一个官方仓库用于proto API。在那里,他们将Go用户重定向到特殊的Go变体。
两者都只定义了一个存根Bazel包。因此,似乎都不能直接使用。
因此,一种方法是fork 后者,引入Packages来构建go_proto_libraries
,并希望目录结构符合go rules。
问题:
- 是否已经有另一个可以简单使用的仓库?
如果没有:
- 后者的仓库被标记为实验性的。更改的可能性有多大?
- 后者的仓库是否保持同步?
- 应该使用后者仓库中的源代码还是使用Bazel从头开始构建新的源代码?
- 是否有更好的方法来完成这个任务?
英文:
I am currently trying to consume Google APIs (for now only due to the annotation options) in Go from Bazel.
There is the official repo for the proto API. There they redirect Go users to special go variant.
Both have only a stub Bazel package defined. Thus none seems to be directly usable.
So one way to do this would be to fork the latter, introduce Packages to build go_proto_libraries
and hope that the directory structure appeases the go rules.
Questions:
- Is there already another repository, which can be used simply?
If not:
- The latter repo is marked as experimental. How likely are changes?
- Is the latter repo kept in sync?
- Should the sources in the latter repo be used or new ones built with Bazel from scratch?
- Is there a better way of doing this?
答案1
得分: 2
我问了Go团队,答案是:
-
https://github.com/bazelbuild/rules_go/blob/master/proto/go_proto_library.bzl 对于.proto文件与.pb.go文件完全不同的位置的情况,没有一个很好的解决方案,除非使用genrule来复制.proto文件并使用go_proto_library对其进行操作。
-
https://github.com/pubref/rules_protobuf/blob/master/go/rules.bzl 有一个go_proto_library,允许.proto文件来自一个地方,.pb.go文件来自另一个地方,但免责声明:此代码不是由Google拥有或维护。
至于问题:
-
不是
-
不知道
-
参见2
-
bazel始终建议从源代码生成(在这种情况下是.proto文件)
-
还没有
英文:
I asked the go team and the answer was:
> https://github.com/bazelbuild/rules_go/blob/master/proto/go_proto_library.bzl does not have a good solution for this case where the .proto is in a completely different location from the .pb.go files other than using a genrule to copy the .proto file from its source and then a go_proto_library to operate on it.
> https://github.com/pubref/rules_protobuf/blob/master/go/rules.bzl has a go_proto_library that allows the .proto from one place and the .pb.go from another, but disclaimer: this code is not owned or maintained by Google.
> As to the questions:
> 1) No
> 2) No idea
> 3) See 2
> 4) bazel always recommends generating from the source (in this case the .proto files)
> 5) Not yet
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论