Skip to content

Latest commit

 

History

History
 
 

protobuf

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 

proto_repositories

The proto_repositories macro loads the required external workspaces for a particular language. This rule is used internally by the language-specific *_proto_repositories rules, but can be invoked directly to load the minimal set of deps to use proto_compile.

Name Type Description Default
excludes string_list An optional list of labels to exclude when loading. []
overrides string_dict A list of override specs to merge when loading. {}
verbose bool An optional flag to be more verbose. False

proto_language

The proto_language rule encapsulates metadata about how to invoke the protoc tool for a particular protocol buffer plugin. You can use your own proto_language definitions in conjunction with the proto_compile rule to generate custom protoc outputs. Here's a hypothetical example to generate php outputs:

load("@org_pubref_rules_protobuf//protobuf:rules.bzl", "proto_language", "proto_compile")

proto_language(
   name = "php",
   # The plugin binary
   pb_plugin = "//external/protoc-gen-php",
   # File extensions that the plugin generates
   pb_file_extensions = ["_pb.php"],
   # Files that the plugin generates
   pb_outputs = [
    "{basename}_queries_pb.php",
    "new_dir/pkg_level_definitions_pb.php",
    "new_dir/{basename}_query_handlers_pb.php"
   ],
   # Optional default plugin options
   pb_options = [],
   # Optional default imports
   pb_imports = [],
)

proto_compile(
   name = "php_protos",
   # Pass in a list of proto_language rules
   langs = [":php"],
)

The same pattern applies to the *_proto_library rules, meaning you can pass in alternative/custom language specifications to these rules to generate custom library outputs.

Name Type Description Default
name string The name of the rule (required) ""
output_to_workspace bool By by default, output are generated in a subdirectory of bazel-genfiles. This is optional flag to output to the workspace (see explanation below). False
output_to_jar bool Optional flag to output to a jar file (used by java). False
output_to_library bool Optional flag to output to a library js file (used by js). False
output_file_style string Optional naming convention used by generated files. Available options are capitalize and pascal. ""
supports_pb bool Optional flag to enable standard protobuf generation. True
pb_file_extensions string_list List of file extensions generated by the plugin. []
pb_outputs string_list Optional list of files generated by the plugin. Use {basename} for the root proto's name. This may be used in place of pb_file_extensions for greater flexibility. []
pb_options string_list Optional list of plugin options. []
pb_imports string_list Optional list of imports for this language. []
pb_inputs label_list Optional list of labels that bazel should ensure are built prior to exection of proto_compile. []
pb_plugin label (executable) Reference to the plugin binary. []
pb_compile_deps label_list Optional list of dependencies for a library rule. Currently only supported for java-based rules. []
pb_runtime_deps label_list Optional list of dependencies for a binary rule. Currently only supported for java-based rules. []
pb_plugin_implements_grpc bool Optional flag if the plugin generates both grpc and non-grpc related outputs. []
supports_grpc bool Optional flag to enable grpc-related protobuf generation. True
grpc_file_extensions string_list List of file extensions generated by the plugin. []
grpc_options string_list Optional list of plugin options. []
grpc_imports string_list Optional list of imports for this language. []
grpc_inputs label_list Optional list of labels that bazel should ensure are built prior to exection of proto_compile. []
grpc_plugin label (executable) Reference to the plugin binary. []
grpc_compile_deps label_list Optional list of dependencies for a library rule. Currently only supported for java-based rules. []
grpc_runtime_deps label_list Optional list of dependencies for a binary rule. Currently only supported for java-based rules. []
pb_plugin_implements_grpc bool Optional flag if the plugin generates both grpc and non-grpc related outputs. []
go_prefix label providing go_prefix Optional label to the go_prefix rule (go specific). ""
importmap string_dict Optional mappings (go specific). {}

proto_compile

The proto_compile rule invokes the protoc tool with a list of proto_language specifications. Here's an example that generates protoc outputs for multiple languages simultaneously:

load("@org_pubref_rules_protobuf//protobuf:rules.bzl", "proto_compile")

proto_compile(
   name = "proto_all",
   langs = [
     "@org_pubref_rules_protobuf//python",
     "@org_pubref_rules_protobuf//java",
     "@org_pubref_rules_protobuf//java:nano",
     "@org_pubref_rules_protobuf//cpp",
     "@org_pubref_rules_protobuf//objc",
     "@org_pubref_rules_protobuf//closure",
     "@org_pubref_rules_protobuf//node",
     "@org_pubref_rules_protobuf//go",
   ],
   with_grpc = True,
)
Name Type Description Default
name string The name of the rule (required) ""
langs label_list having provider proto_language Required list of labels that refer to proto_language rules. []
protos label_list of file type .proto Required list of protobuf source files. Must not be empty. []
deps label_list having provider proto_compile_result Optional list of *_proto_library that the calling rule is dependent upon. []
imports string_list Optional paths to be passed as -I arguments to the protoc tool. []
pb_options string_list Optional options to be to the pb plugin. []
grpc_options string_list Optional options to be to the grpc plugin. []
inputs label_list Optional labels that should be built by bazel and available prior to execution of the rule. []
importmap string_dict (golang specific) Optional mappings for the protoc-gen-go plugin. {}
root string An optional path that shifts the directory scope of the computed execution root ""
protoc executable label Optional override to the default protoc binary tool. //external:protoc
args string_list Optional extra arguments for the protoc command, such as --include_source_info. []
output_to_workspace boolean Optional flag. Under normal operation, generated code is placed in the bazel sandbox and does not need to be checked in into version control. However, your requirements may be such that is necessary to check these generated files in. Setting this flag to True will emit generated *.pb.* files into in your workspace alongside the *.proto source files. Please make sure you're sure you want to do this as it has the potential for unwanted overwrite of source files. False

LANG_proto_library

The proto_library family of rules build compiled library outputs for a particular language. They share a common set of attributes.

The attributes protoc, protos, proto_deps, imports, output_to_workspace, verbose, with_grpc are included in all *_proto_library rules, as described above.

Name Type Description Default
name string The name of the library rule (required). The implicit output target %{name}.pb refers to the corresponding proto_compile rule. ""
srcs label_list of file type specific to library rule Additional source files passed to the implementing library rule (for example, cc_library) []
deps label_list having provider specific to library rule Additional dependencies passed to the implementing library rule (for example, cc_library []
**kwargs dict Additional extra arguments will be passed directly to the library rule implementation (for example, cc_library {}