Skip to content

Commit

Permalink
tonic-build: support boxing fields
Browse files Browse the repository at this point in the history
This exposes tokio-rs/prost#802 in Tonic,
though obviously until that's merged and released this diff does
nothing.
  • Loading branch information
krallin committed Jan 25, 2023
1 parent ff642f9 commit 08f44c0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions tonic-build/src/prost.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub fn configure() -> Builder {
message_attributes: Vec::new(),
enum_attributes: Vec::new(),
type_attributes: Vec::new(),
boxed: Vec::new(),
server_attributes: Attributes::default(),
client_attributes: Attributes::default(),
proto_path: "super".to_string(),
Expand Down Expand Up @@ -229,6 +230,7 @@ pub struct Builder {
pub(crate) type_attributes: Vec<(String, String)>,
pub(crate) message_attributes: Vec<(String, String)>,
pub(crate) enum_attributes: Vec<(String, String)>,
pub(crate) boxed: Vec<String>,
pub(crate) server_attributes: Attributes,
pub(crate) client_attributes: Attributes,
pub(crate) proto_path: String,
Expand Down Expand Up @@ -332,6 +334,14 @@ impl Builder {
self
}

/// Add additional boxed fields.
///
/// Passed directly to `prost_build::Config.boxed`.
pub fn boxed<P: AsRef<str>>(mut self, path: P) -> Self {
self.boxed.push(path.as_ref().to_string());
self
}

/// Add additional attribute to matched server `mod`s. Matches on the package name.
pub fn server_mod_attribute<P: AsRef<str>, A: AsRef<str>>(
mut self,
Expand Down Expand Up @@ -479,6 +489,9 @@ impl Builder {
for (prost_path, attr) in self.enum_attributes.iter() {
config.enum_attribute(prost_path, attr);
}
for prost_path in self.boxed.iter() {
config.boxed(prost_path);
}
if self.compile_well_known_types {
config.compile_well_known_types();
}
Expand Down

0 comments on commit 08f44c0

Please sign in to comment.