-
Notifications
You must be signed in to change notification settings - Fork 6
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
Code generation package plugins #26
Open
rnro
wants to merge
1
commit into
main
Choose a base branch
from
package_plugins
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
c911f1a
to
454684d
Compare
Motivation: To make code generation more convenient for adopters. Modifications: * New build plugin to generate gRPC services and protobuf messages * New command plugin e.g. `swift package generate-grpc-code-from-protos Sources/Protos/HelloWorld.proto` * Integration tests (incomplete) This PR also includes a change to `protoc-gen-grpc-swift` itself: * Generate an empty file if no gRPC services are found in the protobuf definition file. This is required by the build plugin which needs deterministic outputs and matches the behavior of `protoc-gen-swift`. Result: * Users will be able to make use of the build and command plugins. * `protoc-gen-grpc-swift` will Generate an empty file if no gRPC services are found in the protobuf definition file.
glbrntt
requested changes
Jan 6, 2025
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 @rnro, really excited for this. To make the review a bit easier could you split it up into multiple PRs? I think we probably want the following PRs at a minimum:
- Changes to
protoc-gen-grpc-swift
- Build plugin
- Command plugin
- Integration tests
glbrntt
pushed a commit
that referenced
this pull request
Jan 7, 2025
This change is broken out of #26 ### Motivation To prepare for use in a SwiftPM build plugin which requires deterministic output files and to match the behavior of `proto-gen-swift` we should generate a source file even if no definitions are found. ### Modifications: * We no longer return early in the case of no definitions being found. * Add empty proto file test * Add a preamble to `foo-messages.proto` * Don't unconditionally add a dependency on `GRPCProtobuf` if there are no services * Add the new test case code generation to `dev/protos/generate.sh` * Depend on `grpc-swift` `main` to pick up empty file generation changes. ### Result: We will generate a Swift source file even if no definitions are found.
This was referenced Jan 24, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Overview
e.g.
swift package generate-grpc-code-from-protos Sources/Protos/HelloWorld.proto
This PR also includes a change to
protoc-gen-grpc-swift
itself:protoc-gen-swift
. A separate PR togrpc-swift
makes these files more clearly intentional.Build Plugin
The SwiftPM build plugin will locate protobuf files in the
Sources
directory (with the extension.proto
) and attempt to invoke both theprotoc-gen-swift
andprotoc-gen-grpc-swift
protoc
plugins on them to automatically generate Swift source. Behavior can be modified by specifying one or more configuration files (namedgrpc-swift-config.json
).Configuration
Adoption
Users must add the plugin to any target which wishes to make use of it
Command Plugin
protoc
invocations it uses for ease of debugging. The--dry-run
flag can be supplied for this purpose or so that they may be extracted and used separately e.g. in a script.protoc
path is supplied then SwiftPM will attempt to locate it.output
directory is supplied then generated files are placed in the working directory.