rules_protobuf
Bazel skylark rules for generating protocol buffers in (java, golang)
on (linux, macosx).
 |
 |
 |
Bazel |
rules_protobuf |
gRPC |
- Support for generation of protobuf classes.
- Support for generation + compilation of outputs with protobuf dependencies.
- Support for compilation, with gRPC support.
Requirements
These are build rules for bazel. If you have not already
installed bazel
on your workstation, follow the
bazel instructions. Here's one way (osx):
$ curl -O -J -L https://github.com/bazelbuild/bazel/releases/download/0.3.1/bazel-0.3.1-installer-darwin-x86_64.sh
$ shasum -a256 bazel-0.3.1-installer-darwin-x86_64.sh
8d035de9c137bde4f709e3666271af01d1ef6bed6921e1a676d6a6dc0186395c bazel-0.3.1-installer-darwin-x86_64.sh
$ chmod +x bazel-0.3.1-installer-darwin-x86_64.sh
$ ./bazel-0.3.1-installer-darwin-x86_64.sh
$ bazel version
Build label: 0.3.1
...
Installation
Require these rules your WORKSPACE
and trigger loading of external
dependencies (including the protoc
prebuilt binaries for linux or
osx) and other required dependencies specific for a particular
language output. You must specify which language(s) you'd like
support for:
git_repository(
name = "org_pubref_rules_protobuf",
remote = "https://github.com/pubref/rules_protobuf",
tag = "0.2.0",
)
load("@org_pubref_rules_protobuf//bzl:rules.bzl", "rules_protobuf")
# Specify language modules to load
rules_protobuf(
with_java = True,
with_go = True,
)
For fine-grained control over the dependencies that rules_protobuf
loads, call the rules_protobuf
macro and one of the language
specific modules with omit_{dependency}
arguments. For example:
load(
"@org_pubref_rules_protobuf//bzl:rules.bzl",
"rules_protobuf",
"rules_protobuf_java",
)
# Make the protoc binary available
rules_protobuf()
# Make the protoc-gen-grpc-java binary and all dependent jars available,
# but don't try to load guava. Guava is still required, so this assumes you have a
# another workspace rule that provides com_google_guava_guava via another mechanism,
# possibly a local or alternate version.
rules_protobuf_java(
omit_com_google_guava_guava = True,
)
Please refer to the
bzl/{language}.bzl
file for the set of external dependencies that will be hoisted into
your project.
Examples
Demonstrative commands for running the helloworld client/server example (adapted
from
https://github.com/grpc/grpc-java/blob/master/examples/src/main/proto/helloworld.proto
)
are found in the examples/helloworld/Makefile
.
# In terminal 1:
$ (cd examples/helloworld && make netty_server)
# In terminal 2:
$ (cd examples/helloworld && make netty_client)
Contributing
Contributions welcome; please create Issues or GitHub pull requests.
Credits