Remove tabs
148 files changed
tree: 637b6a83070fdd77e8de4841a84ba364537a1ed0
  1. android/
  2. closure/
  3. cpp/
  4. csharp/
  5. dart/
  6. example/
  7. github.com/
  8. go/
  9. java/
  10. node/
  11. objc/
  12. php/
  13. python/
  14. ruby/
  15. rust/
  16. scala/
  17. swift/
  18. tools/
  19. .travis.yml
  20. BUILD.bazel
  21. compile.bzl
  22. deps.bzl
  23. LICENSE
  24. Makefile
  25. Makefile.examples
  26. plugin.bzl
  27. README.md
  28. WORKSPACE
README.md

rules_proto Build Status

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:

  1. Interoperate with the native proto_library rules and other proto support in the bazel ecosystem as much as possible.
  2. Provide a proto_plugin rule to support custom protoc plugins.
  3. Minimal dependency loading. Proto rules should not pull in more dependencies than they absolutely need.

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!

Usage

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.

Rules

LangRuleDescription
cppcpp_proto_compileGenerates .h,.cc protobuf artifacts
cppcpp_grpc_compileGenerates .h,.cc protobuf+gRPC artifacts
cppcpp_proto_libraryGenerates .h,.cc protobuf library
cppcpp_grpc_libraryGenerates .h,.cc protobuf+gRPC library
closureclosure_proto_compileGenerates closure *.js protobuf+gRPC files
closureclosure_proto_libraryGenerates a closure_library with compiled protobuf *.js files
nodenode_proto_compileGenerates node *.js protobuf artifacts
nodenode_grpc_compileGenerates node *.js protobuf+gRPC artifacts
nodenode_proto_libraryGenerates node *.js protobuf library
nodenode_grpc_libraryGenerates node *.js protobuf+gRPC library
javajava_proto_compileGenerates a srcjar with protobuf *.java files
javajava_grpc_compileGenerates a srcjar with protobuf+gRPC *.java files
javajava_proto_libraryGenerates a jar with compiled protobuf *.class files
javajava_grpc_libraryGenerates a jar with compiled protobuf+gRPC *.class files
scalascala_proto_compileGenerates *.scala protobuf artifacts
scalascala_grpc_compileGenerates *.scala protobuf+gRPC artifacts
scalascala_proto_libraryGenerates *.py protobuf library
scalascala_grpc_libraryGenerates *.py protobuf+gRPC library
pythonpython_proto_compileGenerates *.py protobuf artifacts
pythonpython_grpc_compileGenerates *.py protobuf+gRPC artifacts
pythonpython_proto_libraryGenerates *.py protobuf library
pythonpython_grpc_libraryGenerates *.py protobuf+gRPC library
gogo_proto_compileGenerates *.go protobuf artifacts
gogo_grpc_compileGenerates *.go protobuf+gRPC artifacts
gogo_proto_libraryGenerates *.go protobuf library
gogo_grpc_libraryGenerates *.go protobuf+gRPC library
rubyruby_proto_compileGenerates *.ruby protobuf artifacts
rubyruby_grpc_compileGenerates *.ruby protobuf+gRPC artifacts
rubyruby_proto_libraryGenerates *.rb protobuf library
rubyruby_grpc_libraryGenerates *.rb protobuf+gRPC library
objcobjc_proto_compileGenerates objc protobuf artifacts
objcobjc_grpc_compileGenerates objc protobuf+gRPC artifacts
phpphp_proto_compileGenerates php protobuf artifacts
phpphp_grpc_compileGenerates php protobuf+gRPC artifacts
rustrust_proto_compileGenerates rust protobuf artifacts
rustrust_grpc_compileGenerates rust protobuf+gRPC artifacts
rustrust_proto_libraryGenerates rust protobuf library
rustrust_grpc_libraryGenerates rust protobuf+gRPC library
dartdart_proto_compileGenerates dart protobuf artifacts
dartdart_grpc_compileGenerates dart protobuf+gRPC artifacts
dartdart_proto_libraryGenerates dart protobuf library
dartdart_grpc_libraryGenerates dart protobuf+gRPC library
grpc_webclosure_grpc_compileGenerates a closure *.js protobuf+gRPC files
grpc_webcommonjs_grpc_compileGenerates a commonjs *.js protobuf+gRPC files
grpc_webcommonjs_dts_grpc_compileGenerates a commonjs_dts *.js protobuf+gRPC files
grpc_webts_grpc_compileGenerates a commonjs *.ts protobuf+gRPC files
gogogogo_proto_compileGenerates gogo protobuf artifacts
gogogogo_grpc_compileGenerates gogo protobuf+gRPC artifacts
gogogogo_proto_libraryGenerates gogo protobuf library
gogogogo_grpc_libraryGenerates gogo protobuf+gRPC library
gogogogofast_proto_compileGenerates gogofast protobuf artifacts
gogogogofast_grpc_compileGenerates gogofast protobuf+gRPC artifacts
gogogogofast_proto_libraryGenerates gogofast protobuf library
gogogogofast_grpc_libraryGenerates gogofast protobuf+gRPC library
gogogogofaster_proto_compileGenerates gogofaster protobuf artifacts
gogogogofaster_grpc_compileGenerates gogofaster protobuf+gRPC artifacts
gogogogofaster_proto_libraryGenerates gogofaster protobuf library
gogogogofaster_grpc_libraryGenerates gogofaster protobuf+gRPC library

Code Layout

Each language {lang} has a top-level subdirectory that contains:

  1. {lang}/README.md: generated documentation for the rule(s).

  2. {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.

  3. {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.

  4. {lang}/BUILD.bazel: contains proto_plugin() declarations for the available plugins for that language.

  5. {lang}/example/{rule}/: contains a generated WORKSPACE and BUILD.bazel demonstrating standalone usage.

  6. {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.

Developing Custom Plugins

Follow the pattern seen in the multiple examples in this repository. The basic idea is:

  1. Load the plugin rule: load("@build_stack_rules_proto//:plugin.bzl", "proto_plugin").
  2. Define the rule, giving it a name, options (not mandatory), tool, and outputs.
  3. tool is a label that refers to the binary executable for the plugin itself.
  4. 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].

Contributing

Contributions welcome; please create Issues or GitHub pull requests.