aboutsummaryrefslogtreecommitdiffhomepage
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
parent4dc64310bb4f4521fc025f1cb53bab309128c086 (diff)
Adding shim for generating C++ protos.
-rw-r--r--BUILD2
-rw-r--r--WORKSPACE12
-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
-rw-r--r--src/proto/grpc/testing/BUILD69
-rw-r--r--src/proto/grpc/testing/duplicate/BUILD10
8 files changed, 154 insertions, 31 deletions
diff --git a/BUILD b/BUILD
index acf9acd3be..ec750bcef4 100644
--- a/BUILD
+++ b/BUILD
@@ -35,7 +35,7 @@ exports_files(["LICENSE"])
package(default_visibility = ["//visibility:public"])
-load("//:bazel/grpc_build_system.bzl", "grpc_cc_library", "grpc_proto_plugin")
+load("//bazel:grpc_build_system.bzl", "grpc_cc_library", "grpc_proto_plugin")
g_stands_for = "good"
diff --git a/WORKSPACE b/WORKSPACE
index 1499a0a52f..98c3afa5bd 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -4,16 +4,6 @@ bind(
)
bind(
- name = "grpc_cpp_plugin",
- actual = "//:grpc_cpp_plugin",
-)
-
-bind(
- name = "grpc++",
- actual = "//:grpc++",
-)
-
-bind(
name = "libssl",
actual = "@submodule_boringssl//:ssl",
)
@@ -34,7 +24,7 @@ bind(
)
bind(
- name = "protobuf_compiler",
+ name = "protocol_compiler",
actual = "@submodule_protobuf//:protoc",
)
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,
+ )
+
diff --git a/src/proto/grpc/testing/BUILD b/src/proto/grpc/testing/BUILD
new file mode 100644
index 0000000000..2c91006064
--- /dev/null
+++ b/src/proto/grpc/testing/BUILD
@@ -0,0 +1,69 @@
+
+package(default_visibility = ["//visibility:public"])
+
+load("//bazel:grpc_build_system.bzl", "grpc_proto_library")
+
+grpc_proto_library(
+ name = "compiler_test_proto",
+ srcs = ["compiler_test.proto"],
+)
+
+grpc_proto_library(
+ name = "control_proto",
+ srcs = ["control.proto"],
+ deps = ["payloads_proto", "stats_proto"],
+)
+
+#grpc_proto_library(
+# name = "echo_duplicate_proto",
+# srcs = ["duplicate/echo_duplicate.proto"],
+# deps = ["echo_messages_proto"],
+#)
+
+grpc_proto_library(
+ name = "echo_messages_proto",
+ srcs = ["echo_messages.proto"],
+)
+
+grpc_proto_library(
+ name = "echo_proto",
+ srcs = ["echo.proto"],
+ deps = ["echo_messages_proto"],
+)
+
+grpc_proto_library(
+ name = "empty_proto",
+ srcs = ["empty.proto"],
+)
+
+grpc_proto_library(
+ name = "messages_proto",
+ srcs = ["messages.proto"],
+)
+
+grpc_proto_library(
+ name = "metrics_proto",
+ srcs = ["metrics.proto"],
+)
+
+grpc_proto_library(
+ name = "payloads_proto",
+ srcs = ["payloads.proto"],
+)
+
+grpc_proto_library(
+ name = "services_proto",
+ srcs = ["services.proto"],
+ deps = ["control_proto", "messages_proto"],
+)
+
+grpc_proto_library(
+ name = "stats_proto",
+ srcs = ["stats.proto"],
+)
+
+grpc_proto_library(
+ name = "test_proto",
+ srcs = ["test.proto"],
+ deps = ["empty_proto", "messages_proto"],
+)
diff --git a/src/proto/grpc/testing/duplicate/BUILD b/src/proto/grpc/testing/duplicate/BUILD
new file mode 100644
index 0000000000..255e699bec
--- /dev/null
+++ b/src/proto/grpc/testing/duplicate/BUILD
@@ -0,0 +1,10 @@
+
+package(default_visibility = ["//visibility:public"])
+
+load("//bazel:grpc_build_system.bzl", "grpc_proto_library")
+
+grpc_proto_library(
+ name = "echo_duplicate_proto",
+ srcs = ["echo_duplicate.proto"],
+ deps = ["//src/proto/grpc/testing:echo_messages_proto"],
+)