Remove tabs
rules_proto Bazel skylark rules for building protocol buffers +/- gRPC :sparkles:.
These rules are the successor to https://github.com/pubref/rules_protobuf and are in a pre-release status. The primary goals are:
proto_library rules and other proto support in the bazel ecosystem as much as possible.proto_plugin rule to support custom protoc plugins.NOTE: These rules are in a pre-release state. The routeguide examples have been developed thus far with the goal of getting them to compile/build, not to ensure the routeguide client/server is actually correct. Do expect everything to compile, but not to work right!
Add rules_proto your WORKSPACE:
load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") http_archive( name = "build_stack_rules_proto", urls = ["https://github.com/stackb/rules_proto/archive/v0.9.tar.gz"], sha256 = 4329663fe6c523425ad4d3c989a8ac026b04e1acedeceb56aa4b190fa7f3973d, strip_prefix = "rules_proto-v0.9", )
Follow instructions in the language-specific README.md for additional workspace dependencies and build rule usage.
| Lang | Rule | Description |
|---|---|---|
| cpp | cpp_proto_compile | Generates .h,.cc protobuf artifacts |
| cpp | cpp_grpc_compile | Generates .h,.cc protobuf+gRPC artifacts |
| cpp | cpp_proto_library | Generates .h,.cc protobuf library |
| cpp | cpp_grpc_library | Generates .h,.cc protobuf+gRPC library |
| closure | closure_proto_compile | Generates closure *.js protobuf+gRPC files |
| closure | closure_proto_library | Generates a closure_library with compiled protobuf *.js files |
| node | node_proto_compile | Generates node *.js protobuf artifacts |
| node | node_grpc_compile | Generates node *.js protobuf+gRPC artifacts |
| node | node_proto_library | Generates node *.js protobuf library |
| node | node_grpc_library | Generates node *.js protobuf+gRPC library |
| java | java_proto_compile | Generates a srcjar with protobuf *.java files |
| java | java_grpc_compile | Generates a srcjar with protobuf+gRPC *.java files |
| java | java_proto_library | Generates a jar with compiled protobuf *.class files |
| java | java_grpc_library | Generates a jar with compiled protobuf+gRPC *.class files |
| scala | scala_proto_compile | Generates *.scala protobuf artifacts |
| scala | scala_grpc_compile | Generates *.scala protobuf+gRPC artifacts |
| scala | scala_proto_library | Generates *.py protobuf library |
| scala | scala_grpc_library | Generates *.py protobuf+gRPC library |
| python | python_proto_compile | Generates *.py protobuf artifacts |
| python | python_grpc_compile | Generates *.py protobuf+gRPC artifacts |
| python | python_proto_library | Generates *.py protobuf library |
| python | python_grpc_library | Generates *.py protobuf+gRPC library |
| go | go_proto_compile | Generates *.go protobuf artifacts |
| go | go_grpc_compile | Generates *.go protobuf+gRPC artifacts |
| go | go_proto_library | Generates *.go protobuf library |
| go | go_grpc_library | Generates *.go protobuf+gRPC library |
| ruby | ruby_proto_compile | Generates *.ruby protobuf artifacts |
| ruby | ruby_grpc_compile | Generates *.ruby protobuf+gRPC artifacts |
| ruby | ruby_proto_library | Generates *.rb protobuf library |
| ruby | ruby_grpc_library | Generates *.rb protobuf+gRPC library |
| objc | objc_proto_compile | Generates objc protobuf artifacts |
| objc | objc_grpc_compile | Generates objc protobuf+gRPC artifacts |
| php | php_proto_compile | Generates php protobuf artifacts |
| php | php_grpc_compile | Generates php protobuf+gRPC artifacts |
| rust | rust_proto_compile | Generates rust protobuf artifacts |
| rust | rust_grpc_compile | Generates rust protobuf+gRPC artifacts |
| rust | rust_proto_library | Generates rust protobuf library |
| rust | rust_grpc_library | Generates rust protobuf+gRPC library |
| dart | dart_proto_compile | Generates dart protobuf artifacts |
| dart | dart_grpc_compile | Generates dart protobuf+gRPC artifacts |
| dart | dart_proto_library | Generates dart protobuf library |
| dart | dart_grpc_library | Generates dart protobuf+gRPC library |
| grpc_web | closure_grpc_compile | Generates a closure *.js protobuf+gRPC files |
| grpc_web | commonjs_grpc_compile | Generates a commonjs *.js protobuf+gRPC files |
| grpc_web | commonjs_dts_grpc_compile | Generates a commonjs_dts *.js protobuf+gRPC files |
| grpc_web | ts_grpc_compile | Generates a commonjs *.ts protobuf+gRPC files |
| gogo | gogo_proto_compile | Generates gogo protobuf artifacts |
| gogo | gogo_grpc_compile | Generates gogo protobuf+gRPC artifacts |
| gogo | gogo_proto_library | Generates gogo protobuf library |
| gogo | gogo_grpc_library | Generates gogo protobuf+gRPC library |
| gogo | gogofast_proto_compile | Generates gogofast protobuf artifacts |
| gogo | gogofast_grpc_compile | Generates gogofast protobuf+gRPC artifacts |
| gogo | gogofast_proto_library | Generates gogofast protobuf library |
| gogo | gogofast_grpc_library | Generates gogofast protobuf+gRPC library |
| gogo | gogofaster_proto_compile | Generates gogofaster protobuf artifacts |
| gogo | gogofaster_grpc_compile | Generates gogofaster protobuf+gRPC artifacts |
| gogo | gogofaster_proto_library | Generates gogofaster protobuf library |
| gogo | gogofaster_grpc_library | Generates gogofaster protobuf+gRPC library |
Each language {lang} has a top-level subdirectory that contains:
{lang}/README.md: generated documentation for the rule(s).
{lang}/deps.bzl: contains macro functions that declare repository rule dependencies for that language. The name of the macro corresponds to the name of the build rule you'd like to use.
{lang}/{rule}.bzl: rule implementation(s) of the form {lang}_{kind}_{type}, where kind is one of proto|grpc and type is one of compile|library.
{lang}/BUILD.bazel: contains proto_plugin() declarations for the available plugins for that language.
{lang}/example/{rule}/: contains a generated WORKSPACE and BUILD.bazel demonstrating standalone usage.
{lang}/example/routeguide/: routeguide example implementation, if possible.
The root directory contains the base rule defintions:
plugin.bzl: A build rule that defines the name, tool binary, and options for a particular proto plugin.
compile.bzl: A build rule that contains the proto_compile rule. This rule calls protoc with a given list of plugins and generates output files.
Additional protoc plugins and their rules are scoped to the github repository name where the plugin resides. For example, there are 3 grpc-web implementations in this repo: `github.com/improbable-eng/grpc-web, github.com/grpc/grpc-web, and github.com/stackb/grpc.js.
Follow the pattern seen in the multiple examples in this repository. The basic idea is:
load("@build_stack_rules_proto//:plugin.bzl", "proto_plugin").name, options (not mandatory), tool, and outputs.tool is a label that refers to the binary executable for the plugin itself.outputs is a list of strings that predicts the pattern of files generated by the plugin. Specifying outputs is the only attribute that requires much mental effort. [TODO: article here with example writing a custom plugin].Contributions welcome; please create Issues or GitHub pull requests.