aboutsummaryrefslogtreecommitdiffhomepage
path: root/bazel
diff options
context:
space:
mode:
authorGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-10-21 01:54:32 +0200
committerGravatar Nicolas "Pixel" Noble <pixel@nobis-crew.org>2016-10-21 01:54:32 +0200
commit799bd5efb70b0abe076353dedd6a1983f1b01951 (patch)
treee2d27deaff339c6abbad0df423f68387af72cb30 /bazel
parent4dc64310bb4f4521fc025f1cb53bab309128c086 (diff)
Adding shim for generating C++ protos.
Diffstat (limited to 'bazel')
-rw-r--r--bazel/BUILD9
-rw-r--r--bazel/cc_grpc_library.bzl45
-rw-r--r--bazel/generate_cc.bzl27
-rw-r--r--bazel/grpc_build_system.bzl11
4 files changed, 73 insertions, 19 deletions
diff --git a/bazel/BUILD b/bazel/BUILD
new file mode 100644
index 0000000000..940a379404
--- /dev/null
+++ b/bazel/BUILD
@@ -0,0 +1,9 @@
+package(default_visibility = ["//:__subpackages__"])
+
+load(":cc_grpc_library.bzl", "cc_grpc_library")
+
+cc_grpc_library(
+ name = "well_known_protos",
+ srcs = "@submodule_protobuf//:well_known_protos",
+ proto_only = True,
+)
diff --git a/bazel/cc_grpc_library.bzl b/bazel/cc_grpc_library.bzl
index 8e6f9ebb21..e1dd27b0c3 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, **kwargs):
+def cc_grpc_library(name, srcs, deps, proto_only, **kwargs):
"""Generates C++ grpc classes from a .proto file.
Assumes the generated classes will be used in cc_api_version = 2.
@@ -17,19 +17,46 @@ def cc_grpc_library(name, srcs, deps, **kwargs):
if len(srcs) > 1:
fail("Only one srcs value supported", "srcs")
+ proto_target = "_" + name + "_only"
codegen_target = "_" + name + "_codegen"
+ codegen_grpc_target = "_" + name + "_grpc_codegen"
+ proto_deps = ["_" + dep + "_only" for dep in deps if dep.find(':') == -1]
+ proto_deps += [dep.split(':')[0] + ':' + "_" + dep.split(':')[1] + "_only" for dep in deps if dep.find(':') != -1]
- generate_cc(
- name = codegen_target,
+ native.proto_library(
+ name = proto_target,
srcs = srcs,
- plugin = "//external:grpc_cpp_plugin",
+ deps = proto_deps,
**kwargs
)
- native.cc_library(
- name = name,
- srcs = [":" + codegen_target],
- hdrs = [":" + codegen_target],
- deps = deps + ["//external:grpc++"],
+ generate_cc(
+ name = codegen_target,
+ srcs = [proto_target],
**kwargs
)
+
+ if not proto_only:
+ generate_cc(
+ name = codegen_grpc_target,
+ srcs = [proto_target],
+ plugin = "//:grpc_cpp_plugin",
+ **kwargs
+ )
+
+ if not proto_only:
+ 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"],
+ **kwargs
+ )
+ else:
+ native.cc_library(
+ name = name,
+ srcs = [":" + codegen_target],
+ hdrs = [":" + codegen_target],
+ deps = deps + ["//external:protobuf"],
+ **kwargs
+ )
diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl
index a021742798..3665733681 100644
--- a/bazel/generate_cc.bzl
+++ b/bazel/generate_cc.bzl
@@ -5,20 +5,27 @@ directly.
"""
def generate_cc_impl(ctx):
- """Implementation of the gengrpccc rule."""
+ """Implementation of the generate_cc rule."""
protos = [f for src in ctx.attr.srcs for f in src.proto.direct_sources]
includes = [f for src in ctx.attr.srcs for f in src.proto.transitive_imports]
outs = []
- outs += [proto.basename[:-len(".proto")] + ".grpc.pb.h" for proto in protos]
- outs += [proto.basename[:-len(".proto")] + ".grpc.pb.cc" for proto in protos]
+ if ctx.executable.plugin:
+ outs += [proto.basename[:-len(".proto")] + ".grpc.pb.h" for proto in protos]
+ outs += [proto.basename[:-len(".proto")] + ".grpc.pb.cc" for proto in protos]
+ else:
+ outs += [proto.basename[:-len(".proto")] + ".pb.h" for proto in protos]
+ outs += [proto.basename[:-len(".proto")] + ".pb.cc" for proto in protos]
out_files = [ctx.new_file(out) for out in outs]
# The following should be replaced with ctx.configuration.buildout
# whenever this is added to Skylark.
dir_out = out_files[0].dirname[:-len(protos[0].dirname)]
arguments = []
- arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path]
- arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags) + ":" + dir_out]
+ if ctx.executable.plugin:
+ arguments += ["--plugin=protoc-gen-PLUGIN=" + ctx.executable.plugin.path]
+ arguments += ["--PLUGIN_out=" + ",".join(ctx.attr.flags) + ":" + dir_out]
+ else:
+ arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out]
arguments += ["-I{0}={0}".format(include.path) for include in includes]
arguments += [proto.path for proto in protos]
@@ -41,16 +48,16 @@ generate_cc = rule(
"plugin": attr.label(
executable = True,
providers = ["files_to_run"],
- cfg = HOST_CFG,
+ cfg = "host",
),
"flags": attr.string_list(
- mandatory = True,
- allow_empty = False
+ mandatory = False,
+ allow_empty = True,
),
"_protoc": attr.label(
- default = Label("//extern:protocol_compiler"),
+ default = Label("//external:protocol_compiler"),
executable = True,
- cfg = HOST_CFG,
+ cfg = "host",
),
},
# We generate .h files, so we need to output to genfiles.
diff --git a/bazel/grpc_build_system.bzl b/bazel/grpc_build_system.bzl
index f2dde951fd..70a7001d75 100644
--- a/bazel/grpc_build_system.bzl
+++ b/bazel/grpc_build_system.bzl
@@ -55,3 +55,14 @@ def grpc_proto_plugin(name, srcs = [], deps = []):
srcs = srcs,
deps = deps,
)
+
+load("//:bazel/cc_grpc_library.bzl", "cc_grpc_library")
+
+def grpc_proto_library(name, srcs = [], deps = [], well_known_deps = [], has_services = True):
+ cc_grpc_library(
+ name = name,
+ srcs = srcs,
+ deps = deps,
+ proto_only = not has_services,
+ )
+