rules_protobuf

module
v0.3.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2016 License: Apache-2.0

README

rules_protobuf (αlpha) Build Status


Bazel skylark rules for building protocol buffers on (macosx, linux).

Bazel Protobuf gRPC
Bazel rules_protobuf gRPC

Language Compile (1) Build (2) gRPC (3)
C++ cc_proto_compile cc_proto_library yes
C#
Go go_proto_compile go_proto_library yes
Java java_proto_compile java_proto_library yes
JavaNano android_proto_compile android_proto_library yes
Javascript
Objective-C
Python
Ruby
  1. Support for generation of protobuf classes via the protoc tool.
  2. Support for generation + compilation of outputs with protobuf dependencies.
  3. 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):

Note about protoc and related tools: bazel and rules_protobuf will download or build-from-source all required dependencies, including the protoc tool and required plugins. If you do already have these tools installed, bazel will not use them.

$ 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
...

Note about golang: this project uses rules-go for go_library, go_binary, and go_test.

Quick Start

Require these rules your WORKSPACE:

git_repository(
  name = "org_pubref_rules_protobuf",
  remote = "https://github.com/pubref/rules_protobuf",
  tag = "v0.3.2",
)

Trigger loading of external dependencies. Specify the language(s) you'd like support for.

load("@org_pubref_rules_protobuf//bzl:rules.bzl", "protobuf_dependencies")
protobuf_dependencies(
   with_go = True,
   with_java = True,
   with_cpp = True,
)

Note: refer to the bzl/repositories.bzl file for the set of external dependencies that will be loaded into your project.

Build a java-based gRPC library:

load("@org_pubref_rules_protobuf//bzl:java/rules.bzl", "java_proto_library")

java_proto_library(
  name = "protolib",
  srcs = ["my.proto"],
  with_grpc = True,
)

Examples

To run the examples & tests in this repository, clone it to your workstation.

# Clone this repo
$ git clone https://github.com/pubref/rules_protobuf

# Go to examples/helloworld directory
$ cd rules_protobuf/examples/helloworld

# Run all tests
$ bazel test ...

# Build a server
$ bazel build cpp/server

# Run a server from the command-line
$ $(bazel info bazel-bin)/examples/helloworld/cpp/server

# Run a client
$ bazel run go/client
$ bazel run cpp/client
$ bazel run java/org/pubref/rules_closure/examples/helloworld/client:netty

Overriding Dependencies

To load alternate versions of dependencies, pass in a dict having the same overall structure of the repositories.bzl file. Entries having a matching key will override those found in the file. For example, to load a different version of https://github.com/golang/protobuf, provide a different commit ID:

load("@org_pubref_rules_protobuf//bzl:rules.bzl", "protobuf_dependencies")
protobuf_dependencies(
   with_go = True,
   overrides = {
     "com_github_golang_protobuf": {
       "commit": "2c1988e8c18d14b142c0b472624f71647cf39adb", # Aug 8, 2016
     }
   },
)

Contributing

Contributions welcome; please create Issues or GitHub pull requests.

Credits


Directories

Path Synopsis
examples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL