github.com/stackb/rules_proto@v0.0.0-20240221195024-5428336c51f1/rules/proto_plugin.bzl (about) 1 """proto_plugin.bzl provides the "proto_plugin" rule. 2 3 A "proto_plugin" rule wraps metadata about a proto compiler plugin. 4 """ 5 6 load("@rules_proto//proto:defs.bzl", "ProtoInfo") 7 load("@build_stack_rules_proto//rules:providers.bzl", "ProtoDependencyInfo", "ProtoPluginInfo") 8 9 def _proto_plugin_impl(ctx): 10 return [ 11 ProtoPluginInfo( 12 name = ctx.attr.name, 13 label = ctx.label, 14 options = ctx.attr.options, 15 out = ctx.attr.out, 16 tool = ctx.executable.tool, 17 tool_target = ctx.attr.tool, 18 use_built_in_shell_environment = ctx.attr.use_built_in_shell_environment, 19 protoc_plugin_name = ctx.attr.protoc_plugin_name, 20 exclusions = ctx.attr.exclusions, 21 mods = ctx.attr.mods, 22 data = ctx.files.data, 23 supplementary_proto_deps = [dep[ProtoInfo] for dep in ctx.attr.supplementary_proto_deps], 24 deps = [dep[ProtoDependencyInfo] for dep in ctx.attr.deps], 25 ), 26 ] 27 28 proto_plugin = rule( 29 implementation = _proto_plugin_impl, 30 attrs = { 31 "tool": attr.label( 32 doc = "The plugin binary. If absent, it is assumed the plugin is built-in to protoc itself and builtin_plugin_name will be used if available, otherwise the plugin name", 33 cfg = "exec", 34 allow_files = True, 35 executable = True, 36 ), 37 "use_built_in_shell_environment": attr.bool( 38 doc = "Whether the tool should use the built in shell environment or not", 39 default = False, 40 ), 41 "protoc_plugin_name": attr.string( 42 doc = "The name used for the plugin binary on the protoc command line. Useful for targeting built-in plugins. Uses plugin name when not set", 43 ), 44 "options": attr.string_list( 45 doc = "A list of options to pass to the compiler for this plugin", 46 ), 47 "out": attr.string( 48 doc = "The output scheme for the plugin. Can be a string like '.' or a symbol such as {BIN_DIR} or {PACKAGE}.", 49 default = "{BIN_DIR}", 50 ), 51 "exclusions": attr.string_list( 52 doc = "Exclusion filters to apply when generating outputs with this plugin. Used to prevent generating files that are included in the protobuf library, for example. Can exclude either by proto name prefix or by proto folder prefix", 53 ), 54 "data": attr.label_list( 55 doc = "Additional files required for running the plugin", 56 allow_files = True, 57 ), 58 "supplementary_proto_deps": attr.label_list( 59 doc = "Additional proto files/descriptors to be placed on the argument list", 60 allow_files = True, 61 providers = [ProtoInfo], 62 ), 63 "deps": attr.label_list( 64 doc = "Workspace dependencies the plugin tool requires", 65 providers = [ProtoDependencyInfo], 66 ), 67 "mods": attr.string_dict( 68 doc = "content modifications to apply to the output files", 69 ), 70 }, 71 )