Skip to content

namespacing issues with services when not using prost-types for well-known protobuf types #521

@tdyas

Description

@tdyas

Bug Report

Version

tonic v0.3.1
tonic-build v0.3.1
prost at danburkert/prost@a1cccbc (v0.6.x at the commit with Bytes support)

Platform

macOS 10.15.7

Crates

tonic-build

Description

I am using Prost pinned to master at danburkert/prost@a1cccbc (which includes the use of Bytes for binary fields).

I would like to have Prost compile the well-known types (instead of using prost-types) so that Any fields use Bytes. However, when I enable that mode via config.compile_well_known_types() in build.rs, generated grpc service stubs fail to compile because they are in a _client submodule and are missing an extra super reference necessary to get the identifier path out of that submodule.

For example, when compiling the Google Operations API protos, errors like the following occur:

error[E0433]: failed to resolve: could not find `protobuf` in `super`
   --> XXX/target/debug/build/bazel_protos-4307470ac76a8035/out/google.longrunning.rs:183:40
    |
183 |     ) -> Result<tonic::Response<super::protobuf::Empty>, tonic::Status> {
    |                                        ^^^^^^^^ could not find `protobuf` in `super`

This code was within an operations_client submodule. The reference needs to be super::super::protobuf::Empty in this case, not super::protobuf::Empty. (The service in this example returns a google.protobuf.Empty.)

I assume the issue is the special casing of identifiers in google.protobuf performed in the service generator at

let request = if self.input_proto_type.starts_with(".google.protobuf")
and
let response = if self.output_proto_type.starts_with(".google.protobuf")
. That special casing does not apply the proto_path to google.protobuf types but implicitly assumes that they will be found in prost-types, which is not the case if they are being compiled by Prost.

I am willing to contribute a fix, but would need some basic guidance on what the right fix is. I assume the fix be as simple as just taking the else branch when well-known types are being compiled?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-buildC-bugCategory: Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions