diff options
author | makdharma <makdharma@users.noreply.github.com> | 2017-03-06 12:30:35 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-06 12:30:35 -0800 |
commit | 437cc199abff8eb69a4212d42c89dbb7703eb17d (patch) | |
tree | 411acdc57eb88a2b53a5fe3f3d483b101e65c453 | |
parent | 74f7da26945b7aa4a7108a5b44a735308da202b4 (diff) | |
parent | 1e66fcf159dbcb327e2ca6213458eca1ed1fb06c (diff) |
Merge pull request #9968 from makdharma/grpc_bazel
Use grpc_build_system.bzl in other projects
-rw-r--r-- | bazel/cc_grpc_library.bzl | 21 | ||||
-rw-r--r-- | bazel/grpc_build_system.bzl | 3 |
2 files changed, 20 insertions, 4 deletions
diff --git a/bazel/cc_grpc_library.bzl b/bazel/cc_grpc_library.bzl index 9020eacb74..b9d7eb5902 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, 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,8 @@ 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. + 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: @@ -37,18 +39,31 @@ def cc_grpc_library(name, srcs, deps, proto_only, **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, **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/grpc_build_system.bzl b/bazel/grpc_build_system.bzl index daf8b78527..855d2d7b72 100644 --- a/bazel/grpc_build_system.bzl +++ b/bazel/grpc_build_system.bzl @@ -58,11 +58,12 @@ 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_deps = [], has_services = True, use_external = False): cc_grpc_library( name = name, srcs = srcs, deps = deps, proto_only = not has_services, + use_external = use_external, ) |