-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Open
arjan-bal
wants to merge
25
commits into
hyperium:master
Choose a base branch
from
arjan-bal:grpc-codegen
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,622
−421
Open
Changes from 2 commits
Commits
Show all changes
25 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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,6 +33,25 @@ jobs: | |
with: | ||
components: clippy | ||
- uses: taiki-e/install-action@protoc | ||
- name: Install Bazel | ||
uses: bazel-contrib/[email protected] | ||
with: | ||
# Avoid downloading Bazel every time. | ||
bazelisk-cache: true | ||
# Store build cache per workflow. | ||
disk-cache: ${{ github.workflow }} | ||
# Share repository cache between workflows. | ||
repository-cache: true | ||
module-root: ./compiler | ||
- name: Build and protoc plugin and add to PATH | ||
id: build_step | ||
# This runs all commands within the compiler/ directory | ||
working-directory: ./compiler | ||
run: | | ||
bazel build //src:protoc-gen-rust-grpc | ||
|
||
# Add the output directory to the GitHub PATH for subsequent steps | ||
echo "$(pwd)/bazel-bin/src" >> $GITHUB_PATH | ||
- uses: Swatinem/rust-cache@v2 | ||
- run: cargo clippy --workspace --all-features --all-targets | ||
|
||
|
@@ -55,6 +74,25 @@ jobs: | |
- uses: taiki-e/install-action@cargo-hack | ||
- uses: taiki-e/install-action@cargo-udeps | ||
- uses: taiki-e/install-action@protoc | ||
- name: Install Bazel | ||
uses: bazel-contrib/[email protected] | ||
with: | ||
# Avoid downloading Bazel every time. | ||
bazelisk-cache: true | ||
# Store build cache per workflow. | ||
disk-cache: ${{ github.workflow }} | ||
# Share repository cache between workflows. | ||
repository-cache: true | ||
module-root: ./compiler | ||
- name: Build and protoc plugin and add to PATH | ||
id: build_step | ||
# This runs all commands within the compiler/ directory | ||
working-directory: ./compiler | ||
run: | | ||
bazel build //src:protoc-gen-rust-grpc | ||
|
||
# Add the output directory to the GitHub PATH for subsequent steps | ||
echo "$(pwd)/bazel-bin/src" >> $GITHUB_PATH | ||
- uses: Swatinem/rust-cache@v2 | ||
- run: cargo hack udeps --workspace --exclude-features=_tls-any,tls,tls-aws-lc,tls-ring --each-feature | ||
- run: cargo udeps --package tonic --features tls-ring,transport | ||
|
@@ -76,6 +114,25 @@ jobs: | |
- uses: hecrj/setup-rust-action@v2 | ||
- uses: taiki-e/install-action@cargo-hack | ||
- uses: taiki-e/install-action@protoc | ||
- name: Install Bazel | ||
uses: bazel-contrib/[email protected] | ||
with: | ||
# Avoid downloading Bazel every time. | ||
bazelisk-cache: true | ||
# Store build cache per workflow. | ||
disk-cache: ${{ github.workflow }} | ||
# Share repository cache between workflows. | ||
repository-cache: true | ||
module-root: ./compiler | ||
- name: Build and protoc plugin and add to PATH | ||
id: build_step | ||
# This runs all commands within the compiler/ directory | ||
working-directory: ./compiler | ||
run: | | ||
bazel build //src:protoc-gen-rust-grpc | ||
|
||
# Add the output directory to the GitHub PATH for subsequent steps | ||
echo "$(pwd)/bazel-bin/src" >> $GITHUB_PATH | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Check features | ||
run: cargo hack check --workspace --no-private --each-feature --no-dev-deps | ||
|
@@ -115,6 +172,25 @@ jobs: | |
- uses: actions/checkout@v4 | ||
- uses: hecrj/setup-rust-action@v2 | ||
- uses: taiki-e/install-action@protoc | ||
- name: Install Bazel | ||
uses: bazel-contrib/[email protected] | ||
with: | ||
# Avoid downloading Bazel every time. | ||
bazelisk-cache: true | ||
# Store build cache per workflow. | ||
disk-cache: ${{ github.workflow }} | ||
# Share repository cache between workflows. | ||
repository-cache: true | ||
module-root: ./compiler | ||
- name: Build and protoc plugin and add to PATH | ||
id: build_step | ||
# This runs all commands within the compiler/ directory | ||
working-directory: ./compiler | ||
run: | | ||
bazel build //src:protoc-gen-rust-grpc | ||
|
||
# Add the output directory to the GitHub PATH for subsequent steps | ||
echo "$(pwd)/bazel-bin/src" >> $GITHUB_PATH | ||
- uses: taiki-e/install-action@cargo-hack | ||
- uses: taiki-e/install-action@cargo-nextest | ||
- uses: Swatinem/rust-cache@v2 | ||
|
@@ -141,6 +217,25 @@ jobs: | |
- uses: actions/checkout@v4 | ||
- uses: hecrj/setup-rust-action@v2 | ||
- uses: taiki-e/install-action@protoc | ||
- name: Install Bazel | ||
uses: bazel-contrib/[email protected] | ||
with: | ||
# Avoid downloading Bazel every time. | ||
bazelisk-cache: true | ||
# Store build cache per workflow. | ||
disk-cache: ${{ github.workflow }} | ||
# Share repository cache between workflows. | ||
repository-cache: true | ||
module-root: ./compiler | ||
- name: Build and protoc plugin and add to PATH | ||
id: build_step | ||
# This runs all commands within the compiler/ directory | ||
working-directory: ./compiler | ||
run: | | ||
bazel build //src:protoc-gen-rust-grpc | ||
|
||
# Add the output directory to the GitHub PATH for subsequent steps | ||
echo "$(pwd)/bazel-bin/src" >> $GITHUB_PATH | ||
- uses: Swatinem/rust-cache@v2 | ||
- name: Run interop tests | ||
run: ./interop/test.sh | ||
|
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,9 @@ | ||
# Bazel | ||
bazel-bin | ||
bazel-examples | ||
bazel-genfiles | ||
bazel-grpc-java | ||
bazel-out | ||
bazel-testlogs | ||
MODULE.bazel.lock | ||
|
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,15 @@ | ||
bazel_dep(name = "protobuf", repo_name = "com_google_protobuf", version = "31.1") | ||
|
||
# Hedron's Compile Commands Extractor for bazel | ||
# This is used to generate a compile_commands.json file which can be used by | ||
# LSP servers like clangd. | ||
# https://github.com/hedronvision/bazel-compile-commands-extractor | ||
bazel_dep(name = "hedron_compile_commands", dev_dependency = True) | ||
git_override( | ||
module_name = "hedron_compile_commands", | ||
# Using a commit from a fork to workaround failures while using absl. | ||
# TODO: replace with a commit on the official repo once the following PR is | ||
# merged: https://github.com/hedronvision/bazel-compile-commands-extractor/pull/219 | ||
remote = "https://github.com/mikael-s-persson/bazel-compile-commands-extractor", | ||
commit = "f5fbd4cee671d8d908f37c83abaf70fba5928fc7" | ||
) |
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,29 @@ | ||
## Usage example | ||
```sh | ||
# Build the plugin with Bazel | ||
bazel build //src:protoc-gen-rust-grpc | ||
|
||
# Set the plugin path | ||
PLUGIN_PATH="$(pwd)/bazel-bin/src/protoc-gen-rust-grpc" | ||
|
||
# Run protoc with the Rust and gRPC plugins | ||
protoc \ | ||
--plugin=protoc-gen-grpc-rust="$PLUGIN_PATH" \ | ||
--rust_opt="experimental-codegen=enabled,kernel=upb" \ | ||
--rust_out=./tmp \ | ||
--rust-grpc_opt="experimental-codegen=enabled" \ | ||
--rust-grpc_out=./tmp \ | ||
routeguide.proto | ||
``` | ||
|
||
## Build | ||
```sh | ||
bazel build //src:protoc-gen-rust-grpc | ||
``` | ||
|
||
## Language Server Support for development | ||
Generate compile_commands.json using bazel plugin. Configure the language | ||
server to use the generate json file. | ||
```sh | ||
bazel run @hedron_compile_commands//:refresh_all | ||
``` |
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,13 @@ | ||
cc_binary( | ||
name = "protoc-gen-rust-grpc", | ||
srcs = [ | ||
"grpc_rust_plugin.cc", | ||
"grpc_rust_generator.h", | ||
"grpc_rust_generator.cc", | ||
], | ||
visibility = ["//visibility:public"], | ||
deps = [ | ||
"@com_google_protobuf//:protoc_lib", | ||
], | ||
) | ||
|
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.
Should we rename this containg folder? Compiler seems quite ambiguous?
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.
Yes, it is. I was using the same name as Java and the core repo. I've changed it to the name of protoc plugin,
protoc-gen-rust-grpc
now.