Skip to content

compiler: support protobuf well-known types - #322

Open
Tim-Zhang wants to merge 2 commits into
masterfrom
fix-168-well-known-protos
Open

compiler: support protobuf well-known types#322
Tim-Zhang wants to merge 2 commits into
masterfrom
fix-168-well-known-protos

Conversation

@Tim-Zhang

Copy link
Copy Markdown
Member

Summary

  • replace the vendored proto parser with protobuf-parse
  • resolve embedded Google well-known and descriptor proto imports
  • map RPC input and output types to their protobuf runtime paths
  • preserve local paths for proto files explicitly selected for generation
  • cover sync, async, and streaming code generation

Why

ttrpc-codegen could not resolve canonical Google well-known proto imports unless callers supplied local copies. Even after parsing those imports, generated ttrpc services referenced local modules that protobuf-codegen does not emit for embedded runtime types.

This change uses the parser maintained alongside protobuf-codegen and makes ttrpc service generation follow the same runtime type mapping.

Fixes #168

Validation

  • cargo test --workspace --all-features
  • cargo build -p ttrpc-example --all-targets
  • cargo clippy -p ttrpc -p ttrpc-compiler -p ttrpc-codegen --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • git diff --check

The workspace test was run after removing all generated example Rust sources, confirming that code generation recreates and compiles them from a clean state.

Replace the vendored parser with the parser used by rust-protobuf.

Signed-off-by: Tim Zhang <tim@hyper.sh>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-codegen with protobuf-parse and adds coverage for well-known import resolution.
  • Introduces runtime-vs-generated Rust type mapping in ttrpc-compiler so 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.

Comment thread compiler/src/util/scope.rs Outdated
Comment thread compiler/src/util/scope.rs Outdated
@Tim-Zhang
Tim-Zhang force-pushed the fix-168-well-known-protos branch 2 times, most recently from d16ce90 to ca77ffe Compare August 11, 2026 09:06
@Tim-Zhang
Tim-Zhang requested a balanced review from Copilot August 11, 2026 09:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

@Tim-Zhang
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
Tim-Zhang force-pushed the fix-168-well-known-protos branch from ca77ffe to 1a9120c Compare August 11, 2026 09:25
@Tim-Zhang
Tim-Zhang requested a balanced review from Copilot August 11, 2026 09:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 19 out of 19 changed files in this pull request and generated no new comments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Well known proto support

2 participants