grpc: C++ GRPC targets fail to build with import_prefix or strip_import_prefix in Bazel

GRPC Bazel targets (cc_grpc_library) fail to build when proto_library sources contain import_prefix and/or strip_import_prefix options.

What version of gRPC and what language are you using?

1.24.2 (latest master)

What operating system (Linux, Windows,…) and version?

Ubuntu Linux 18.04

What runtime / compiler are you using (e.g. python version or version of gcc)

clang 6.0 with bazel 0.29.1

What did you do?

Created a simple GRPC target (using the HelloService), where the proto_library contains configuration for import_prefix and strip_import_prefix. To reproduce, in the grpc repository:

  1. Cherry pick this commit: https://github.com/grpc/grpc/commit/6f1c7150d1d25674d53c8715ddf060d46199f0b4
  2. run bazel build //examples/cpp/strip_prefix:service_cc_grpc

What did you expect to see?

Target builds successfully.

What did you see instead?

INFO: Found 1 target...
ERROR: /home/cbills/git/grpc-coopeyb/examples/cpp/strip_prefix/BUILD:15:1: C++ compilation of rule '//examples/cpp/strip_prefix:service_cc_grpc' failed (Exit 1) clang failed: error executing command /usr/bin/clang -U_FORTIFY_SOURCE -fstack-protector -Wall -Wthread-safety -Wself-assign -fcolor-diagnostics -fno-omit-frame-pointer '-std=c++0x' -MD -MF ... (remaining 46 argument(s) skipped)

Use --sandbox_debug to see verbose messages from the sandbox
bazel-out/k8-fastbuild/bin/examples/cpp/strip_prefix/_virtual_imports/service_proto/custom/prefix/service.grpc.pb.cc:5:10: fatal error: 'examples/cpp/strip_prefix/_virtual_imports/service_proto/custom/prefix/service.pb.h' file not found
#include "examples/cpp/strip_prefix/_virtual_imports/service_proto/custom/prefix/service.pb.h"
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Target //examples/cpp/strip_prefix:service_cc_grpc failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 0.709s, Critical Path: 0.59s
INFO: 0 processes.
FAILED: Build did NOT complete successfully

Worth noting: poking around the sandbox after the failed build, service.pb.h exists, but under _virtual_includes instead of _virtual_imports.

Anything else we should know about your project / environment?

We’re having issues in our repository as well. We need the stirp_import_prefix and import_prefix options for integrating with our existing codebases and consider this issue to be a blocking item to migrate to Bazel.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 4
  • Comments: 23 (4 by maintainers)

Most upvoted comments

Quick update: Moving the protoc output directory seems the most promising. I’ll need to run some experiments to make sure it merges smoothly internally here at Google. It’s worth noting that changing the locations of intermediate files might have repercussions for anyone who was relying on them, but given that *import_prefix support is currently broken, this seems fairly low risk. I was also considering a lighter-weight solution that’s not ideal in other ways (embeds bazel-specific logic in the otherwise independent compiler).

@CoopeyB since the code in https://github.com/grpc/grpc/pull/26826/files is effectively your original patch, please file a PR and I’ll help usher it through.

Apologies that nobody from the gRPC team has addressed this, it’s been almost 2 years. As I understand it, in discussions past, this has been a troublesome problem to fix correctly without breaking things for some established users. (See https://github.com/grpc/grpc/pull/26826#issuecomment-889477022 for some commentary on a PR for @CoopeyB 's patch). I’ve reached out for help on this from the bazel team, and we’ll see if we can come up with the best way forward.