-
Notifications
You must be signed in to change notification settings - Fork 382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protoc-gen-rust does not follow common file placement conventions #189
Comments
Maybe it could be added as an option. It would be nice to output files as |
I'd second this request although I'm currently working around it. |
|
name_pb would have some interesting side effects. At the very least you'd have to change how you import other protos, since the file name is the same as the name of the module its contents live in. As an "update" to this, I actually had to do a lot more shenanigans to the generated files to get them to play nice in bazel. I use my own little fork for now, and perform the following additional transformations after the fact using an external script:
This impl is against some pretty ancient rust-protobuf though. EDIT: I remember why super is dropped. At the time (and maybe now too), rust-protobuf assumed that it was compiled using a build.rs, with generated protos living in the same "module". Therefore, all other proto deps were implicitly available in EDIT EDIT: The "ex post facto use" is mandatory, as the generated file uses crate attributes, which have to come before any use statements. |
I'm not sure you need to drop
Crate
and after that So basially all imported Or, better, bazel could simply generate file likes
So each proto file Am I missing something? |
And another idea. Probably rust-protobuf could have another generator next to Instead of importing files as |
Ah I think you are missing something (that I forgot until now). The reason I cannot use "super::*" is because using that would pollute the extern-ed namespace of the root crate. That is to say, the following scenario is not possible if you
This is caused by the bulk import of proto dependencies (pub use my_dep_proto::*). You end up with a namespace collision on proto_dep_3. In my example, i've nestled the generated code into a geneated module to hide the module's own proto deps. That said, I need to completely review the rest of your post, and also the current state of the project. Thanks for your reply! |
Do you mean that you want to deal with two different |
I mean that I have three totally separate generated crates -- proto_dep_1, proto_dep_2 and proto_dep_3. proto_dep_1 is my actual target, but it transitively depends on proto_dep_3 twice: once for itself, and once through proto_dep_2. This causes a namespace collision when the contents of proto_dep_3 are resolved within proto_dep_1: a given proto_dep_3::Proto could come in via proto_dep_2::* or from proto_dep_3::*. Let me furnish a real world example. |
Do I understand correctly that That shouldn't be right. When compiling |
Ah, so its not "compiled" three times. Rather, the reference to the inner module of //../game_proto ("game_proto" again i think), is ambiguous. That is to say, in the default implementation at the time of writing, the outer module of network_proto would be re-exporting game_proto due to its Then when it comes time for state_proto's outer module to go and fetch the It boils down to each generated mod.rs |
I think this actually may be an artifact of my own solution to avoiding super::*, not something intrinsic to rust-protobuf. Let me review this code and come back with either a more concrete set of facts, or a pull request. Thanks again for your time in responding. |
@stepancheg do you have a solution for that scenario? It seems like right now rust-protobuf will overwrite the earlier generated |
Would we be able to use an option to add support in a backwards-compatible way, analogous to these changes to the go_package option? |
@jbowens yes, definitely we could have options to
|
I would appreciate this being merged. Working in a mono repo without this is very much harder with the current output placement of files. |
Someone needs to implement it first :) I'd like to do it, but honestly it's unlikely I will have time to do that change soon. As I said, if should be first implemented as option, and some time later probably made default. |
I can put up a PR some time soon with this change, but I need to learn how to pass configuration options through |
It's not easily possible to pass configurations directly through However, there are two ways: First,option can be specified in Another optionis to pass options to rust cogegen when codegen is invoked from E. g. user could write in
This way of passing options is not implemented yet, but it is relatively easy to implement, and need to be implemented anyway. This works because |
Ah this is news to me! I use the protoc_gen_rust binary directly with protoc to generate my rust and haven't noticed any issues. Are you planning to deprecate this usage? Regarding passing data directly through |
Probably not, because this is the way Google recommends using protobuf. However, readme of rust-protobuf project recommends using
I don't recall if any protobuf implementation for other languages uses this mechanism, and this is probably inconvenient, but yes, this also works. So, I think, there shoud be three ways of passing parameters to code generator:
And all three alternatives should support exactly the same set of options. |
is there any solution today? |
I'm encountering this as well, as I'm trying to retain a similar module hierarchy to that of the directory tree all source .proto files are structured in my project. Why should flattening generated files into a single directory ever be the default behavior? How are folks working around this issue today? |
API significantly changes in the last two years. Closing due to old age. Please reopen if you have suggestions before rust-protobuf=3 released. |
Instead of outputting *.rs files to the "conventional" (per cpp, go, and python) directories -- relative to the source proto files -- the generated files are placed relative to the command invocation site.
When I run the following example command:
Instead of
We see
A more complete example with several generators:
It appears that only we and the Java rules break from "convention".
I understand this change would likely break many existing users, so I'd understand if this change was rejected for that reason. Example short change diff
EDIT:
To clarify, the primary reason this is an issue for me (and hasn't been for anyone else yet presumably) is because I'm using this protoc extension with bazel instead of cargo+build.rs file, specifically the rules_protobuf "library". That library has an expectation built in that generated source files are placed in a directory structure adjacent to the underlying proto files. It seems that assumption holds for all protoc-gen-* except us and java.
The text was updated successfully, but these errors were encountered: