From ec27b28121dec4c8a6cad0eab60efec706114718 Mon Sep 17 00:00:00 2001 From: Ian Sturdy Date: Wed, 7 Mar 2018 11:27:59 -0800 Subject: Fix C++ codegen with bazel in subrepositories --- bazel/generate_cc.bzl | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'bazel') diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index f88ee2f56f..11affaa4c7 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -10,7 +10,16 @@ def generate_cc_impl(ctx): includes = [f for src in ctx.attr.srcs for f in src.proto.transitive_imports] outs = [] # label_len is length of the path from WORKSPACE root to the location of this build file - label_len = len(ctx.label.package) + 1 + label_len = 0 + # proto_root is the directory relative to which generated include paths should be + proto_root = "" + if ctx.label.package: + # The +1 is for the trailing slash. + label_len += len(ctx.label.package) + 1 + if ctx.label.workspace_root: + label_len += len(ctx.label.workspace_root) + 1 + proto_root = "/" + ctx.label.workspace_root + if ctx.executable.plugin: outs += [proto.path[label_len:-len(".proto")] + ".grpc.pb.h" for proto in protos] outs += [proto.path[label_len:-len(".proto")] + ".grpc.pb.cc" for proto in protos] @@ -20,7 +29,7 @@ def generate_cc_impl(ctx): outs += [proto.path[label_len:-len(".proto")] + ".pb.h" for proto in protos] outs += [proto.path[label_len:-len(".proto")] + ".pb.cc" for proto in protos] out_files = [ctx.new_file(out) for out in outs] - dir_out = str(ctx.genfiles_dir.path) + dir_out = str(ctx.genfiles_dir.path + proto_root) arguments = [] if ctx.executable.plugin: @@ -33,7 +42,11 @@ def generate_cc_impl(ctx): else: arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] additional_input = [] - arguments += ["-I{0}={0}".format(include.path) for include in includes] + # Import protos relative to the workspace root so that protoc prints the right + # include paths. + arguments += ["--proto_path=" + (ctx.label.workspace_root or ".")] + # A second include so that protoc puts the generated code in the right directory. + arguments += ["--proto_path={0}{1}".format(dir_out, proto_root)] arguments += [proto.path for proto in protos] # create a list of well known proto files if the argument is non-None -- cgit v1.2.3 From 3a8c0d6a192cc969d9f9e5d72a968251d93459a7 Mon Sep 17 00:00:00 2001 From: Ian Sturdy Date: Wed, 7 Mar 2018 12:11:21 -0800 Subject: Add external bindings for targets needed for the cc_grpc_library rule. --- bazel/grpc_deps.bzl | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'bazel') diff --git a/bazel/grpc_deps.bzl b/bazel/grpc_deps.bzl index a441c3ff3d..6b3a55379e 100644 --- a/bazel/grpc_deps.bzl +++ b/bazel/grpc_deps.bzl @@ -57,6 +57,16 @@ def grpc_deps(): actual = "@com_github_gflags_gflags//:gflags", ) + native.bind( + name = "grpc_cpp_plugin", + actual = "@com_github_grpc_grpc//:grpc_cpp_plugin" + ) + + native.bind( + name = "grpc++_codegen_proto", + actual = "@com_github_grpc_grpc//:grpc++_codegen_proto" + ) + if "boringssl" not in native.existing_rules(): native.http_archive( name = "boringssl", -- cgit v1.2.3 From e6dfa9cd74fe7fa187072b362719d2a1ba386e3e Mon Sep 17 00:00:00 2001 From: Ian Sturdy Date: Mon, 19 Mar 2018 16:12:45 -0700 Subject: Fix cross-repository proto includes. --- bazel/generate_cc.bzl | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'bazel') diff --git a/bazel/generate_cc.bzl b/bazel/generate_cc.bzl index 11affaa4c7..96610d873e 100644 --- a/bazel/generate_cc.bzl +++ b/bazel/generate_cc.bzl @@ -42,10 +42,19 @@ def generate_cc_impl(ctx): else: arguments += ["--cpp_out=" + ",".join(ctx.attr.flags) + ":" + dir_out] additional_input = [] - # Import protos relative to the workspace root so that protoc prints the right - # include paths. - arguments += ["--proto_path=" + (ctx.label.workspace_root or ".")] - # A second include so that protoc puts the generated code in the right directory. + + # Import protos relative to their workspace root so that protoc prints the + # right include paths. + for include in includes: + directory = include.path + if directory.startswith("external"): + external_sep = directory.find("/") + repository_sep = directory.find("/", external_sep + 1) + arguments += ["--proto_path=" + directory[:repository_sep]] + else: + arguments += ["--proto_path=."] + # Include the output directory so that protoc puts the generated code in the + # right directory. arguments += ["--proto_path={0}{1}".format(dir_out, proto_root)] arguments += [proto.path for proto in protos] -- cgit v1.2.3