@@ -221,6 +221,22 @@ public enum ToolchainResolutionMode {
221
221
ENABLED ,
222
222
/** The rule should not use toolchain resolution. */
223
223
DISABLED ,
224
+ /**
225
+ * The rule instance uses toolchain resolution if it has a select().
226
+ *
227
+ * <p>This is for rules that don't intrinsically use toolchains but have select()s on {@link
228
+ * com.google.devtools.build.lib.rules.platform.ConstraintValue}, which are part of the build's
229
+ * platform. Such instances need to know what platform the build is targeting, which Bazel won't
230
+ * provide unless toolchain resolution is enabled.
231
+ *
232
+ * <p>This is set statically in rule definitions on an opt-in basis. Bazel doesn't automatically
233
+ * infer this for any target with a select().
234
+ *
235
+ * <p>Ultimately, we should remove this when <a
236
+ * href="https://github.com/bazelbuild/bazel/issues/12899#issuecomment-767759147}#12899</a>is
237
+ * addressed, so platforms are unconditionally provided for all rules.
238
+ */
239
+ HAS_SELECT ,
224
240
/** The rule should inherit the value from its parent rules. */
225
241
INHERIT ;
226
242
@@ -245,6 +261,7 @@ boolean isActive() {
245
261
case ENABLED :
246
262
return true ;
247
263
case DISABLED :
264
+ case HAS_SELECT : // Not true for RuleClass, but Rule may enable it.
248
265
return false ;
249
266
default :
250
267
}
@@ -380,7 +397,7 @@ public RuleErrorException(String message, Throwable cause) {
380
397
* normal dependency resolution because they're needed to determine other dependencies. So there's
381
398
* no intrinsic reason why we need an extra attribute to store them.
382
399
*
383
- * <p>There are three reasons why we still create this attribute:
400
+ * <p>There are four reasons why we still create this attribute:
384
401
*
385
402
* <ol>
386
403
* <li>Collecting them once in {@link #populateRuleAttributeValues} instead of multiple times in
@@ -390,6 +407,9 @@ public RuleErrorException(String message, Throwable cause) {
390
407
* we need to make sure its coverage remains complete.
391
408
* <li>Manual configuration trimming uses the normal dependency resolution process to work
392
409
* correctly and config_setting keys are subject to this trimming.
410
+ * <li>{@link Rule#useToolchainResolution() supports conditional toolchain resolution for
411
+ * targets with non-empty select()s. This requirement would go away if platform info was
412
+ * prepared for all rules regardless of toolchain needs.
393
413
* </ol>
394
414
*
395
415
* <p>It should be possible to clean up these issues if we decide we don't want an artificial
@@ -2753,8 +2773,12 @@ public ImmutableSet<Label> getRequiredToolchains() {
2753
2773
return requiredToolchains ;
2754
2774
}
2755
2775
2756
- public boolean useToolchainResolution () {
2757
- return this .useToolchainResolution .isActive ();
2776
+ /**
2777
+ * Public callers should use {@link Rule#useToolchainResolution()}, which also takes into account
2778
+ * target-specific information.
2779
+ */
2780
+ ToolchainResolutionMode useToolchainResolution () {
2781
+ return this .useToolchainResolution ;
2758
2782
}
2759
2783
2760
2784
public boolean useToolchainTransition () {
0 commit comments