Protocol Buffer Rules

Report an issue View source Nightly · 7.4 . 7.3 · 7.2 · 7.1 · 7.0 · 6.5

Rules

py_proto_library

View rule source
py_proto_library(name, deps, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
Use `py_proto_library` to generate Python libraries from `.proto` files. The convention is to name the `py_proto_library` rule `foo_py_pb2`, when it is wrapping `proto_library` rule `foo_proto`. `deps` must point to a `proto_library` rule. Example: ```starlark py_library( name = "lib", deps = [":foo_py_pb2"], ) py_proto_library( name = "foo_py_pb2", deps = [":foo_proto"], ) proto_library( name = "foo_proto", srcs = ["foo.proto"], ) ```

Arguments

Attributes
name

Name; required

A unique name for this target.

deps

List of labels; default is []

The list of `proto_library` rules to generate Python libraries for. Usually this is just the one target: the proto library of interest. It can be any target providing `ProtoInfo`.

proto_lang_toolchain

View rule source
proto_lang_toolchain(name, allowlist_different_package, blacklisted_protos, command_line, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, mnemonic, output_files, plugin, plugin_format_flag, progress_message, protoc_minimal_do_not_use, restricted_to, runtime, tags, target_compatible_with, testonly, toolchain_type, toolchains, visibility)

If using Bazel, please load the rule from https://github.com/bazelbuild/rules_proto.

Specifies how a LANG_proto_library rule (e.g., java_proto_library) should invoke the proto-compiler. Some LANG_proto_library rules allow specifying which toolchain to use using command-line flags; consult their documentation.

Normally you should not write those kind of rules unless you want to tune your Java compiler.

There's no compiler. The proto-compiler is taken from the proto_library rule we attach to. It is passed as a command-line flag to Blaze. Several features require a proto-compiler to be invoked on the proto_library rule itself. It's beneficial to enforce the compiler that LANG_proto_library uses is the same as the one proto_library does.

Examples

A simple example would be:


proto_lang_toolchain(
    name = "javalite_toolchain",
    command_line = "--javalite_out=shared,immutable:$(OUT)",
    plugin = ":javalite_plugin",
    runtime = ":protobuf_lite",
)

Arguments

Attributes
name

Name; required

A unique name for this target.

allowlist_different_package

Label; default is None

blacklisted_protos

List of labels; default is []

No code will be generated for files in the srcs attribute of blacklisted_protos. This is used for .proto files that are already linked into proto runtimes, such as any.proto.
command_line

String; required

This value will be passed to proto-compiler to generate the code. Only include the parts specific to this code-generator/plugin (e.g., do not include -I parameters)
  • $(OUT) is LANG_proto_library-specific. The rules are expected to define how they interpret this variable. For Java, for example, $(OUT) will be replaced with the src-jar filename to create.
mnemonic

String; default is "GenProto"

This value will be set as the mnemonic on protoc action.
output_files

String; default is "legacy"

Controls how $(OUT) in command_line is formatted, either by a path to a single file or output directory in case of multiple files. Possible values are: "single", "multiple".
plugin

Label; default is None

If provided, will be made available to the action that calls the proto-compiler, and will be passed to the proto-compiler: --plugin=protoc-gen-PLUGIN=<executable>.
plugin_format_flag

String; default is ""

If provided, this value will be passed to proto-compiler to use the plugin. The value must contain a single %s which is replaced with plugin executable. --plugin=protoc-gen-PLUGIN=<executable>.
progress_message

String; default is "Generating proto_library %{label}"

This value will be set as the progress message on protoc action.
protoc_minimal_do_not_use

Label; default is None

runtime

Label; default is None

A language-specific library that the generated code is compiled against. The exact behavior is LANG_proto_library-specific. Java, for example, should compile against the runtime.
toolchain_type

Label; default is None

proto_toolchain

View rule source
proto_toolchain(name, command_line, compatible_with, deprecation, distribs, exec_compatible_with, exec_properties, features, mnemonic, output_files, progress_message, proto_compiler, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)

Arguments

Attributes
name

Name; required

A unique name for this target.

command_line

String; default is "--descriptor_set_out=%s"

mnemonic

String; default is "GenProtoDescriptorSet"

output_files

String; default is "single"

progress_message

String; default is "Generating Descriptor Set proto_library %{label}"

proto_compiler

Label; default is None