prost
                                
                                 prost copied to clipboard
                                
                                    prost copied to clipboard
                            
                            
                            
                        prost-build: Idiomatic Code Generation
I prefer to generate code manually instead of in build.rs for readability and better IDE support. (rust-analyzer and Intellij both run into issues and instability , no matter the settings).
Currently code generation spits out files named after the Proto package, and creates a single file with the module hierarchy and include!()s.
I've written a little script to transform this into a normal Rust module hierarchy with the expected directory structure.
It would be nice to have this as an official setting in prost-build.
Happy to implement this if it would be accepted.
What do you rename the files too?
In addition, this is the approach I took for console to commit the generated code https://github.com/tokio-rs/console/tree/main/console-api/src
What do you rename the files too?
To the idiomatic rust structure you'd expect.
So package a.b.c  ends up looking like:
a/mod.rs  // pub mod b;
a/b/mod.rs // pub mod c;
a/b/c.rs // the generated "a.b.c.rs"
If support for manual code generation is a goal (which I do like), then it would also be nice to have a command line tool (such as pb-rs's binary, but for prost instead of quick-protobuf). If I understand right, prost-build doesn't provide a binary tool as of yet.
I might be missing something, but the source files generated now from proto files with complex package names (e.g. a.b.c) must be manually manipulated to be attached to a module (the dots cause compilation errors).
To me, this looked like an obvious bug but I tend to search through issues first :smile:
IMO, @theduke's proposal is necessary to isolate generated files and not worry about them after the build even in the standard build.rs approach. I.e:
- Generate a proto to a directory, e.g. ~/src/generated/
- Currently manual: create ~/src/generated/mod.rswithpub mod <name>for every file in that directory
- Add an entry of pub mod generatedto~/src/lib.rs
- Call it a library
Has there been any solution?
@theduke can you share your script?
there is already a solution https://github.com/tokio-rs/prost/issues/826