-
Notifications
You must be signed in to change notification settings - Fork 14
Code generation package plugins #26
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
Closed
Closed
Conversation
This file contains hidden or 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
glbrntt
added a commit
that referenced
this pull request
Mar 5, 2025
### Motivation: To make it simpler to generate gRPC stubs with `protoc-gen-grpc-swift` and `protoc-gen-swift`. ### Modifications: * Add a new command plugin * Refactor some errors The command plugin can be invoked from the CLI as: ``` swift package generate-grpc-code-from-protos --import-path /path/to/Protos -- /path/to/Protos/HelloWorld.proto ``` The plugin has flexible configuration: ``` ❯ swift package generate-grpc-code-from-protos --help Usage: swift package generate-grpc-code-from-protos [flags] [--] [input files] Flags: --servers Indicate that server code is to be generated. Generated by default. --no-servers Indicate that server code is not to be generated. Generated by default. --clients Indicate that client code is to be generated. Generated by default. --no-clients Indicate that client code is not to be generated. Generated by default. --messages Indicate that message code is to be generated. Generated by default. --no-messages Indicate that message code is not to be generated. Generated by default. --file-naming The naming scheme for output files [fullPath/pathToUnderscores/dropPath]. Defaults to fullPath. --access-level The access level of the generated source [internal/public/package]. Defaults to internal. --access-level-on-imports Whether imports should have explicit access levels. Defaults to false. --import-path The directory in which to search for imports. --protoc-path The path to the protoc binary. --output-path The path into which the generated source files are created. --verbose Emit verbose output. --dry-run Print but do not execute the protoc commands. --help Print this help. ``` * When executing, the command prints the `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. * If no `protoc` path is supplied then Swift Package Manager will attempt to locate it. * If no `output` directory is supplied then generated files are placed a Swift Package Manager build directory. ### Result: More convenient code generation This PR is split out of #26 --------- Co-authored-by: George Barnett <[email protected]>
glbrntt
added a commit
to glbrntt/grpc-swift-protobuf
that referenced
this pull request
Mar 5, 2025
### Motivation: To make it simpler to generate gRPC stubs with `protoc-gen-grpc-swift` and `protoc-gen-swift`. ### Modifications: * Add a new command plugin * Refactor some errors The command plugin can be invoked from the CLI as: ``` swift package generate-grpc-code-from-protos --import-path /path/to/Protos -- /path/to/Protos/HelloWorld.proto ``` The plugin has flexible configuration: ``` ❯ swift package generate-grpc-code-from-protos --help Usage: swift package generate-grpc-code-from-protos [flags] [--] [input files] Flags: --servers Indicate that server code is to be generated. Generated by default. --no-servers Indicate that server code is not to be generated. Generated by default. --clients Indicate that client code is to be generated. Generated by default. --no-clients Indicate that client code is not to be generated. Generated by default. --messages Indicate that message code is to be generated. Generated by default. --no-messages Indicate that message code is not to be generated. Generated by default. --file-naming The naming scheme for output files [fullPath/pathToUnderscores/dropPath]. Defaults to fullPath. --access-level The access level of the generated source [internal/public/package]. Defaults to internal. --access-level-on-imports Whether imports should have explicit access levels. Defaults to false. --import-path The directory in which to search for imports. --protoc-path The path to the protoc binary. --output-path The path into which the generated source files are created. --verbose Emit verbose output. --dry-run Print but do not execute the protoc commands. --help Print this help. ``` * When executing, the command prints the `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. * If no `protoc` path is supplied then Swift Package Manager will attempt to locate it. * If no `output` directory is supplied then generated files are placed a Swift Package Manager build directory. ### Result: More convenient code generation This PR is split out of grpc#26 --------- Co-authored-by: George Barnett <[email protected]>
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.