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

Support feature resolution for Protobuf Editions. #473

Merged
merged 4 commits into from
Oct 1, 2024

Conversation

chungyc
Copy link
Member

@chungyc chungyc commented Sep 16, 2024

This implements Protobuf Editions feature resolution for the Haskell protoc plugin.

This embeds the binary protobuf message that protoc outputs for feature set defaults, which is deserialized at runtime. It is done this way since it does not seem sustainable to manually translate the protobuf message to Haskell code every time there is a new edition. It also seems to be the same approach that protocolbuffers/protobuf intends for use with custom code generators written in C++. This is not stored in a separate file with the binary protobuf message to avoid adding additional dependencies such as file-embed.

Tests are not included in this pull request, but this code is tested in a subsequent change (https://github.com/chungyc/proto-lens/pull/8), which confirm that the feature resolution works by maintaining the same behavior for proto2 and proto3. This is due to the fact that tests cannot directly import these modules. Perhaps the modules in app/ should be turned into an internal library for unit tests, but that change is not for this one.

This does not complete Protobuf Editions support, which requires two more changes: https://github.com/chungyc/proto-lens/pull/7 (control proto2 and proto3 behavior based on features, not syntax type), https://github.com/chungyc/proto-lens/pull/8 (override features in enclosed scopes)

For #468.

@chungyc
Copy link
Member Author

chungyc commented Sep 26, 2024

Are they any concerns that need to be addressed?

I can also have a pull request with all the changes for Protobuf Editions support at once if that is the preference.

@blackgnezdo
Copy link
Collaborator

I was hoping @agrue would take the lead on this one :) I'm a bit distanced from protobufs these days (I know!) so it's harder for me to find the time to invest into a proper review.

@agrue
Copy link
Contributor

agrue commented Sep 29, 2024

Sure, I will take a look. Just need to find the time.

This should successfully generate code for these files.  However, they do not have the correct semantics yet.  `protoc` does not translate equivalent features supported in proto2 and proto3 into previous `FieldOptions` fields, and we must adjust the semantics according to what are specified in `FeatureSet` messages.
It will not accept actual Protobuf Editions files by restricting
the supported edition to `LEGACY`.  This restriction will be
lifted once support for edition 2023 is complete.
@chungyc chungyc force-pushed the edition-features-incremental branch from d50e7da to 0298168 Compare October 1, 2024 14:33
@agrue agrue merged commit 1818e75 into google:master Oct 1, 2024
11 checks passed
@chungyc chungyc deleted the edition-features-incremental branch October 1, 2024 23:11
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