feat(build): Add disable_package_emission option to tonic-build (#556)

This commit is contained in:
Max Bruce
2021-02-12 10:59:44 -05:00
committed by GitHub
parent ca3b9a1df1
commit 4f5e160679
3 changed files with 30 additions and 19 deletions
+20 -2
View File
@@ -19,6 +19,7 @@ pub fn configure() -> Builder {
proto_path: "super".to_string(),
#[cfg(feature = "rustfmt")]
format: true,
emit_package: true,
}
}
@@ -136,12 +137,20 @@ impl ServiceGenerator {
impl prost_build::ServiceGenerator for ServiceGenerator {
fn generate(&mut self, service: prost_build::Service, _buf: &mut String) {
if self.builder.build_server {
let server = server::generate(&service, &self.builder.proto_path);
let server = server::generate(
&service,
self.builder.emit_package,
&self.builder.proto_path,
);
self.servers.extend(server);
}
if self.builder.build_client {
let client = client::generate(&service, &self.builder.proto_path);
let client = client::generate(
&service,
self.builder.emit_package,
&self.builder.proto_path,
);
self.clients.extend(client);
}
}
@@ -184,6 +193,7 @@ pub struct Builder {
pub(crate) field_attributes: Vec<(String, String)>,
pub(crate) type_attributes: Vec<(String, String)>,
pub(crate) proto_path: String,
pub(crate) emit_package: bool,
out_dir: Option<PathBuf>,
#[cfg(feature = "rustfmt")]
@@ -258,6 +268,14 @@ impl Builder {
self
}
/// Emits GRPC endpoints with no attached package. Effectively ignores protofile package declaration from grpc context.
///
/// This effectively sets prost's exported package to an empty string.
pub fn disable_package_emission(mut self) -> Self {
self.emit_package = false;
self
}
/// Compile the .proto files and execute code generation.
pub fn compile<P>(self, protos: &[P], includes: &[P]) -> io::Result<()>
where