containerd / ttrpc-rust

Rust implementation of ttrpc (GRPC for low-memory environments)
Apache License 2.0
197 stars 47 forks source link

codegen: Introduce a new codegen using prost #173

Closed justxuewei closed 1 year ago

justxuewei commented 1 year ago

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[bot] commented 1 year ago

Codecov Report

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

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

:exclamation: 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 ```diff @@ 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](https://codecov.io/gh/containerd/ttrpc-rust/pull/173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=containerd) | Coverage Δ | | |---|---|---| | [src/common.rs](https://codecov.io/gh/containerd/ttrpc-rust/pull/173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=containerd#diff-c3JjL2NvbW1vbi5ycw==) | `34.57% <0.00%> (-1.00%)` | :arrow_down: | | [src/sync/client.rs](https://codecov.io/gh/containerd/ttrpc-rust/pull/173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=containerd#diff-c3JjL3N5bmMvY2xpZW50LnJz) | `0.00% <0.00%> (ø)` | | | [src/asynchronous/client.rs](https://codecov.io/gh/containerd/ttrpc-rust/pull/173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=containerd#diff-c3JjL2FzeW5jaHJvbm91cy9jbGllbnQucnM=) | `0.00% <0.00%> (ø)` | | | [src/asynchronous/server.rs](https://codecov.io/gh/containerd/ttrpc-rust/pull/173?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=containerd#diff-c3JjL2FzeW5jaHJvbm91cy9zZXJ2ZXIucnM=) | `0.00% <0.00%> (ø)` | | Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=containerd). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=containerd)

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

Tim-Zhang commented 1 year ago

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