-
Notifications
You must be signed in to change notification settings - Fork 435
do not add own module import in generated code #796
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
do not add own module import in generated code #796
Conversation
| // mappings to import the service protos as well as and any other proto modules that the file | ||
| // imports. | ||
| let moduleMappings = options.protoToModuleMappings | ||
| if let serviceProtoModuleName = moduleMappings.moduleName(forFile: file) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cc @allevato who added this originally (#347)
My understanding of the comment above is that if we have a foo.proto containing:
service FooService { ... }
message FooMessage { ... }Then Bazel would produce two Swift modules, say FooServices and FooMessages; and this line is to import the FooMessages module.
If my understanding of this is correct this seems like a misuse of module mappings since the output generated from a single proto is split across multiple modules. Using it in this way also leads to an unnecessary warning if you want to use module mappings in the intended way. Can this be better expressed in the Bazel rules as an additional import instead of module mappings?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct about the original motivation; the Bazel rule swift_proto_library generates just the code for the messages, the rule swift_grpc_library generates just the code for the services, and they're in separate modules so the latter needs to import the former.
The ExtraModuleImports flag was added in #402 (after my original change) to support getting the right imports for client stubs, so that wasn't an option when we first spun up Bazel support. But looking at the rule implementation again (it's been a while), I think it should be a straightforward change to use ExtraModuleImports in the same way here, so I don't foresee a problem with this change; we'll just need to update the rules when we update to this version.
cc @mpetrov for awareness as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, thanks very much.
As a heads up: this is change is for protoc-gen-grpc-swift (gRPC Swift 1.x); protoc-gen-swiftgrpc (gRPC Swift 0.x) won't be affected.
…d an import for its own module
glbrntt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @jagobagascon!
When generating a file using the option
ProtoPathModuleMappingsthe module of the generated proto is being added to the header of the file.swift mappings file:
a.grpc.swift (generated from a.proto that depends on b.proto)