Crates.io | tonic-build-protobuf |
lib.rs | tonic-build-protobuf |
version | 0.1.0 |
source | src |
created_at | 2024-06-02 15:25:36.090883 |
updated_at | 2024-06-02 15:25:36.090883 |
description | Codegen module of `tonic` gRPC implementation with rust-protobuf. |
homepage | https://github.com/overvenus/tonic-protobuf |
repository | https://github.com/overvenus/tonic-protobuf |
max_upload_size | |
id | 1259279 |
size | 18,670 |
Compiles proto files via rust-protobuf and generates service stubs for use with tonic.
Required dependencies
[dependencies]
tonic = "<tonic-version>"
protobuf = "<protobuf-version>"
tonic-codec-protobuf = "<tonic-codec-protobuf-version>"
[build-dependencies]
tonic-build-protobuf = "<tonic-build-protobuf-version>"
In build.rs
:
fn main() {
// Project layout:
// .
// ├── Cargo.toml
// ├── build.rs
// ├── include
// │ └── rustproto.proto
// ├── proto
// │ └── debugpb.proto
// └── src
// └── lib.rs
tonic_build_protobuf::Builder::new()
.out_dir(format!(
"{}/protos",
std::env::var("OUT_DIR").expect("No OUT_DIR defined")
))
.proto_path("crate")
.file_name(|pkg, svc| format!("{pkg}_{svc}_tonic"))
.codec_path("::tonic_codec_protobuf::ProtobufCodecV3")
.compile(&["proto/debugpb.proto"], &["proto", "include"]);
}
Then you can reference the generated Rust like this this in your code:
mod generated {
include!(concat!(env!("OUT_DIR"), "debugpb_debug_tonic.rs"));
}
pub use generated::*;
See examples here
This project is licensed under the MIT license.