@@ -4,8 +4,6 @@ use std::{collections::HashMap, io::BufRead, path::PathBuf};
44
55use heck:: { ToPascalCase , ToSnakeCase } ;
66use proc_macro2:: TokenStream ;
7- use prost:: Message ;
8- use prost_types:: FileDescriptorSet ;
97use quote:: format_ident;
108use quote:: quote;
119use quote:: ToTokens ;
@@ -75,10 +73,10 @@ fn main() {
7573 } ;
7674
7775 // Generate the protobuf message files
78- let fd = generate_messages_rs ( & protoc, & protos, proto_include_dir, & out_path) ;
76+ generate_messages_rs ( & protoc, & protos, proto_include_dir, & out_path) ;
7977
8078 // Generate the plugin stubs
81- generate_stubs_rs ( & fd , & protos, & out_path)
79+ generate_stubs_rs ( & protos, & out_path)
8280}
8381
8482fn get_protoc ( ) -> PathBuf {
@@ -87,17 +85,11 @@ fn get_protoc() -> PathBuf {
8785 protoc_fetcher:: protoc ( protoc_version, Path :: new ( & out_dir) ) . unwrap ( )
8886}
8987
90- fn generate_messages_rs (
91- protoc : & PathBuf ,
92- protos : & [ PathBuf ] ,
93- include_dir : & str ,
94- out_path : & Path ,
95- ) -> FileDescriptorSet {
88+ fn generate_messages_rs ( protoc : & PathBuf , protos : & [ PathBuf ] , include_dir : & str , out_path : & Path ) {
9689 let mut out_path = out_path. to_path_buf ( ) ;
9790 out_path. push ( "messages" ) ;
9891 std:: fs:: create_dir_all ( & out_path) . unwrap ( ) ;
99- messages_protoc_codegen ( protoc, protos, include_dir, & out_path)
100- //messages_generate_mod_rs(protos, &out_path);
92+ messages_protoc_codegen ( protoc, protos, include_dir, & out_path) ;
10193}
10294
10395// Call the protoc code generation
@@ -106,20 +98,16 @@ fn messages_protoc_codegen(
10698 protos : & [ PathBuf ] ,
10799 include_dir : & str ,
108100 out_path : & Path ,
109- ) -> FileDescriptorSet {
110- let mut prost = prost_build:: Config :: new ( ) ;
111- let fd = PathBuf :: from ( env:: var ( "OUT_DIR" ) . expect ( "OUT_DIR environment variable not set" ) )
112- . join ( "file_descriptor_set.bin" ) ;
113- prost. protoc_executable ( protoc) ;
114- prost. file_descriptor_set_path ( & fd) ;
115- prost. out_dir ( out_path) ;
116- prost. compile_protos ( protos, & [ include_dir] ) . unwrap ( ) ;
117-
118- let fd = std:: fs:: read ( fd) . unwrap ( ) ;
119- prost_types:: FileDescriptorSet :: decode ( fd. as_slice ( ) ) . unwrap ( )
101+ ) {
102+ prost_build:: Config :: new ( )
103+ . enable_type_names ( )
104+ . protoc_executable ( protoc)
105+ . out_dir ( out_path)
106+ . compile_protos ( protos, & [ include_dir] )
107+ . unwrap ( ) ;
120108}
121109
122- fn generate_stubs_rs ( fd : & FileDescriptorSet , protos : & Vec < PathBuf > , out_path : & Path ) {
110+ fn generate_stubs_rs ( protos : & Vec < PathBuf > , out_path : & Path ) {
123111 let plugins = read_protos_rpcs ( protos) ;
124112 let mut out_path = out_path. to_path_buf ( ) ;
125113 out_path. push ( "stubs" ) ;
@@ -129,7 +117,7 @@ fn generate_stubs_rs(fd: &FileDescriptorSet, protos: &Vec<PathBuf>, out_path: &P
129117 generate_stubs_mod_rs ( & plugins, & mut file) ;
130118
131119 for plugin in & plugins {
132- generate_stub_rs ( fd , plugin, & mut file) ;
120+ generate_stub_rs ( plugin, & mut file) ;
133121 }
134122
135123 let mut mod_rs_path = out_path. clone ( ) ;
@@ -145,6 +133,7 @@ fn generate_stubs_mod_rs(plugins: &Vec<Plugin>, file: &mut TokenStream) {
145133
146134 file. extend ( quote ! {
147135 use crate :: messages:: * ;
136+ use prost:: Name ;
148137 } ) ;
149138
150139 let mut reflection_vec_building = quote ! ( ) ;
@@ -195,18 +184,7 @@ fn generate_stubs_mod_rs(plugins: &Vec<Plugin>, file: &mut TokenStream) {
195184 } ) ;
196185}
197186
198- fn get_full_name ( fd : & FileDescriptorSet , message_name : & str ) -> String {
199- for file in & fd. file {
200- for message_type in & file. message_type {
201- if message_type. name ( ) == message_name {
202- return format ! ( "{}.{}" , file. package( ) , message_type. name( ) ) ;
203- }
204- }
205- }
206- panic ! ( "Could not find {}" , message_name) ;
207- }
208-
209- fn generate_stub_rs ( fd : & FileDescriptorSet , plugin : & Plugin , file : & mut TokenStream ) {
187+ fn generate_stub_rs ( plugin : & Plugin , file : & mut TokenStream ) {
210188 let plugin_name = & plugin. plugin_name ;
211189 let plugin_doc = format ! ( "RPC for the \" {}\" plugin." , plugin_name) ;
212190 let struct_ident = plugin. struct_ident . clone ( ) ;
@@ -238,9 +216,6 @@ fn generate_stub_rs(fd: &FileDescriptorSet, plugin: &Plugin, file: &mut TokenStr
238216 let input_ident = format_ident ! ( "{}" , rpc. input) ;
239217 let output_ident = format_ident ! ( "{}" , rpc. output) ;
240218
241- let input_full_name = get_full_name ( fd, & rpc. input ) ;
242- let output_full_name = get_full_name ( fd, & rpc. output ) ;
243-
244219 let mut return_token = output_ident. to_token_stream ( ) ;
245220
246221 let mut parameters = quote ! {
@@ -337,8 +312,8 @@ fn generate_stub_rs(fd: &FileDescriptorSet, plugin: &Plugin, file: &mut TokenStr
337312 crate :: reflection:: RemoteProcedureDescriptor {
338313 name: #function_name,
339314 plugin_name: #plugin_name,
340- input_type: #input_full_name ,
341- output_type: #output_full_name ,
315+ input_type: #input_ident :: full_name ( ) ,
316+ output_type: #output_ident :: full_name ( ) ,
342317 } ,
343318 } ) ;
344319 }
@@ -379,9 +354,6 @@ fn read_protos_rpcs(protos: &Vec<PathBuf>) -> Vec<Plugin> {
379354
380355 plugins. sort_by ( |a, b| a. plugin_name . cmp ( & b. plugin_name ) ) ;
381356
382- dbg ! ( plugins) ;
383- panic ! ( ) ;
384-
385357 plugins
386358}
387359
0 commit comments