@@ -50,33 +50,35 @@ fn main() {
5050 println ! ( "cargo:rerun-if-changed=build.rs" ) ;
5151 println ! ( "cargo:rerun-if-env-changed=DFHACK_REGEN" ) ;
5252
53- let protoc = get_protoc ( ) ;
54-
55- let proto_include_dir = dfhack_proto_srcs:: include_dir ( ) ;
56- let protos = dfhack_proto_srcs:: protos ( ) ;
57-
58- assert ! ( !protos. is_empty( ) , "No protobuf file for code generation." ) ;
59-
60- // Generate in the sources if DFHACK_REGEN is set
61- // in OUT_DIR otherwise.
62- // TODO It should always be OUT_DIR, then expose macros.
63- let out_path = match std:: env:: var ( "DFHACK_REGEN" ) {
64- Ok ( _) => {
65- let dst = PathBuf :: from ( "src/generated" ) ;
66- if dst. exists ( ) {
67- std:: fs:: remove_dir_all ( & dst) . unwrap ( ) ;
53+ if std:: env:: var ( "DFHACK_REGEN" ) . is_ok ( ) {
54+ let protoc = get_protoc ( ) ;
55+
56+ let proto_include_dir = dfhack_proto_srcs:: include_dir ( ) ;
57+ let protos = dfhack_proto_srcs:: protos ( ) ;
58+
59+ assert ! ( !protos. is_empty( ) , "No protobuf file for code generation." ) ;
60+
61+ // Generate in the sources if DFHACK_REGEN is set
62+ // in OUT_DIR otherwise.
63+ // TODO It should always be OUT_DIR, then expose macros.
64+ let out_path = match std:: env:: var ( "DFHACK_REGEN" ) {
65+ Ok ( _) => {
66+ let dst = PathBuf :: from ( "src/generated" ) ;
67+ if dst. exists ( ) {
68+ std:: fs:: remove_dir_all ( & dst) . unwrap ( ) ;
69+ }
70+ std:: fs:: create_dir_all ( & dst) . unwrap ( ) ;
71+ dst
6872 }
69- std:: fs:: create_dir_all ( & dst) . unwrap ( ) ;
70- dst
71- }
72- Err ( _) => PathBuf :: from ( std:: env:: var ( "OUT_DIR" ) . unwrap ( ) ) ,
73- } ;
73+ Err ( _) => PathBuf :: from ( std:: env:: var ( "OUT_DIR" ) . unwrap ( ) ) ,
74+ } ;
7475
75- // Generate the protobuf message files
76- generate_messages_rs ( & protoc, & protos, proto_include_dir, & out_path) ;
76+ // Generate the protobuf message files
77+ generate_messages_rs ( & protoc, & protos, proto_include_dir, & out_path) ;
7778
78- // Generate the plugin stubs
79- generate_stubs_rs ( & protos, & out_path)
79+ // Generate the plugin stubs
80+ generate_stubs_rs ( & protos, & out_path)
81+ }
8082}
8183
8284fn get_protoc ( ) -> PathBuf {
@@ -101,13 +103,14 @@ fn messages_protoc_codegen(
101103) {
102104 prost_build:: Config :: new ( )
103105 . enable_type_names ( )
106+ . type_attribute ( "." , "#[derive(serde::Serialize)]" )
104107 . protoc_executable ( protoc)
105108 . out_dir ( out_path)
106109 . compile_protos ( protos, & [ include_dir] )
107110 . unwrap ( ) ;
108111}
109112
110- fn generate_stubs_rs ( protos : & Vec < PathBuf > , out_path : & Path ) {
113+ fn generate_stubs_rs ( protos : & [ PathBuf ] , out_path : & Path ) {
111114 let plugins = read_protos_rpcs ( protos) ;
112115 let mut out_path = out_path. to_path_buf ( ) ;
113116 out_path. push ( "stubs" ) ;
@@ -173,7 +176,6 @@ fn generate_stubs_mod_rs(plugins: &Vec<Plugin>, file: &mut TokenStream) {
173176 #plugins_impl
174177 }
175178
176- #[ cfg( feature = "reflection" ) ]
177179 impl <TChannel : crate :: Channel > crate :: reflection:: StubReflection for Stubs <TChannel > {
178180 fn list_methods( ) -> Vec <crate :: reflection:: RemoteProcedureDescriptor > {
179181 let mut methods = Vec :: new( ) ;
@@ -323,7 +325,6 @@ fn generate_stub_rs(plugin: &Plugin, file: &mut TokenStream) {
323325 #plugin_impl
324326 }
325327
326- #[ cfg( feature = "reflection" ) ]
327328 impl <TChannel : crate :: Channel > crate :: reflection:: StubReflection for #struct_ident<' _, TChannel > {
328329 fn list_methods( ) -> Vec <crate :: reflection:: RemoteProcedureDescriptor > {
329330 vec![
@@ -334,7 +335,7 @@ fn generate_stub_rs(plugin: &Plugin, file: &mut TokenStream) {
334335 } ) ;
335336}
336337
337- fn read_protos_rpcs ( protos : & Vec < PathBuf > ) -> Vec < Plugin > {
338+ fn read_protos_rpcs ( protos : & [ PathBuf ] ) -> Vec < Plugin > {
338339 let mut plugins = HashMap :: < String , Plugin > :: new ( ) ;
339340
340341 for proto in protos {
0 commit comments