tonic icon indicating copy to clipboard operation
tonic copied to clipboard

`protobuf` v4 codec and codegen

Open kriswuollett opened this issue 9 months ago • 2 comments

Feature Request

Add protobuf v4 server code generation and server codec support.

Motivation

A beta version of the Google-assumed protobuf library seems to have been released (4.30.0-beta1). Assuming this will eventually provide semi-official Proto Text and JSON serialization support. See docs.

Given that the protobuf library wraps the C++ implementations, I'd lean towards assuming that any new gRPC Rust implementation will also wrap the C++ server given the battle-tested C++ proto messages stated reasonings. Or maybe it would be pure Rust, but based on another runtime like Cloudflare's Pingora. In any case, developers may wish to stick with tonic/hyper/tokio, but replace prost.

Caveats

  • Message generation will probably not be done under the prost project?
  • Have not tried to compile the protos myself personally (Ubuntu 22.04.5 LTS, x86_64):
$ sha256sum ~/tmp/bin/protoc 
1736d7bdcf94a2d96ed355c329b603f067dc70b3b7306431cedf5a3e5f2b91d8  /home/kris/tmp/bin/protoc
$ ~/tmp/bin/protoc --version
libprotoc 30.0
$ ~/tmp/bin/protoc --rust_out=./rust_out \
    --rust_opt=experimental-codegen=enabled \
    --rust_opt=kernel=cpp \
    -Iprotos protos/google/protobuf/source_context.proto
$ tree rust_out/
rust_out/
└── google
    └── protobuf
        ├── generated.rs
        ├── source_context.c.pb.rs
        └── source_context.pb.thunks.cc

3 directories, 3 files

kriswuollett avatar Mar 05 '25 23:03 kriswuollett

Work has already started on the next branch for this.

LucioFranco avatar Jun 20 '25 14:06 LucioFranco

If you got an error like this:

Expected protoc version 32.0 but found 3.19.6

try this:

⬢ [riscv@toolbx tonic]$ grep -n -H interop Cargo.toml
Cargo.toml:16:  #"interop", # Tests

cargo build --release --offline

omac777 avatar Sep 25 '25 21:09 omac777