compiler: support protobuf well-known types - #322
Open
Tim-Zhang wants to merge 2 commits into
Open
Conversation
Replace the vendored parser with the parser used by rust-protobuf. Signed-off-by: Tim Zhang <tim@hyper.sh>
There was a problem hiding this comment.
Pull request overview
This PR updates ttrpc-codegen/ttrpc-compiler so .proto inputs that import canonical Google well-known protos (e.g., google/protobuf/timestamp.proto) can be parsed/typechecked without local copies, and generated RPC stubs reference the protobuf runtime types for those dependencies.
Changes:
- Replaces the vendored proto parser in
ttrpc-codegenwithprotobuf-parseand adds coverage for well-known import resolution. - Introduces runtime-vs-generated Rust type mapping in
ttrpc-compilerso RPC input/output types from well-known dependencies use::protobuf::well_known_types::...(and descriptor types use::protobuf::descriptor::...) unless explicitly generated. - Extends request-handler macros to accept a fully-qualified request type path, enabling service codegen to reference runtime types.
Reviewed changes
Copilot reviewed 19 out of 19 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| ttrpc-codegen/tests/well_known.rs | Adds tests asserting parsing/typechecking and generated service/message type paths for well-known imports. |
| ttrpc-codegen/tests/protos/well_known.proto | Test fixture proto importing descriptor/timestamp well-known protos. |
| ttrpc-codegen/src/str_lit.rs | Removes string-literal decoding code from the old vendored parser. |
| ttrpc-codegen/src/parser.rs | Removes the vendored proto lexer/parser implementation. |
| ttrpc-codegen/src/model.rs | Removes the vendored parser AST/model types. |
| ttrpc-codegen/src/lib.rs | Switches parse_and_typecheck to protobuf-parse and updates docs. |
| ttrpc-codegen/src/convert.rs | Removes the old AST→descriptor conversion layer. |
| ttrpc-codegen/README.md | Documents well-known type resolution and runtime type mapping behavior. |
| ttrpc-codegen/Cargo.toml | Replaces protobuf-support with protobuf-parse; adds tempfile for tests. |
| src/sync/utils.rs | Updates request_handler! to accept request type as a path (supports runtime types). |
| src/asynchronous/utils.rs | Updates async handler macros to accept request type as a path where needed. |
| README.md | Notes that well-known imports are available automatically for programmatic generation. |
| example/protocols/protos/well_known.proto | Adds example proto using descriptor/timestamp well-known types. |
| example/protocols/protos/well_known_streaming.proto | Adds example streaming proto using Timestamp well-known type. |
| example/build.rs | Includes new well-known example protos in the example build. |
| compiler/src/util/scope.rs | Adds RustType and logic to map well-known/descriptor dependencies to protobuf runtime paths. |
| compiler/src/codegen.rs | Uses RustType for method signatures and handler macro invocations. |
| compiler/README.md | Documents how well-known dependencies map to runtime types unless explicitly generated. |
| Cargo.toml | Replaces workspace dependency protobuf-support with protobuf-parse. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Tim-Zhang
force-pushed
the
fix-168-well-known-protos
branch
2 times, most recently
from
August 11, 2026 09:06
d16ce90 to
ca77ffe
Compare
Tim-Zhang
marked this pull request as ready for review
August 11, 2026 09:13
Resolve well-known imports and generate their protobuf runtime paths. Signed-off-by: Tim Zhang <tim@hyper.sh>
Tim-Zhang
force-pushed
the
fix-168-well-known-protos
branch
from
August 11, 2026 09:25
ca77ffe to
1a9120c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
protobuf-parseprotobufruntime pathsWhy
ttrpc-codegencould not resolve canonical Google well-known proto imports unless callers supplied local copies. Even after parsing those imports, generated ttrpc services referenced local modules thatprotobuf-codegendoes not emit for embedded runtime types.This change uses the parser maintained alongside
protobuf-codegenand makes ttrpc service generation follow the same runtime type mapping.Fixes #168
Validation
cargo test --workspace --all-featurescargo build -p ttrpc-example --all-targetscargo clippy -p ttrpc -p ttrpc-compiler -p ttrpc-codegen --all-targets --all-features -- -D warningscargo fmt --all -- --checkgit diff --checkThe workspace test was run after removing all generated example Rust sources, confirming that code generation recreates and compiles them from a clean state.