fix(build): Correctly convert Empty
to ()
#734
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
#521 covers the work for Tonic to compile the well-known protobuf types instead of relying on the
prost-types
crate. (One reason to do that is for projects that wantgoogle.protobuf.Any
to useBytes
instead ofVec<u8>
for binary data.)#522 added initial support for Tonic to configure Prost and itself to compile the well-known protobuf types.
That support is incomplete, however:
tonic-build
fails to compile when configured to convertgoogle.protobuf.Empty
to()
. This configuration occurs if the user callsconfig.extern_path(".google.protobuf.Empty", "()")
whereconfig
is an instance ofprost_build::Config
. The error occurs because the existing code tries to interpret()
as a Rust path and parsing, for example,super::()
as a Rust path will always fail.Solution
This PR fixes the conversion of
google.protobuf.Empty
to()
by specifically allowing the use of()
as a valid Rust conversion without attempting to prepend any Rust path.There are several stacked commits in this PR:
wellknown-compiled
integration test to configure thegoogle.protobuf.Empty
->()
conversion. This first commit fails to compile without the fix.tonic_build::prost::Service::request_response_name
to remove the duplication of logic between converting request and response types.()
for now) and just generate a token stream in that case without trying to interpret as a Rust path.