@@ -19,6 +19,7 @@ pub fn configure() -> Builder {
1919 proto_path : "super" . to_string ( ) ,
2020 #[ cfg( feature = "rustfmt" ) ]
2121 format : true ,
22+ emit_package : true ,
2223 }
2324}
2425
@@ -136,12 +137,20 @@ impl ServiceGenerator {
136137impl prost_build:: ServiceGenerator for ServiceGenerator {
137138 fn generate ( & mut self , service : prost_build:: Service , _buf : & mut String ) {
138139 if self . builder . build_server {
139- let server = server:: generate ( & service, & self . builder . proto_path ) ;
140+ let server = server:: generate (
141+ & service,
142+ self . builder . emit_package ,
143+ & self . builder . proto_path ,
144+ ) ;
140145 self . servers . extend ( server) ;
141146 }
142147
143148 if self . builder . build_client {
144- let client = client:: generate ( & service, & self . builder . proto_path ) ;
149+ let client = client:: generate (
150+ & service,
151+ self . builder . emit_package ,
152+ & self . builder . proto_path ,
153+ ) ;
145154 self . clients . extend ( client) ;
146155 }
147156 }
@@ -184,6 +193,7 @@ pub struct Builder {
184193 pub ( crate ) field_attributes : Vec < ( String , String ) > ,
185194 pub ( crate ) type_attributes : Vec < ( String , String ) > ,
186195 pub ( crate ) proto_path : String ,
196+ pub ( crate ) emit_package : bool ,
187197
188198 out_dir : Option < PathBuf > ,
189199 #[ cfg( feature = "rustfmt" ) ]
@@ -258,6 +268,14 @@ impl Builder {
258268 self
259269 }
260270
271+ /// Emits GRPC endpoints with no attached package. Effectively ignores protofile package declaration from grpc context.
272+ ///
273+ /// This effectively sets prost's exported package to an empty string.
274+ pub fn disable_package_emission ( mut self ) -> Self {
275+ self . emit_package = false ;
276+ self
277+ }
278+
261279 /// Compile the .proto files and execute code generation.
262280 pub fn compile < P > ( self , protos : & [ P ] , includes : & [ P ] ) -> io:: Result < ( ) >
263281 where
0 commit comments