Thanks to visit codestin.com
Credit goes to github.com

Skip to content

nelhage/rules_protobuf

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

87 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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
gRPC gateway grpc_gateway_proto_compile grpc_gateway_proto_library yes
  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.4",
)

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


About

Bazel rules for building protocol buffers (java, c++, go)

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Python 99.7%
  • Makefile 0.3%