@@ -32,7 +32,7 @@ fn main() -> miette::Result<()> {
3232 ] ;
3333
3434 for file_descriptors in & descriptor_sets {
35- generate_bindings ( file_descriptors. clone ( ) , & dst_dir) ?;
35+ generate_bindings ( file_descriptors, & dst_dir) ?;
3636 }
3737
3838 let server_dst_dir = dst_dir. join ( "server" ) ;
@@ -54,14 +54,19 @@ fn main() -> miette::Result<()> {
5454
5555/// Generates protobuf bindings from the given file descriptor set and stores them in the given
5656/// destination directory.
57- fn generate_bindings ( file_descriptors : FileDescriptorSet , dst_dir : & Path ) -> miette:: Result < ( ) > {
57+ fn generate_bindings ( file_descriptors : & FileDescriptorSet , dst_dir : & Path ) -> miette:: Result < ( ) > {
5858 let mut prost_config = tonic_prost_build:: Config :: new ( ) ;
5959 prost_config. skip_debug ( [ "AccountId" , "Digest" ] ) ;
6060
6161 // Generate the stub of the user facing server from its proto file
6262 tonic_prost_build:: configure ( )
63+ . server_mod_attribute ( "." , "#[allow(deprecated, clippy::mixed_attributes_style)]" )
64+ . server_attribute (
65+ "." ,
66+ r#"#[deprecated(note = "use the service constructors in `miden_node_proto::server` instead")]"# ,
67+ )
6368 . out_dir ( dst_dir)
64- . compile_fds_with_config ( file_descriptors, prost_config)
69+ . compile_fds_with_config ( file_descriptors. clone ( ) , prost_config)
6570 . into_diagnostic ( )
6671 . wrap_err ( "compiling protobufs" ) ?;
6772
@@ -216,6 +221,8 @@ impl Service {
216221 fn generate ( & self ) -> Module {
217222 let mut module = Module :: new ( & self . name ) ;
218223
224+ module. push_fn ( self . service_constructor ( ) ) ;
225+ module. push_fn ( self . service_name ( ) ) ;
219226 module. push_trait ( self . service_trait ( ) ) ;
220227 module. push_impl ( self . blanket_impl ( ) ) ;
221228 module. push_impl ( self . tonic_impl ( ) ) ;
@@ -302,12 +309,7 @@ impl Service {
302309 /// }
303310 /// ```
304311 fn tonic_impl ( & self ) -> Impl {
305- let tonic_path = format ! (
306- "crate::generated::{}::{}_server::{}" ,
307- self . package,
308- to_snake_case( & self . name) ,
309- self . name
310- ) ;
312+ let tonic_path = self . tonic_trait_path ( ) ;
311313
312314 let mut ret = Impl :: new ( "T" ) ;
313315 ret. generic ( "T" )
@@ -329,6 +331,60 @@ impl Service {
329331
330332 ret
331333 }
334+
335+ /// Constructs the underlying tonic server for this service behind an opaque tower service type.
336+ fn service_constructor ( & self ) -> Function {
337+ let mut ret = Function :: new ( "service" ) ;
338+ ret. vis ( "pub" )
339+ . attr ( "allow(deprecated)" )
340+ . generic ( "T" )
341+ . arg ( "service" , "T" )
342+ . ret (
343+ "impl tower::Service<
344+ http::Request<tonic::body::Body>,
345+ Response = http::Response<tonic::body::Body>,
346+ Error = std::convert::Infallible,
347+ Future: Send + 'static,
348+ > + tonic::server::NamedService
349+ + Clone
350+ + Send
351+ + Sync
352+ + 'static" ,
353+ )
354+ . bound ( "T" , self . service_trait ( ) . ty ( ) )
355+ . bound ( "T" , "Send" )
356+ . bound ( "T" , "Sync" )
357+ . bound ( "T" , "'static" )
358+ . line ( format ! ( "{}::new(service)" , self . tonic_server_path( ) ) ) ;
359+
360+ ret
361+ }
362+
363+ /// Returns the gRPC service name used by tonic routing and health reporting.
364+ fn service_name ( & self ) -> Function {
365+ let mut ret = Function :: new ( "service_name" ) ;
366+ ret. vis ( "pub" ) . attr ( "allow(deprecated)" ) . ret ( "&'static str" ) . line ( format ! (
367+ "<{}::<()> as tonic::server::NamedService>::NAME" ,
368+ self . tonic_server_path( )
369+ ) ) ;
370+
371+ ret
372+ }
373+
374+ /// Returns the full path to the service's trait.
375+ fn tonic_trait_path ( & self ) -> String {
376+ format ! (
377+ "crate::generated::{}::{}_server::{}" ,
378+ self . package,
379+ to_snake_case( & self . name) ,
380+ self . name
381+ )
382+ }
383+
384+ /// Returns the full path to the generated server struct.
385+ fn tonic_server_path ( & self ) -> String {
386+ format ! ( "{}Server" , self . tonic_trait_path( ) )
387+ }
332388}
333389
334390impl UnaryMethod {
0 commit comments