aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--BUILD46
-rw-r--r--WORKSPACE17
-rw-r--r--bazel/cc_grpc_library.bzl35
-rw-r--r--bazel/generate_cc.bzl59
-rw-r--r--bazel/grpc_build_system.bzl (renamed from grpc-build-system.bzl)7
5 files changed, 161 insertions, 3 deletions
diff --git a/BUILD b/BUILD
index 7230183155..acf9acd3be 100644
--- a/BUILD
+++ b/BUILD
@@ -35,7 +35,7 @@ exports_files(["LICENSE"])
package(default_visibility = ["//visibility:public"])
-load(":grpc-build-system.bzl", "grpc_cc_library")
+load("//:bazel/grpc_build_system.bzl", "grpc_cc_library", "grpc_proto_plugin")
g_stands_for = "good"
@@ -190,7 +190,7 @@ grpc_cc_library(
"src/compiler/ruby_generator_string-inl.h",
],
external_deps = [
- "protobuf_compiler",
+ "protobuf_clib",
],
language = "c++",
deps = [
@@ -198,6 +198,48 @@ grpc_cc_library(
],
)
+grpc_proto_plugin(
+ name = "grpc_cpp_plugin",
+ srcs = ["src/compiler/cpp_plugin.cc"],
+ deps = [":grpc_plugin_support"],
+)
+
+grpc_proto_plugin(
+ name = "grpc_csharp_plugin",
+ srcs = ["src/compiler/csharp_plugin.cc"],
+ deps = [":grpc_plugin_support"],
+)
+
+grpc_proto_plugin(
+ name = "grpc_node_plugin",
+ srcs = ["src/compiler/node_plugin.cc"],
+ deps = [":grpc_plugin_support"],
+)
+
+grpc_proto_plugin(
+ name = "grpc_objective_c_plugin",
+ srcs = ["src/compiler/objective_c_plugin.cc"],
+ deps = [":grpc_plugin_support"],
+)
+
+grpc_proto_plugin(
+ name = "grpc_php_plugin",
+ srcs = ["src/compiler/php_plugin.cc"],
+ deps = [":grpc_plugin_support"],
+)
+
+grpc_proto_plugin(
+ name = "grpc_python_plugin",
+ srcs = ["src/compiler/python_plugin.cc"],
+ deps = [":grpc_plugin_support"],
+)
+
+grpc_proto_plugin(
+ name = "grpc_ruby_plugin",
+ srcs = ["src/compiler/ruby_plugin.cc"],
+ deps = [":grpc_plugin_support"],
+)
+
grpc_cc_library(
name = "grpc_csharp_ext",
srcs = [
diff --git a/WORKSPACE b/WORKSPACE
index 6a1b70e152..1499a0a52f 100644
--- a/WORKSPACE
+++ b/WORKSPACE
@@ -4,6 +4,16 @@ bind(
)
bind(
+ name = "grpc_cpp_plugin",
+ actual = "//:grpc_cpp_plugin",
+)
+
+bind(
+ name = "grpc++",
+ actual = "//:grpc++",
+)
+
+bind(
name = "libssl",
actual = "@submodule_boringssl//:ssl",
)
@@ -14,13 +24,18 @@ bind(
)
bind(
+ name = "protobuf",
+ actual = "@submodule_protobuf//:protobuf",
+)
+
+bind(
name = "protobuf_clib",
actual = "@submodule_protobuf//:protoc_lib",
)
bind(
name = "protobuf_compiler",
- actual = "@submodule_protobuf//:protoc_lib",
+ actual = "@submodule_protobuf//:protoc",
)
new_local_repository(
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
+ )
diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl
new file mode 100644
index 0000000000..a021742798
--- /dev/null
+++ b/bazel/generate_cc.bzl
@@ -0,0 +1,59 @@
+"""Generates C++ grpc stubs from proto_library rules.
+
+This is an internal rule used by cc_grpc_library, and shouldn't be used
+directly.
+"""
+
+def generate_cc_impl(ctx):
+ """Implementation of the gengrpccc 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]
+ 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]
+ arguments += ["-I{0}={0}".format(include.path) for include in includes]
+ arguments += [proto.path for proto in protos]
+
+ ctx.action(
+ inputs = protos + includes,
+ outputs = out_files,
+ executable = ctx.executable._protoc,
+ arguments = arguments,
+ )
+
+ return struct(files=set(out_files))
+
+generate_cc = rule(
+ attrs = {
+ "srcs": attr.label_list(
+ mandatory = True,
+ non_empty = True,
+ providers = ["proto"],
+ ),
+ "plugin": attr.label(
+ executable = True,
+ providers = ["files_to_run"],
+ cfg = HOST_CFG,
+ ),
+ "flags": attr.string_list(
+ mandatory = True,
+ allow_empty = False
+ ),
+ "_protoc": attr.label(
+ default = Label("//extern:protocol_compiler"),
+ executable = True,
+ cfg = HOST_CFG,
+ ),
+ },
+ # We generate .h files, so we need to output to genfiles.
+ output_to_genfiles = True,
+ implementation = generate_cc_impl,
+)
diff --git a/grpc-build-system.bzl b/bazel/grpc_build_system.bzl
index 187cc3e424..f2dde951fd 100644
--- a/grpc-build-system.bzl
+++ b/bazel/grpc_build_system.bzl
@@ -48,3 +48,10 @@ def grpc_cc_library(name, srcs = [], public_hdrs = [], hdrs = [], external_deps
"include"
]
)
+
+def grpc_proto_plugin(name, srcs = [], deps = []):
+ native.cc_binary(
+ name = name,
+ srcs = srcs,
+ deps = deps,
+ )