Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

c++: gRPC service descriptors are missing if the source proto has no messages defined #4221

Closed
kyessenov opened this issue Jan 24, 2018 · 2 comments

Comments

@kyessenov
Copy link

It seems that if my protobuf file consists of a single service, and I link against the resulting .pb.h then the service descriptor is missing from the generated descriptor pool. For context, this is happening in Envoy (https://github.com/envoyproxy/envoy/blob/master/source/common/upstream/cds_api_impl.cc#L40) using Bazel to generate protobuf files.

The workaround is to (1) add a dummy message to the service proto; (2) instantiate the dummy message from the resulting .pb.h file.

cc @htuch

@xfxyjwf
Copy link
Contributor

xfxyjwf commented Jan 25, 2018

What you observed is most likely due to the linker dropping unused symbols (i.e., the descriptor registering code is not reachable from your application code so they got removed by linker). Besides adding a dummy message and referencing it in C++ code, there are a few other options:

  1. Add "option cc_generic_services = true;" to the proto file and reference the generated service code.
  2. Use bazel's always_link attribute to prevent linker dropping the proto library.

@htuch
Copy link
Contributor

htuch commented Jan 25, 2018

always_link makes the most sense in our situation, since we do not want to use the generated service code. @kyessenov can you confirm this works? Thanks @xfxyjwf.

htuch added a commit to htuch/envoy that referenced this issue Dec 2, 2019
It's unclear if these are still needed given a number of protobuf library bumps, changes to the API
build system and protocolbuffers/protobuf#4221. Removing the target
doesn't cause any tests to fail.

Risk level: Low
Testing: bazel test //test/... This PR merging is conditional on the Envoy Mobile team confirming
  that there is no breakage.

Signed-off-by: Harvey Tuch <htuch@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants