build: use mode default and valid_archive=False in bazel proto gen#74313
Merged
craig[bot] merged 2 commits intocockroachdb:masterfrom Jan 4, 2022
Merged
build: use mode default and valid_archive=False in bazel proto gen#74313craig[bot] merged 2 commits intocockroachdb:masterfrom
craig[bot] merged 2 commits intocockroachdb:masterfrom
Conversation
In this mode it generates a go_library target as well that embeds the go_proto_library target and resolves users to depend on it instead. On its own this changes very little, but paves the way for a follow-up change to how go_proto_library targets behave. Release note: none.
This comment has been minimized.
This comment has been minimized.
Contributor
Author
|
Before this change: After this change: |
Prior to this change, there were some known-broken go targets in the tree, defined by `go_proto_library` rules, that were unbuildable for reasons explained below. They existed only to be embedded in other `go_library` targets which could then be built, tested, etc and were not _intended_ to be built or tested on their own, but their presence in the tree still caused problems for workflows that inadvertently tried to build them, such as `build //some/prefix/...` or test-changed-packages. Specifically, some options used in protos to control code generation can result in a generated file that cannot be compiled on its own. For example, several of our proto messages use `gogo.stringer=false` which causes the generated message to not include a String() method, but it still asserts that it implements the Message interface which requires that method. It is expected that the generated file is passed to the go compiler along with a hand-written file that adds the missing method to the message type, so that it them implements the interface. That hand-written file depends on the generated file, e.g. the type is appears in the receiver when defining the String() method, so it too cannot be built on its own. Thus simply wrapping it in a go_library of its own to `embed` in the `go_proto_library` doesn't solve this; now *that* target fails to build. Instead, we can set the `valid_archive=False` flag on the proto compiler used to generate these go_proto_library targets. Doing so causes these targets to no longer yeidld a `GoArchive`, which believes it should be able to be built, and instead only yeild the `GoLibrary` and `GoSource` that can then be embedded in `go_library` to complete it. Release note: none.
rickystewart
approved these changes
Jan 4, 2022
Collaborator
rickystewart
left a comment
There was a problem hiding this comment.
works for me, thanks!
Contributor
Author
|
TFTR! bors r+ |
Contributor
|
This PR was included in a batch that was canceled, it will be automatically retried |
Contributor
|
Cool! |
Contributor
|
Build failed (retrying...): |
Contributor
|
Build succeeded: |
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.
Prior to this change, there were some known-broken go targets in the tree, defined by
go_proto_libraryrules, that were unbuildable for reasons explained below. They existed only to be embedded in othergo_librarytargets which could then be built, tested, etc and were not intended to be built or tested on their own, but their presence in the tree still caused problems for workflows that inadvertently tried to build them, such asbuild //some/prefix/...or test-changed-packages.Specifically, some options used in protos to control code generation can result in a generated file that cannot be compiled on its own. For example, several of our proto messages use
gogo.stringer=falsewhich causes the generated message to not include a String() method, but it still asserts that it implements the Message interface which requires that method. It is expected that the generated file is passed to the go compiler along with a hand-written file that adds the missing method to the message type, so that it them implements the interface.That hand-written file depends on the generated file, e.g. the type is appears in the receiver when defining the String() method, so it too cannot be built on its own. Thus simply wrapping it in a go_library of its own to
embedin thego_proto_librarydoesn't solve this; now that target fails to build.Instead, we can set the
valid_archive=Falseflag on the proto compiler used to generate these go_proto_library targets. Doing so causes these targets to no longer yeidld aGoArchive, which believes it should be able to be built, and instead only yeild theGoLibraryandGoSourcethat can then be embedded ingo_libraryto complete it.To use the above, we also switch gazelle's proto mode from
packagetodefault; the latter instructs it to generate thesego_librarywrapper targets that embded thego_proto_library.