diff options
author | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2016-10-20 23:07:37 +0200 |
---|---|---|
committer | Nicolas "Pixel" Noble <pixel@nobis-crew.org> | 2016-10-20 23:07:37 +0200 |
commit | 4dc64310bb4f4521fc025f1cb53bab309128c086 (patch) | |
tree | 2b286ac946923976ca5493fbe44a9c9b914bd854 /bazel/cc_grpc_library.bzl | |
parent | d58c375d764c65d699cfd0e4536c3e8f631e8221 (diff) |
Adding cc_grpc_library.
Diffstat (limited to 'bazel/cc_grpc_library.bzl')
-rw-r--r-- | bazel/cc_grpc_library.bzl | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/bazel/cc_grpc_library.bzl b/bazel/cc_grpc_library.bzl new file mode 100644 index 0000000000..8e6f9ebb21 --- /dev/null +++ b/bazel/cc_grpc_library.bzl @@ -0,0 +1,35 @@ +"""Generates and compiles C++ grpc stubs from proto_library rules.""" + +load("//:bazel/generate_cc.bzl", "generate_cc") + +def cc_grpc_library(name, srcs, deps, **kwargs): + """Generates C++ grpc classes from a .proto file. + + Assumes the generated classes will be used in cc_api_version = 2. + + Arguments: + name: name of rule. + srcs: a single proto_library, which wraps the .proto files with services. + deps: a list of C++ proto_library (or cc_proto_library) which provides + the compiled code of any message that the services depend on. + **kwargs: rest of arguments, e.g., compatible_with and visibility. + """ + if len(srcs) > 1: + fail("Only one srcs value supported", "srcs") + + codegen_target = "_" + name + "_codegen" + + generate_cc( + name = codegen_target, + srcs = srcs, + plugin = "//external:grpc_cpp_plugin", + **kwargs + ) + + native.cc_library( + name = name, + srcs = [":" + codegen_target], + hdrs = [":" + codegen_target], + deps = deps + ["//external:grpc++"], + **kwargs + ) |