Add python_resolve
field to protobuf_source
and thrift_source
to support multiple resolves with codegen (Cherry-pick of #14693)
#14698
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.
Closes #14484.
Problem
Generated code needs associated runtime libraries, e.g.
protobuf
. Those must come from apython_requirement
which by definition have a singleresolve
.Before this PR, it was impossible to have >1
python_requirement
target used for each runtime library and everyprotobuf_source
target would depend on the samepython_requirement
. Practically, this means codegen could only work with code belonging to a single resolve.Solution
Add a
python_resolve
field to codegen targets so that they can indicate whichpython_requirement
they should be using. Our new dependency inference from #14691 wires this up properly.If you want the same generated code to work with multiple resolves, you will need to use
parametrize
. That gets tricky when you consider a codegen target generating for multiple languages, as explained at the bottom of #14484, but there is a decent workaround via configurations. That will be tackled in a followup.FYI: lazy validation of runtime library
#14691 asserts that there is exactly 1 runtime library in the project; now we assert that for each resolve.
Key nuance: this check is lazy. If you have 2 resolves, but your codegen targets only use 1 of the 2, then we will never end up checking that there is a runtime library defined for the 2nd resolve. That is important so that, for example, if you have a
pants-plugins
resolve we don't force you to addprotobuf
unnecessarily to it.[ci skip-rust]
[ci skip-build-wheels]