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

Add support for Protobuf Editions #284

Merged
merged 5 commits into from
Jul 31, 2024
Merged

Add support for Protobuf Editions #284

merged 5 commits into from
Jul 31, 2024

Conversation

rebello95
Copy link
Collaborator

@rebello95 rebello95 commented Jul 31, 2024

This PR adds support for Protobuf Editions to Connect-Swift plugins. There is no change to generated outputs in this PR, but it adds supportsEditions and supportedEditionRange specifications in the Generator class to ensure the Connect plugins can run with Protobuf files that use Editions.

SwiftProtobuf also deprecated some usages of Google_Protobuf_Compiler_CodeGeneratorResponse:

'Google_Protobuf_Compiler_CodeGeneratorResponse.init(files:supportedFeatures:)' is deprecated: Please move your plugin to the CodeGenerator interface

As part of these changes, I migrated over to using CodeGenerator in order to be able to specify the new Editions-related variables mentioned above.

Comment on lines +24 to +27
override var outputFileExtension: String {
".connect.swift"
}

Copy link
Member

Choose a reason for hiding this comment

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

This is the default extension in the super-class. Maybe omit this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I noticed this as well. Is the Generator ever initialized and used on its own? It seems like if it's just a superclass that holds some core/shared functionality, perhaps we could even consider putting an assertion or something in that superclass outputFileExtension implementation and specify that it must be overridden in subclasses?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Is the Generator ever initialized and used on its own?

It's not, I added a comment to clarify this as well

perhaps we could even consider putting an assertion or something in that superclass outputFileExtension implementation and specify that it must be overridden in subclasses?

This sounds good to me -- I'd rather do that than omit it in subclasses so that it's explicit in each generator. Updated

}

public var supportedEditionRange: ClosedRange<SwiftProtobuf.Google_Protobuf_Edition> {
return SwiftProtobufPluginLibrary.DescriptorSet.bundledEditionsSupport
Copy link
Member

Choose a reason for hiding this comment

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

This seems potentially dangerous: a future edition could introduce service or method-specific changes that need to be handled by the plugin. In such a case, if this plugin code (without the necessary updates) were paired with a newer version of the runtime (that was updated to support that edition) then it would report that the edition is supported even though it may generate incorrect code.

While it's a bit of a maintenance nuisance to have to manually bump the max supported edition, I think that's the safest way to implement this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Fair point, updated

@rebello95 rebello95 requested review from eseay and jhump July 31, 2024 15:54
DescriptorSet.bundledEditionsSupport.lowerBound, Google_Protobuf_Edition.legacy
)
let maxEdition = min(
DescriptorSet.bundledEditionsSupport.upperBound, Google_Protobuf_Edition.edition2024
Copy link
Member

@jhump jhump Jul 31, 2024

Choose a reason for hiding this comment

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

It is sadly confusing in descriptor.proto, which shows 2024 as the latest edition. But 2024 isn't actually fully-defined yet. It's an experimental edition that is still in progress.

If you try to compile a file with it (using buf or the latest v27.2 of protoc) you'll get the following:

$ echo 'edition = "2024";' > test.proto
$ protoc test.proto -o /dev/null
test.proto:1:1: Edition 2024 is later than the maximum supported edition 2023
$ buf build
test.proto:1:11:edition value "2024" not recognized; should be one of ["2023"]

(You can try out 2024 in protoc by passing the --experimental_editions flag.)

Since it's incomplete (and 2023 changed quite a bit between early experimental releases like v24 and the final version in v27), we probably should hold off and use 2023 here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, got it. This was also failing without the min here for the same reason, but that makes sense to not support 2024 until it's done. Updated

updates

Update Generator.swift

Signed-off-by: Michael Rebello <[email protected]>
Signed-off-by: Michael Rebello <[email protected]>
Signed-off-by: Michael Rebello <[email protected]>
Signed-off-by: Michael Rebello <[email protected]>
Signed-off-by: Michael Rebello <[email protected]>
@rebello95
Copy link
Collaborator Author

(Had to rebase for DCO)

@rebello95 rebello95 merged commit 7dcc4b6 into main Jul 31, 2024
14 of 15 checks passed
@rebello95 rebello95 deleted the rebello-editions branch July 31, 2024 18:06
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