ttrpc-rust
ttrpc-rust is a non-core subproject of containerd
ttrpc-rust
is the Rust version of ttrpc. ttrpc is GRPC for low-memory environments.
The ttrpc compiler of ttrpc-rust
ttrpc_rust_plugin
is modified from gRPC compiler of gRPC-rs grpcio-compiler.
Usage
protoc
command
1. Generate with To generate the sources from proto files:
-
Install protoc from github.com/protocolbuffers/protobuf
-
Install protobuf-codegen from github.com/pingcap/grpc-rs
cd grpc-rs
cargo install --force protobuf-codegen
- Install ttrpc_rust_plugin from ttrpc-rust/compiler
cd ttrpc-rust/compiler
cargo install --force --path .
- Generate the sources:
$ protoc --rust_out=. --ttrpc_out=. --plugin=protoc-gen-ttrpc=`which ttrpc_rust_plugin` example.proto
2. Generate programmatically
API to generate .rs files to be used e. g. from build.rs.
Example code:
fn main() {
protoc_rust_ttrpc::Codegen::new()
.out_dir("protocols")
.inputs(&[
"protocols/protos/agent.proto",
])
.include("protocols/protos")
.rust_protobuf() // also generate protobuf messages, not just services
.run()
.expect("Codegen failed.");
}
Run Examples
-
Go to the directory
$ cd ttrpc-rust/example
-
Start the server
$ cargo run --example server unix:///tmp/1
-
Start a client
$ cargo run --example client /tmp/1
Notes: the version of protobuf
protobuf-codegen, ttrpc_rust_plugin and your code should use the same version protobuf. You will get following fail if use the different version protobuf.
27 | const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_0;
| ^^^^^^^^^^^^^ help: a constant with a similar name exists: `VERSION_2_10_1`
The reason is that files generated by protobuf-codegen are compatible only with the same version of runtime
To fix this issue:
- Rebuild protobuf-codegen with new protobuf:
cd grpc-rs
cargo clean
cargo update
cargo install --force protobuf-codegen
- Rebuild ttrpc_rust_plugin with new protobuf:
cd ttrpc-rust/compiler
cargo clean
cargo update
cargo install --force --path .
- Build your project.