Rules
- cc_proto_library
- java_lite_proto_library
- java_proto_library
- proto_library
- py_proto_library
- proto_lang_toolchain
- proto_toolchain
cc_proto_library
View rule sourcecc_proto_library(name, deps, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
cc_proto_library generates C++ code from .proto files.
deps must point to proto_library
 rules.
Example:
cc_library(
    name = "lib",
    deps = [":foo_cc_proto"],
)
cc_proto_library(
    name = "foo_cc_proto",
    deps = [":foo_proto"],
)
proto_library(
    name = "foo_proto",
)
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| deps | List of labels; default is  proto_libraryrules to generate C++ code for. | 
java_lite_proto_library
View rule sourcejava_lite_proto_library(name, deps, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
java_lite_proto_library generates Java code from .proto files.
deps must point to proto_library
 rules.
Example:
java_library(
    name = "lib",
    runtime_deps = [":foo"],
)
java_lite_proto_library(
    name = "foo",
    deps = [":bar"],
)
proto_library(
    name = "bar",
)
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| deps | List of labels; default is  proto_libraryrules to generate Java code for. | 
java_proto_library
View rule sourcejava_proto_library(name, deps, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, licenses, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
java_proto_library generates Java code from .proto files.
deps must point to proto_library
 rules.
Example:
java_library(
    name = "lib",
    runtime_deps = [":foo_java_proto"],
)
java_proto_library(
    name = "foo_java_proto",
    deps = [":foo_proto"],
)
proto_library(
    name = "foo_proto",
)
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| deps | List of labels; default is  proto_libraryrules to generate Java code for. | 
proto_library
View rule sourceproto_library(name, deps, srcs, data, allow_exports, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, exports, extension_declarations, features, import_prefix, licenses, option_deps, package_metadata, restricted_to, strip_import_prefix, tags, target_compatible_with, testonly, toolchains, visibility)
Use proto_library to define libraries of protocol buffers which
may be used from multiple languages. A proto_library may be listed
in the deps clause of supported rules, such as
java_proto_library.
When compiled on the command-line, a proto_library creates a file
named foo-descriptor-set.proto.bin, which is the descriptor set for
the messages the rule srcs. The file is a serialized
FileDescriptorSet, which is described in
https://developers.google.com/protocol-buffers/docs/techniques#self-description.
It only contains information about the .proto files directly
mentioned by a proto_library rule; the collection of transitive
descriptor sets is available through the
[ProtoInfo].transitive_descriptor_sets Starlark provider.
See documentation in proto_info.bzl.
Recommended code organization:
- One proto_libraryrule per.protofile.
- A file named foo.protowill be in a rule namedfoo_proto, which is located in the same package.
- A [language]_proto_librarythat wraps aproto_librarynamedfoo_protoshould be calledfoo_[language]_proto, and be located in the same package.
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| deps | List of labels; default is  proto_libraryrules that the target depends upon.
Aproto_librarymay only depend on otherproto_librarytargets. It may not depend on language-specific libraries. | 
| srcs | List of labels; default is  .protoand.protodevelfiles that are
processed to create the target. This is usually a non empty list. One usecase
wheresrcscan be empty is an alias-library. This is a
proto_library rule having one or more other proto_library indeps.
This pattern can be used to e.g. export a public api under a persistent name. | 
| allow_exports | Label; default is  | 
| exports | List of labels; default is  | 
| extension_declarations | List of labels; default is  | 
| import_prefix | String; default is  When set, the .proto source files in the  The prefix in the  | 
| option_deps | List of labels; default is  proto_libraryrules that the target depends upon for options only.
Aproto_librarymay only depend on otherproto_librarytargets. It may not depend on language-specific libraries. | 
| strip_import_prefix | String; default is  When set, .proto source files in the  If it's a relative path (not starting with a slash), it's taken as a package-relative one. If it's an absolute one, it's understood as a repository-relative path. The prefix in the  | 
py_proto_library
View rule sourcepy_proto_library(name, deps, aspect_hints, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, package_metadata, restricted_to, tags, target_compatible_with, testonly, toolchains, visibility)
Arguments
| Attributes | |
|---|---|
| name | Name; required A unique name for this target. | 
| deps | List of labels; default is  | 
proto_lang_toolchain
View rule sourceproto_lang_toolchain(name, allowlist_different_package, aspect_hints, blacklisted_protos, command_line, compatible_with, denylisted_protos, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, mnemonic, output_files, package_metadata, 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  | 
| blacklisted_protos | List of labels; default is  denylisted_protos. Will be removed in a future release. | 
| command_line | String; requiredThis 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) 
 | 
| denylisted_protos | List of labels; default is  srcsattribute ofdenylisted_protos.
This is used for .proto files that are already linked into proto runtimes, such asany.proto. | 
| mnemonic | String; default is  | 
| output_files | String; default is  $(OUT)incommand_lineis 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  --plugin=protoc-gen-PLUGIN=<executable>. | 
| plugin_format_flag | String; default is  --plugin=protoc-gen-PLUGIN=<executable>. | 
| progress_message | String; default is  | 
| protoc_minimal_do_not_use | Label; default is  | 
| runtime | Label; default is  | 
| toolchain_type | Label; default is  | 
proto_toolchain
View rule sourceproto_toolchain(name, aspect_hints, command_line, compatible_with, deprecation, exec_compatible_with, exec_group_compatible_with, exec_properties, features, mnemonic, output_files, package_metadata, 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  | 
| mnemonic | String; default is  | 
| output_files | String; default is  | 
| progress_message | String; default is  | 
| proto_compiler | Label; default is  |