-
Notifications
You must be signed in to change notification settings - Fork 4k
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 new ToolchainTypeInfo provider to track toolchain type information. #6235
Conversation
Will eventually be part of checking the toolchain provider types, as part of bazelbuild#6015. Change-Id: I74e9372fb19d1f78c00a340c484c3c4d4b2f2ab1
This will be required after bazelbuild#6235 requires actual dependencies on toolchain_type targets. Part of the work on bazelbuild#6015. Change-Id: I21e5399dc0c43bb7b4d42e1f1bd5b9a1c820075e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forgive my ignorance, but this is motivated by C++ toolchain resolution, and the desire to not have to litter awkward checking throughout the code base, right?
What's the current state of Starlark-defined C++ toolchain definitions and the rules that consume them? i..e. which rule definitions for C++ would this logic use to do the checking?
@@ -0,0 +1,70 @@ | |||
package com.google.devtools.build.lib.analysis.platform; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File header comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
/* <!-- #BLAZE_RULE(toolchain).ATTRIBUTE(toolchain_type) --> | ||
The type of the toolchain, which should be the label of a toolchain_type() target. | ||
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */ | ||
.add( | ||
attr(TOOLCHAIN_TYPE_ATTR, BuildType.NODEP_LABEL) | ||
attr(TOOLCHAIN_TYPE_ATTR, BuildType.LABEL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What does the NODEP_LABEL to LABEL change signify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is so that the toolchain_type()
rule referred to by the label gets analyzed and thus the ToolchainTypeInfo
gets created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, exactly. There's now an actual dependency on the toolchain type, so:
a) it must exist, and
b) the new provider can now be used.
import com.google.devtools.build.lib.skylarkinterface.SkylarkModule; | ||
import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory; | ||
|
||
/** Info object representing data about a specific platform. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the right comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope, fixed it.
public static final NativeProvider<ToolchainTypeInfo> PROVIDER = | ||
new NativeProvider<ToolchainTypeInfo>(ToolchainTypeInfo.class, SKYLARK_NAME) {}; | ||
|
||
private final Label typeLabel; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What other information is expected to be here other than the label?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a branch in progress that adds a (string-valued) provider_id attribute, which can then be checked against the actual provider during toolchain resolution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Understood! I don't know what your plans are and thus I can't say anything wise about them, but I think this change by itself is a net win, since I consider nodep labels a hack (they are confusing because label attributes usually mean a dependency).
I'm somewhat worried about the "string-valued provider_id attribute" part, but we can discuss that in a separate thread.
|
||
/* <!-- #BLAZE_RULE(toolchain).ATTRIBUTE(toolchain_type) --> | ||
The type of the toolchain, which should be the label of a toolchain_type() target. | ||
<!-- #END_BLAZE_RULE.ATTRIBUTE --> */ | ||
.add( | ||
attr(TOOLCHAIN_TYPE_ATTR, BuildType.NODEP_LABEL) | ||
attr(TOOLCHAIN_TYPE_ATTR, BuildType.LABEL) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this is so that the toolchain_type()
rule referred to by the label gets analyzed and thus the ToolchainTypeInfo
gets created.
Change-Id: Iec98478ea0051440129d9e19efbf6c3aff68d3da
Change-Id: I6022b2f8ace0b41599753584823a3fda82b85370
Correct, this came about from a conversation @lberki and I had about type checking C++ toolchain providers. The same issues will also come up for Java toolchain providers. While the C++ crosstool is moving into Starlark, I'm not aware of any long-term plans to re-write the CppToolchainProvider as Starlark code, as it is very heavily used in Bazel internals. Given that, we still need the check that a target that requires a c++ toolchain gets an actual CppToolchainProvider, in order to avoid the current potential class cast errors. |
Change-Id: Ic1d98c1cbeb3c40a3d3a81c03ccfb6c8f0a87b86
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the larger check, I need to test what exactly is available to validate on. Every toolchain has to be a subclass of ToolchainInfo, so that is the actual provider type for them all. I may need to do class name matching for native providers instead, or add a "type" to the ToolchainInfo for comparison. Still considering. |
Yes, still working out the best way to do the actual check on the provider type. It turns out to be fairly tricky. But I think this change is still worthwhile even without the provider type checking. |
Change-Id: I53d6a0d41c05029b98dddac4c8b8a7f60aa218d6
Change-Id: I80592a3e130dea99bee9ccecfaaf2b64b73bc80a
*** Reason for rollback *** This change is causing many rules_* jobs to fail at HEAD: https://buildkite.com/bazel/bazel-with-downstream-projects-bazel/builds/480 Filed issue: #6311 *** Original change description *** Add new ToolchainTypeInfo provider to track toolchain type information. Will eventually be part of checking the toolchain provider types, as part of #6015. Closes #6235. PiperOrigin-RevId: 215911302
Will eventually be part of checking the toolchain provider types, as
part of #6015.
Change-Id: I74e9372fb19d1f78c00a340c484c3c4d4b2f2ab1