Skip to content
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

Allow the gRPC module name to be customised when generating code #945

Merged
merged 4 commits into from
Aug 19, 2020

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented Aug 19, 2020

Motivation:

Some Cocoapods may find themselves in a situation where their dependency
graph contains both gRPC Swift and the gRPC core library. This is
problematic since both have the same module name ("GRPC"). Changing our
own module name is a very large breaking change and one we'd like to avoid.
As an escape valve, users who take a direct dependency on us may rename
our module via their Podfile; doing so would require their generated
code to depend on that module, rather than the currently hardcoded
'GRPC' module.

Modifications:

  • Add an option to the codegen to specify the gRPC module name
  • Remove a couple of imports which were previously used but are now no
    longer required
  • Regenerate

Result:

It's possible for Cocoapods users to take a direct dependency on gRPC
Swift and libgrpc.

@glbrntt glbrntt requested a review from MrMage August 19, 2020 08:49
@glbrntt glbrntt added cocoapods Relates to CocoaPods codegen Relates to the protoc-gen-grpc-swift plugin semver-patch • Requires a SemVer Patch version change labels Aug 19, 2020
@glbrntt glbrntt marked this pull request as draft August 19, 2020 08:49
@glbrntt glbrntt force-pushed the gb-custom-codegen-module-name branch from 7b04aa8 to 82c6f7b Compare August 19, 2020 09:02
@glbrntt glbrntt marked this pull request as ready for review August 19, 2020 09:39
Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please also document this in https://github.com/grpc/grpc-swift/blob/main/docs/plugin.md?

@MrMage
Copy link
Collaborator

MrMage commented Aug 19, 2020

This "fixes #915." If you encounter conflicting module names, please follow this process:

  1. Download our current Podspec from https://github.com/grpc/grpc-swift/raw/main/gRPC-Swift.podspec and place it next to your Podfile.
  2. In the downloaded gRPC-Swift.podspec, replace s.module_name = 'GRPC' with s.module_name = 'GRPC_Swift'.
  3. Include the dependency in your Podfile as follows: pod 'gRPC-Swift', :podspec => 'gRPC-Swift.podspec'
  4. Change your protobuf codegen script to include --grpc-swift_out=GRPCModuleName=GRPC_Swift in your options (or append it to the end of an existing config string).

Whenever we tag a new release, I'm afraid you will need to repeat steps 1 and 2 (or manually increment s.version in gRPC-Swift.podspec).

@glbrntt glbrntt requested a review from MrMage August 19, 2020 09:52
Copy link
Collaborator

@MrMage MrMage left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. I wonder whether we should also include the steps from my comment, WDYT?

@glbrntt
Copy link
Collaborator Author

glbrntt commented Aug 19, 2020

Looks good. I wonder whether we should also include the steps from my comment, WDYT?

If anything I'd think they should be included in the README, I suspect If someone hits this they might search the README but will be unlikely to look in the plugin docs.

Motivation:

Some Cocoapods may find themselves in a situation where their dependency
graph contains both gRPC Swift and the gRPC core library. This is
problematic since both have the same module name ("GRPC"). Changing our
own module name is a very large breaking change and one we'd like to avoid.
As an escape valve, users who take a direct dependency on us may rename
our module via their Podfile; doing so would require their generated
code to depend on that module, rather than the currently hardcoded
'GRPC' module.

Modifications:

- Add an option to the codegen to specify the gRPC module name
- Remove a couple of imports which were previously used but are now no
  longer require
- Regenerate

Result:

It's possible for Cocoapods users to take a direct dependency on gRPC
Swift and libgrpc.
@MrMage
Copy link
Collaborator

MrMage commented Aug 19, 2020

If anything I'd think they should be included in the README, I suspect If someone hits this they might search the README but will be unlikely to look in the plugin docs.

Fine with me as well. Maybe just mention in the README to look here when encountering this particular issue?

@glbrntt glbrntt force-pushed the gb-custom-codegen-module-name branch from c30099b to 9a6012b Compare August 19, 2020 12:22
@glbrntt glbrntt merged commit 8b5d7d9 into grpc:main Aug 19, 2020
@glbrntt glbrntt deleted the gb-custom-codegen-module-name branch August 19, 2020 13:18
@vlopezferrando
Copy link

This "fixes #915." If you encounter conflicting module names, please follow this process:

1. Download our current Podspec from https://github.com/grpc/grpc-swift/raw/main/gRPC-Swift.podspec and place it next to your `Podfile`.

2. In the downloaded `gRPC-Swift.podspec`, replace `s.module_name = 'GRPC'` with `s.module_name = 'GRPC_Swift'`.

3. Include the dependency in your Podfile as follows: `pod 'gRPC-Swift', :podspec => 'gRPC-Swift.podspec'`

4. Change your protobuf codegen script to include `--grpc-swift_out=GRPCModuleName=GRPC_Swift` in your options (or append it to the end of an existing config string).

Whenever we tag a new release, I'm afraid you will need to repeat steps 1 and 2 (or manually increment s.version in gRPC-Swift.podspec).

Please note that the option for protobuf codegen is --grpc-swift_opt=... and not --grpc-swift_out.

@nshoura
Copy link

nshoura commented Dec 7, 2020

Hello everyone,

How can the mentioned solution work when gRPC-Swift is used as a dependency for another pod since, in podspec files, it's only allowed to define the name and the version specifier of a Pod?
Basically, the following isn't valid:
s.dependency 'gRPC-Swift', :podspec => 'gRPC-Swift.podspec'

@Artfire
Copy link

Artfire commented Apr 19, 2021

@nshoura
Hi,
Did you solve this issue? I faced with the same issue and could't not find any solutions.
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cocoapods Relates to CocoaPods codegen Relates to the protoc-gen-grpc-swift plugin semver-patch • Requires a SemVer Patch version change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants