rust-protobuf icon indicating copy to clipboard operation
rust-protobuf copied to clipboard

Codegen option to create module hierarchy

Open jeffparsons opened this issue 6 years ago • 4 comments

I'm working with hundreds of .proto files, so it's not practical for me to manually set up a module hierarchy to mirror the protobuf package hierarchy.

Some of these .proto files have the same name as others. So even if I did something in my build.rs like suggested here https://github.com/stepancheg/rust-protobuf/issues/324#issuecomment-476109276 then I'd still run into trouble with the output.

What I'd really like is an option in protobuf-codegen-pure (controlled via Customize) to automatically generate a directory hierarchy and Rust module hierarchy to match the protobuf package hierarchy. If you're open to the idea, I could take a swing at implementing this.

jeffparsons avatar Aug 03 '19 13:08 jeffparsons

Yes, I'm very open to this idea.

Also, I'm open to the idea of preserving the directory structure of .proto files same was as C++ does.

stepancheg avatar Sep 16 '19 02:09 stepancheg

Any updates on this? It would be quite useful.

Nub avatar Dec 20 '19 00:12 Nub

Either version should be done in rust-protobuf 3.

I'm inclined to implement C++/Java style, where foo/bar/baz.proto is generated to foo/bar/baz.rs. This is easier to implement, but also it solves several hard questions, like for example, how to generate code when multiple files declare the same package.

stepancheg avatar Aug 12 '20 17:08 stepancheg

Curious if this is now available in master -- It seems the src code of 2.18.1 and master differ quite a bit now.

Context -- I'm also working with hundreds of .proto files and I tried to manually mapping individual files into their respective paths with 2.18.1. It wasn't fully successful since it messes up the relative paths (eg ::super::).

Another issue I had to work around was having both foo.proto and foo subdirectory container more proto files, since the generated foo.rs and foo sub module would confuse Rust. Just surfacing that in case this has not been considered.

fiibbb avatar Dec 31 '20 01:12 fiibbb