aboutsummaryrefslogtreecommitdiffhomepage
path: root/bazel
diff options
context:
space:
mode:
authorGravatar Mark D. Roth <roth@google.com>2017-03-17 11:04:09 -0700
committerGravatar Mark D. Roth <roth@google.com>2017-03-17 11:04:09 -0700
commitf3792b2024961430878ed770db07bf94526729c6 (patch)
tree4092d6575a49d9b0f6daf86adab47b2c2c70ee54 /bazel
parent1dcd922ce65a00892e0815262b8446af06ad882b (diff)
parent11c57e89e5b6f869dab744aeb2b0a7dc5be4ca5e (diff)
Merge remote-tracking branch 'upstream/master' into remove_initial_connect_string
Diffstat (limited to 'bazel')
-rw-r--r--bazel/cc_grpc_library.bzl26
-rw-r--r--bazel/generate_cc.bzl17
-rw-r--r--bazel/grpc_build_system.bzl5
3 files changed, 43 insertions, 5 deletions
diff --git a/bazel/cc_grpc_library.bzl b/bazel/cc_grpc_library.bzl
index 9020eacb74..ab1add476e 100644
--- a/bazel/cc_grpc_library.bzl
+++ b/bazel/cc_grpc_library.bzl
@@ -2,7 +2,7 @@
load("//:bazel/generate_cc.bzl", "generate_cc")
-def cc_grpc_library(name, srcs, deps, proto_only, **kwargs):
+def cc_grpc_library(name, srcs, deps, proto_only, well_known_protos, use_external = False, **kwargs):
"""Generates C++ grpc classes from a .proto file.
Assumes the generated classes will be used in cc_api_version = 2.
@@ -12,6 +12,11 @@ def cc_grpc_library(name, srcs, deps, proto_only, **kwargs):
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.
+ well_known_protos: The target from protobuf library that exports well
+ known protos. Currently it will only work if the value is
+ "@submodule_protobuf//:well_known_protos"
+ use_external: When True the grpc deps are prefixed with //external. This
+ allows grpc to be used as a dependency in other bazel projects.
**kwargs: rest of arguments, e.g., compatible_with and visibility.
"""
if len(srcs) > 1:
@@ -33,22 +38,37 @@ def cc_grpc_library(name, srcs, deps, proto_only, **kwargs):
generate_cc(
name = codegen_target,
srcs = [proto_target],
+ well_known_protos = well_known_protos,
**kwargs
)
if not proto_only:
+ if use_external:
+ # when this file is used by non-grpc projects
+ plugin = "//external:grpc_cpp_plugin"
+ else:
+ plugin = "//:grpc_cpp_plugin"
+
generate_cc(
name = codegen_grpc_target,
srcs = [proto_target],
- plugin = "//:grpc_cpp_plugin",
+ plugin = plugin,
+ well_known_protos = well_known_protos,
**kwargs
)
+ if use_external:
+ # when this file is used by non-grpc projects
+ grpc_deps = ["//external:grpc++", "//external:grpc++_codegen_proto",
+ "//external:protobuf"]
+ else:
+ grpc_deps = ["//:grpc++", "//:grpc++_codegen_proto", "//external:protobuf"]
+
native.cc_library(
name = name,
srcs = [":" + codegen_grpc_target, ":" + codegen_target],
hdrs = [":" + codegen_grpc_target, ":" + codegen_target],
- deps = deps + ["//:grpc++", "//:grpc++_codegen_proto", "//external:protobuf"],
+ deps = deps + grpc_deps,
**kwargs
)
else:
diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl
index d49cbe8d72..f3961f0a41 100644
--- a/bazel/generate_cc.bzl
+++ b/bazel/generate_cc.bzl
@@ -31,8 +31,20 @@ def generate_cc_impl(ctx):
arguments += ["-I{0}={0}".format(include.path) for include in includes]
arguments += [proto.path for proto in protos]
+ # create a list of well known proto files if the argument is non-None
+ well_known_proto_files = []
+ if ctx.attr.well_known_protos:
+ f = ctx.attr.well_known_protos.files.to_list()[0].dirname
+ if f != "external/submodule_protobuf/src/google/protobuf":
+ print("Error: Only @submodule_protobuf//:well_known_protos is supported")
+ else:
+ # f points to "external/submodule_protobuf/src/google/protobuf"
+ # add -I argument to protoc so it knows where to look for the proto files.
+ arguments += ["-I{0}".format(f + "/../..")]
+ well_known_proto_files = [f for f in ctx.attr.well_known_protos.files]
+
ctx.action(
- inputs = protos + includes + additional_input,
+ inputs = protos + includes + additional_input + well_known_proto_files,
outputs = out_files,
executable = ctx.executable._protoc,
arguments = arguments,
@@ -56,6 +68,9 @@ generate_cc = rule(
mandatory = False,
allow_empty = True,
),
+ "well_known_protos" : attr.label(
+ mandatory = False,
+ ),
"_protoc": attr.label(
default = Label("//external:protocol_compiler"),
executable = True,
diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl
index daf8b78527..8b524bd0e5 100644
--- a/bazel/grpc_build_system.bzl
+++ b/bazel/grpc_build_system.bzl
@@ -58,11 +58,14 @@ def grpc_proto_plugin(name, srcs = [], deps = []):
load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library")
-def grpc_proto_library(name, srcs = [], deps = [], well_known_deps = [], has_services = True):
+def grpc_proto_library(name, srcs = [], deps = [], well_known_protos = None,
+ has_services = True, use_external = False):
cc_grpc_library(
name = name,
srcs = srcs,
deps = deps,
+ well_known_protos = well_known_protos,
proto_only = not has_services,
+ use_external = use_external,
)