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

[grpc-protoc] Add an option to generate default service methods #3110

Merged

Conversation

mgodave
Copy link
Contributor

@mgodave mgodave commented Nov 15, 2024

Motivation

When evolving a service definition that has multiple implementations it is ideal not to break these implementations. Therefore it would be nice if the protoc generator was able to generate default implementations on the service interface to ensure implementations always conform.

Changes

Add an option, defaultServiceMethods to the grpc-protoc stub compiler to generate these default implementation. The result is that service interfaces will provide a default, throwing, implementation of all service RPC interfaces that they implement.

test_service.proto: https://gist.github.com/mgodave/d9064c67da9f365de70ef7526c9eea72

…d code (apple#3089)

### Motivation

The generated ServiceTalk gRPC stubs make use of deprecated calls. This causes a problem when `-Werror` is used to build the code since it will automatically fail the build. We should allow users who have already migrated their code to prevent the protoc compiler from generating and using deprecated references.

### Modifications

Add an option, `skipDeprecated`, as part of the protoc compiler configuration, to tell the generator to leave out deprecated references.

Remove
- initSerializationProvider, reason: ContentCodec is deprecated
- isSupportedMessageCodingsEmpty, reason ContentCodec is deprecated
- Deprecated ServiceFactory constructors
- ServiceFactory::Builder references to ContentCodec
- Generated client metadata and associated methods, reason: deprecated

### Result

Users can generate gRPC stubs without deprecated code.

### Testing

Manually tested:
- Add new option to ServiceTalk/examples/grpc/protoc-options and use it to generate test_service.proto which covers all combinations of streaming (or not) services.
@mgodave mgodave force-pushed the drusek/default-service-implementations branch from d8de863 to 7ed1fe5 Compare November 19, 2024 18:52
Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

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

New findings:

Copy link
Contributor

@bryce-anderson bryce-anderson left a comment

Choose a reason for hiding this comment

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

Take my review with a grain of salt, but it seems good to me.

Copy link
Member

@idelpivnitskiy idelpivnitskiy left a comment

Choose a reason for hiding this comment

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

Pushed minor style corrections into your branch: 80b53a4
Everything looks good, great work!

@idelpivnitskiy idelpivnitskiy merged commit 1bcf8ea into apple:main Dec 7, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants