-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(grpc): Add protobuf codegen
#2320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
1f78401
protobuf codec, codegen, interop test
arjan-bal 6a379ea
CI fixes
arjan-bal f3f9446
Enforce c++17
arjan-bal 05f4d7d
Cache plugin
arjan-bal 805cf79
Feature gate protobuf dependency
arjan-bal da8873f
Rename compiler directory
arjan-bal 1a66195
Fix external types check
arjan-bal 9c25329
Rename interop client biary
arjan-bal 15e1519
Add liscenses
arjan-bal 202411c
Docs and comments
arjan-bal fe31b76
Fix test
arjan-bal 89d7331
Avoid using protobuf rust's context
arjan-bal 9305da7
create a seperate module for the protobuf codec
arjan-bal ca8d638
Add readme for codegen
arjan-bal 08c6be1
Apply suggestions from code review
arjan-bal 4431e83
copyright in build files, clippy fixes and typos in README
arjan-bal 8a8e4e6
mostly C++ readability fixes
arjan-bal cd77988
Format generated code during build
arjan-bal 9f06a59
Address review
arjan-bal 5cd495c
Apply suggestions from code review
arjan-bal c3e03f9
Combine client binaries, use flag for codec
arjan-bal e8aaa51
Merge remote-tracking branch 'source/master' into grpc-codegen
arjan-bal 726d227
Fix cpp function name casing
arjan-bal d13eed5
Address review
arjan-bal c33f380
Align tonic-* crate versions in README
arjan-bal 00b6d63
Use include! instead of path
arjan-bal e35ddb9
Merge remote-tracking branch 'source/master' into grpc-codegen
arjan-bal 4b150c1
Export protobuf from tonic-protobuf
arjan-bal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| /* | ||
| * | ||
| * Copyright 2025 gRPC authors. | ||
| * | ||
| * Permission is hereby granted, free of charge, to any person obtaining a copy | ||
| * of this software and associated documentation files (the "Software"), to | ||
| * deal in the Software without restriction, including without limitation the | ||
| * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or | ||
| * sell copies of the Software, and to permit persons to whom the Software is | ||
| * furnished to do so, subject to the following conditions: | ||
| * | ||
| * The above copyright notice and this permission notice shall be included in | ||
| * all copies or substantial portions of the Software. | ||
| * | ||
| * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS | ||
| * IN THE SOFTWARE. | ||
| * | ||
| */ | ||
|
|
||
| /// Includes generated proto message, client, and server code. | ||
| /// | ||
| /// You must specify the path to the `.proto` file | ||
| /// **relative to the proto root directory**, without the `.proto` extension. | ||
| /// | ||
| /// For example, if your proto directory is `path/to/protos` and it contains the | ||
| /// file `helloworld.proto`, you would write: | ||
| /// | ||
| /// ```rust,ignore | ||
| /// mod pb { | ||
| /// grpc::include_proto!("path/to/protos", "helloworld"); | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// # Note | ||
| /// **This macro only works if the gRPC build output directory and message path | ||
| /// are unmodified.** | ||
| /// By default: | ||
| /// - The output directory is set to the [`OUT_DIR`] environment variable. | ||
| /// - The message path is set to `self`. | ||
| /// | ||
| /// If your `.proto` files are not in a subdirectory, you can omit the first | ||
| /// parameter. | ||
| /// | ||
| /// ```rust,ignore | ||
| /// mod pb { | ||
| /// grpc::include_proto!("helloworld"); | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// If you have modified the output directory or message path, you should | ||
| /// include the generated code manually instead of using this macro. | ||
| /// | ||
| /// The following example assumes the message code is imported using `self`: | ||
| /// | ||
| /// ```rust,ignore | ||
| /// mod protos { | ||
| /// // Include message code. | ||
| /// include!("relative/protobuf/directory/generated.rs"); | ||
| /// | ||
| /// // Include service code. | ||
| /// include!("relative/protobuf/directory/helloworld_grpc.pb.rs"); | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// If the message code and service code are in different modules, and the | ||
| /// message path specified during code generation is `super::protos`, use: | ||
| /// | ||
| /// ```rust,ignore | ||
| /// mod protos { | ||
| /// // Include message code. | ||
| /// include!("relative/protobuf/directory/generated.rs"); | ||
| /// } | ||
| /// | ||
| /// mod grpc { | ||
| /// // Include service code. | ||
| /// include!("relative/protobuf/directory/helloworld_grpc.pb.rs"); | ||
| /// } | ||
| /// ``` | ||
| /// | ||
| /// [`OUT_DIR`]: https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-build-scripts | ||
| #[macro_export] | ||
| macro_rules! include_proto { | ||
| // Assume the generated output dir is OUT_DIR. | ||
| ($proto_file:literal) => { | ||
| $crate::include_proto!("", $proto_file); | ||
| }; | ||
|
|
||
| ($parent_dir:literal, $proto_file:literal) => { | ||
| include!(concat!(env!("OUT_DIR"), "/", $parent_dir, "/generated.rs")); | ||
| include!(concat!( | ||
| env!("OUT_DIR"), | ||
| "/", | ||
| $parent_dir, | ||
| "/", | ||
| $proto_file, | ||
| "_grpc.pb.rs" | ||
| )); | ||
| }; | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this step take a long time? Generally, speaking I would rather that we build the plugin in each test job to ensure we are building the latest code and there is no caching issues. Could you explain the reasoning for breaking it up like this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a comment in the yaml. Building the protoc plugin from scratch takes 6–14 minutes, depending on the OS. This delays the execution of workflows that use the plugin in build.rs files.
Example workflow execution: https://github.com/hyperium/tonic/actions/runs/16217230891/job/45789317103
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay yeah if this works its fine for now, we probably want to improve this in the future..