Skip to content

codegen: Introduce a new codegen using prost#173

Closed
justxuewei wants to merge 4 commits intocontainerd:masterfrom
justxuewei:prost
Closed

codegen: Introduce a new codegen using prost#173
justxuewei wants to merge 4 commits intocontainerd:masterfrom
justxuewei:prost

Conversation

@justxuewei
Copy link
Copy Markdown
Contributor

@justxuewei justxuewei commented Feb 8, 2023

This pull request introduces a new feature, prost, for the ttrpc-rust. The Prost is a modern Protobuf compiler that leverages the power of procedural macro of Rust. Currently, the prost version supports sync, async, and streaming. Here is part of the directory structure:

.
|-- codegen: The new codegen using prost
|-- compiler
|-- example2: Examples for the new codegen
|-- install_protoc.sh: Install protoc on the local environment
|-- src: The ttrpc-rust's src
`-- ttrpc-codegen

The ttrpc-rust is compatible with the older version, while there are certain differences:

  1. Protoc is required.
  2. Enable "prost" feature for the ttrpc-rust, e.g. ttrpc = { version = "1.0", features = ["prost"] }.
  3. Generated Rust files are named based on their proto's package name, rather than the proto filename.
  4. Some variable names are different, e.g. for "cpu", CPU is generated by the Rust-protobuf, and Cpu is generated by the Prost.

"example2" gives some examples on how to use it. The functionalities are completely the same as "example".

Fixes: #170


codegen: Introduce a new codegen using prost

This pull request refactors the ttrpc-codegen and the compiler, and merges the two crates into a single crate, named "codegen". The codegen uses prost crate, a protobuf compiler for Rust.

Signed-off-by: Xuewei Niu niuxuewei.nxw@antgroup.com


ttrpc-rust: Support the new version of codegen

The ttrpc provides a "prost" feature to support the new version of
codegen. An "example2" has been added to demonstrate how to use the
codegen.

Signed-off-by: Xuewei Niu niuxuewei.nxw@antgroup.com


ci: Add codegen-related ci testing

Install protoc when executing make deps of the ttrpc. Add codegen's
check and build, and example2' build to the ci testing.

Signed-off-by: Xuewei Niu niuxuewei.nxw@antgroup.com


codegen: Fix issues reported by cargo clippy

Fix all issues reported by cargo clippy to make ci testing pass.

Signed-off-by: Xuewei Niu niuxuewei.nxw@antgroup.com

@codecov
Copy link
Copy Markdown

codecov Bot commented Feb 8, 2023

Codecov Report

Base: 25.71% // Head: 25.64% // Decreases project coverage by -0.08% ⚠️

Coverage data is based on head (ce4775e) compared to base (3522dac).
Patch has no changes to coverable lines.

❗ Current head ce4775e differs from pull request most recent head bfa8710. Consider uploading reports for the commit bfa8710 to get more accurate results

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #173      +/-   ##
==========================================
- Coverage   25.71%   25.64%   -0.08%     
==========================================
  Files          16       16              
  Lines        2399     2406       +7     
==========================================
  Hits          617      617              
- Misses       1782     1789       +7     
Impacted Files Coverage Δ
src/common.rs 34.57% <0.00%> (-1.00%) ⬇️
src/sync/client.rs 0.00% <0.00%> (ø)
src/asynchronous/client.rs 0.00% <0.00%> (ø)
src/asynchronous/server.rs 0.00% <0.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

@justxuewei justxuewei marked this pull request as draft February 8, 2023 06:23
@justxuewei justxuewei marked this pull request as ready for review February 16, 2023 15:32
@justxuewei justxuewei force-pushed the prost branch 2 times, most recently from a274a9e to 6dc75f5 Compare February 17, 2023 02:46
This commit refactors the ttrpc-codegen and the compiler, and merges the two
crates into a single crate, named "codegen". The codegen uses prost crate, a
protobuf compiler for Rust.

Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
The ttrpc provides a "prost" feature to support the new version of
codegen. An "example2" has been added to demonstrate how to use the
codegen.

Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Install protoc when executing `make deps` of the ttrpc. Add codegen's
check and build, and example2' build to the ci testing.

Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
@justxuewei justxuewei force-pushed the prost branch 2 times, most recently from 5f8f5b8 to f80fa73 Compare February 21, 2023 03:10
Fix all issues reported by cargo clippy to make ci testing pass.

Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Comment thread codegen/Cargo.toml
prost-build = "0.11"
proc-macro2 = "1.0"
quote = "1.0"
anyhow = "^1.0"
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.

Use anyhow="1.0" directly.

@Tim-Zhang
Copy link
Copy Markdown
Member

Tim-Zhang commented Aug 10, 2023

Hold this and going to reopen it when we need replace rust-protobuf in the future

@Tim-Zhang Tim-Zhang closed this Aug 10, 2023
jokemanfire added a commit to jokemanfire/ttrpc-rust that referenced this pull request Feb 24, 2025
ref: containerd#173

Co-authored-by: jokemanfire <hu.dingyang@zte.com.cn>
Signed-off-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
@jokemanfire jokemanfire mentioned this pull request Feb 24, 2025
@Tim-Zhang Tim-Zhang linked an issue Feb 25, 2025 that may be closed by this pull request
jokemanfire added a commit to jokemanfire/ttrpc-rust that referenced this pull request Feb 28, 2025
ref: containerd#173

Co-authored-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
jokemanfire added a commit to jokemanfire/ttrpc-rust that referenced this pull request Mar 13, 2025
ref: containerd#173

Co-authored-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
jokemanfire added a commit to jokemanfire/ttrpc-rust that referenced this pull request Mar 13, 2025
ref: containerd#173

Co-authored-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
jokemanfire added a commit to jokemanfire/ttrpc-rust that referenced this pull request Apr 10, 2025
merge from remote branch.
ref: containerd#173

Co-authored-by: Xuewei Niu <niuxuewei.nxw@antgroup.com>
Signed-off-by: jokemanfire <hu.dingyang@zte.com.cn>
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.

can we change protobuf to tokio-rs/prost? Replace rust-protobuf with prost

3 participants