-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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
tonic/tonic-build/src/prost.rs
Line 96 in 3c2a4a2
| let request = if self.input_proto_type.starts_with(".google.protobuf") |
tonic/tonic-build/src/prost.rs
Line 106 in 3c2a4a2
| let response = if self.output_proto_type.starts_with(".google.protobuf") |
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?