如何依赖 extra_action protobuf 作为 extra_action 工具?

How to depend on the extra_action protobuf for an extra_action tool?

我正在尝试编写一个使用 action_listener/extra_action 调用的工具。该工具需要读取 $(EXTRA_ACTION_FILE)。要实际读取文件的内容,我需要 proto_library 来解码信息。实现此目标的最佳方法是什么?

我试过类似的方法:

java_binary(
    name = "analyzer",
    srcs = ["Analyzer.java"],
    deps = [
        "@bazel_tools//src/main/protobuf:extra_actions_base_java_proto"
    ]
)

但这不起作用,因为我的工作区中没有工具可以使用它,@build_tools//src/main/protobuf 中的 BUILD 文件有几个从 Bazel 存储库加载内容的加载语句。这些库是否在 Bazel 安装中预先构建的某处提供?

编写需要 protobuf 的 extra_action 工具的最佳实践是什么?

不幸的是,到目前为止,答案只是将原型复制到您的工作区,例如进入 //third_party/bazel/... 然后使用 protobuf 规则为您的分析器编译它。