|
| 1 | +"""A Starlark implementation of the proto_toolchain rule.""" |
| 2 | + |
| 3 | +load("//bazel/common:proto_common.bzl", "proto_common") |
| 4 | +load("//bazel/common:proto_lang_toolchain_info.bzl", "ProtoLangToolchainInfo") |
| 5 | + |
| 6 | +def _impl(ctx): |
| 7 | + kwargs = {} |
| 8 | + if getattr(proto_common, "INCOMPATIBLE_PASS_TOOLCHAIN_TYPE", False): |
| 9 | + kwargs["toolchain_type"] = "//third_party/bazel_rules/rules_proto/proto:toolchain_type" |
| 10 | + |
| 11 | + return [ |
| 12 | + DefaultInfo( |
| 13 | + files = depset(), |
| 14 | + runfiles = ctx.runfiles(), |
| 15 | + ), |
| 16 | + platform_common.ToolchainInfo( |
| 17 | + proto = ProtoLangToolchainInfo( |
| 18 | + out_replacement_format_flag = ctx.attr.command_line, |
| 19 | + output_files = ctx.attr.output_files, |
| 20 | + plugin = None, |
| 21 | + runtime = None, |
| 22 | + proto_compiler = ctx.attr.proto_compiler.files_to_run, |
| 23 | + protoc_opts = ctx.fragments.proto.experimental_protoc_opts, |
| 24 | + progress_message = ctx.attr.progress_message, |
| 25 | + mnemonic = ctx.attr.mnemonic, |
| 26 | + **kwargs |
| 27 | + ), |
| 28 | + ), |
| 29 | + ] |
| 30 | + |
| 31 | +proto_toolchain = rule( |
| 32 | + _impl, |
| 33 | + attrs = |
| 34 | + { |
| 35 | + "progress_message": attr.string(default = "Generating Descriptor Set proto_library %{label}"), |
| 36 | + "mnemonic": attr.string(default = "GenProtoDescriptorSet"), |
| 37 | + "command_line": attr.string(default = "--descriptor_set_out=%s"), |
| 38 | + "output_files": attr.string(values = ["single", "multiple", "legacy"], default = "single"), |
| 39 | + "proto_compiler": attr.label( |
| 40 | + cfg = "exec", |
| 41 | + executable = True, |
| 42 | + allow_files = True, # Used by mocks in tests. Consider fixing tests and removing it. |
| 43 | + ), |
| 44 | + }, |
| 45 | + provides = [platform_common.ToolchainInfo], |
| 46 | + fragments = ["proto"], |
| 47 | +) |
0 commit comments