Skip to content

feat(compiler): support C++ gRPC code generation - #3877

Merged
chaokunyang merged 1 commit into
apache:mainfrom
BaldDemian:cpp-grpc
Aug 2, 2026
Merged

feat(compiler): support C++ gRPC code generation#3877
chaokunyang merged 1 commit into
apache:mainfrom
BaldDemian:cpp-grpc

Conversation

@BaldDemian

@BaldDemian BaldDemian commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Why?

Support C++ gRPC code generation.

What does this PR do?

Overview

This PR adds C++ gRPC code generation support.
All unary, server-streaming, client-streaming, and bidirectional RPC types are supported.
They integrate with gRPC C++ synchronous APIs.

Fory-backed codec

Generated gRPC code uses Fory as codec. Given that the codec is relatively small, it is generated directed within each *_service_grpc.h.
On writes, codec moves serialized bytes into a gRPC Slice, avoiding an additional outbound payload copy. On reads, it uses a single ByteBuffer slice when possible and merges fragmented buffers only when necessary.

Error-handling

To make the logic more robust, this PR also adds gRPC-related naming collision detection and escaping.
This PR also considers special characters of C++ such as compilation guards.
Generated model and service headers use sanitized include guards;
the shared Fory codec is protected by FORY_GENERATED_GRPC_SERIALIZATION_TRAITS_;
each grpc::SerializationTraits<T> specialization has a stable, type-specific guard derived from a sanitized fully qualified type name and a SHA-256 prefix. This prevents duplicate specializations when several generated service headers use the same message type.

Testing

This PR adds compiler-side pytests and C++-Java gRPC interop tests. It also adds a dedicated job in the CI.

Documentation

This PR adds documentation for the usage and example of the C++ gRPC code generation feature.

Related issues

Close #3276.

AI Contribution Checklist

  • Substantial AI assistance was used in this PR: yes / no
  • If yes, I included a completed AI Contribution Checklist in this PR description and the required AI Usage Disclosure.
  • If yes, my PR description includes the required ai_review summary and screenshot evidence or equivalent persisted links of the final clean AI review results from both fresh reviewers described in AI_POLICY.md, the Fory-guided reviewer and the independent general reviewer, on the current PR diff or current HEAD after the latest code changes.

Does this PR introduce any user-facing change?

N/A.

Benchmark

N/A.

@BaldDemian
BaldDemian force-pushed the cpp-grpc branch 4 times, most recently from cce1a87 to dcb463d Compare July 22, 2026 10:23
@BaldDemian
BaldDemian force-pushed the cpp-grpc branch 2 times, most recently from 9041283 to 8aeadbf Compare July 29, 2026 09:10
@BaldDemian
BaldDemian force-pushed the cpp-grpc branch 2 times, most recently from 11d33c9 to aba3a14 Compare July 30, 2026 06:27
@BaldDemian
BaldDemian marked this pull request as ready for review July 30, 2026 06:54
Comment thread MODULE.bazel Outdated

@chaokunyang chaokunyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I found several correctness, compatibility, performance, and integration issues; see the inline comments.

Comment thread compiler/fory_compiler/generators/services/cpp.py Outdated
Comment thread compiler/fory_compiler/generators/services/cpp.py
Comment thread compiler/fory_compiler/generators/services/cpp.py Outdated
Comment thread compiler/fory_compiler/generators/services/cpp.py Outdated
Comment thread docs/guide/cpp/grpc-support.md
Comment thread compiler/fory_compiler/generators/services/cpp.py Outdated
Comment thread .github/workflows/ci.yml Outdated
Comment thread compiler/README.md

@wenshao wenshao 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.

Reviewed — no blockers. Suggestions are inline. Not linted (tool limitation, not a blocker): the executable-script lint — .github/workflows/ci.yml: actionlint embedded-shell source mapping is not yet supported — not linted.

— Qwen3-235B-A22B via Qwen Code /review (v0.21.2)

Comment thread docs/guide/cpp/grpc-support.md Outdated
Comment thread compiler/fory_compiler/generators/services/cpp.py
Comment thread compiler/fory_compiler/generators/services/rust.py
Comment thread docs/compiler/compiler-guide.md
@BaldDemian

Copy link
Copy Markdown
Contributor Author

Hi @chaokunyang, all advice listed above has been addressed. PTAL.

@chaokunyang chaokunyang left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@chaokunyang
chaokunyang merged commit 5971ded into apache:main Aug 2, 2026
72 checks passed
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.

[Compiler][gRPC][C++] Generate gRPC stubs with Fory codec

3 participants