refactor(protoc): migrate to protocompile experimental compiler for Edition 2024#404
Open
Kybxd wants to merge 4 commits into
Open
refactor(protoc): migrate to protocompile experimental compiler for Edition 2024#404Kybxd wants to merge 4 commits into
Kybxd wants to merge 4 commits into
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #404 +/- ##
==========================================
- Coverage 75.60% 75.42% -0.19%
==========================================
Files 88 89 +1
Lines 9527 9565 +38
==========================================
+ Hits 7203 7214 +11
- Misses 1749 1767 +18
- Partials 575 584 +9 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
The latest Buf updates on your PR. Results from workflow Buf CI / buf (pull_request).
|
The experimental compiler only accepts source files via source.Opener, so
vendor required .proto deps under internal/x/xproto/protoc/embedded/ and
expose them through go:embed:
- tableau/protobuf/*.proto: copied from proto/tableau/protobuf/
- buf/validate/validate.proto: exported from buf.build/bufbuild/protovalidate
at the commit pinned in buf.lock
gen_embedded.sh (invoked via go:generate) refreshes the embedded tree and
explicitly forwards buf.lock's protovalidate commit to `buf export`, since
ad-hoc `buf export` does not consult buf.lock. The embedded/ tree is
committed so `go install ...@latest` works without buf or go generate.
Regenerate embedded/tableau/protobuf/tableau.proto, wellknown.proto and embedded/buf/validate/validate.proto to sync with the aggregate field added to FieldProp in proto/tableau/protobuf/tableau.proto (PR #395). The stale embedded copy caused test/functest failures: "cannot resolve message field name for tableau.FieldProp".
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
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.
Why
Protobuf Edition 2024 is not understood by
bufbuild/protocompile's stableCompiler. To unblock Edition 2024 schemas, we follow the same path Buf itself took in buf v1.69.0 and switch the internalprotocwrapper to protocompile's experimental compiler, which has Edition 2024 support.What changes vs. the stable compiler
The experimental compiler exclusively consumes source files via
source.Opener. It no longer accepts pre-compiledFileDescriptors throughprotoregistry.GlobalFiles— which is how the stable compiler used to pick uptableau/protobuf/*.protoandbuf/validate/validate.proto. We need a new mechanism to make those imports resolvable at compile time.How
Expose the required
.protosources throughgo:embedand feed them to protocompile via a customfs.FS:tableau/protobuf/tableau.protoproto/tableau/protobuf/tableau.proto(embedded viatableauprotobuf.FS)tableau/protobuf/wellknown.protoproto/tableau/protobuf/wellknown.proto(embedded viatableauprotobuf.FS)buf/validate/validate.protobuf exportofbuf.build/bufbuild/protovalidatepinned inbuf.lockinternal/x/xproto/protoc/embedded/Standard imports (
google/protobuf/*) continue to be served bysource.WKTsand need no embedding.Single source of truth for tableau protos
A new
proto/tableau/protobuf/embed.goexposestableauprotobuf.FS(//go:embed tableau.proto wellknown.proto, matchingbuf.yaml's top-level-only scope), andinternal/x/xproto/protoc/embed.gocomposes it with the vendoredbuf/validate/tree behind a smalllayeredFSthat routestableau/protobuf/*reads totableauprotobuf.FSand everything else to the embedded buf-validate export. This means the compiler always sees the exact same tableau proto text that ships inproto/tableau/protobuf/, with no risk of a stale second copy.Refresh workflow for protovalidate
A
go:generatedirective inembed.goinvokesgen_embedded.sh, which:embedded/and recreatesembedded/buf/validate/.buf.lockand forwards it tobuf export buf.build/bufbuild/protovalidate:<commit>.Why is
embedded/checked into version control?So that downstream consumers of
go install github.com/tableauio/tableau/cmd/tableauc@latestcan build withoutbufinstalled and without runninggo generate—proxy.golang.orgonly packages git-tracked files.Upgrading protovalidate
Diff summary
7 files changed, mostly the vendored
buf/validate/validate.proto(~5.1k lines):internal/x/xproto/protoc/compiler.go— switch to experimental compiler, wiresource.Openeragainst the layeredfs.FS.internal/x/xproto/protoc/embed.go—go:embedforbuf/validate/,layeredFS, and refresh-workflow docs.internal/x/xproto/protoc/gen_embedded.sh— refresh script driven bybuf.lock.internal/x/xproto/protoc/embedded/buf/validate/validate.proto— vendored protovalidate schema.proto/tableau/protobuf/embed.go— newtableauprotobuf.FSexposing this repo's own proto sources.go.mod/go.sum— protocompile experimental dep.