From 4dc64310bb4f4521fc025f1cb53bab309128c086 Mon Sep 17 00:00:00 2001 From: "Nicolas \"Pixel\" Noble" Date: Thu, 20 Oct 2016 23:07:37 +0200 Subject: Adding cc_grpc_library. --- bazel/cc_grpc_library.bzl | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 bazel/cc_grpc_library.bzl (limited to 'bazel/cc_grpc_library.bzl') 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 + ) -- cgit v1.2.3