Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(build): Expose Prost generation plugin #947

Merged
merged 2 commits into from Mar 31, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tonic-build/src/lib.rs
Expand Up @@ -77,7 +77,7 @@ mod prost;

#[cfg(feature = "prost")]
#[cfg_attr(docsrs, doc(cfg(feature = "prost")))]
pub use prost::{compile_protos, configure, Builder};
pub use prost::{compile_protos, configure, Builder, ServiceGenerator};

/// Service code generation for client
pub mod client;
Expand Down
12 changes: 10 additions & 2 deletions tonic-build/src/prost.rs
Expand Up @@ -133,14 +133,22 @@ fn is_google_type(ty: &str) -> bool {
ty.starts_with(".google.protobuf")
}

struct ServiceGenerator {
/// A service generator compatible with `prost_build`'s one, to extend its code generator.
///
/// This is used internally by Tonic build, but also when the codegen output is not to be handled
/// by prost or tonic; e.g. such as in a flow for a `protoc` code generation plugin. When compiling
/// as part of a `build.rs` file, instead use [`compile_protos()`].
#[derive(Debug)]
pub struct ServiceGenerator {
builder: Builder,
clients: TokenStream,
servers: TokenStream,
}

impl ServiceGenerator {
fn new(builder: Builder) -> Self {
/// Create a new service generator from a configured builder, ready to be passed to
/// `prost_build`'s `Config::service_generator`.
pub fn new(builder: Builder) -> Self {
LucioFranco marked this conversation as resolved.
Show resolved Hide resolved
ServiceGenerator {
builder,
clients: TokenStream::default(),
Expand Down