bazelbuild / bazelbuild/bazel

Validate that rules without toolchain context cannot create actions

Open
#20,505 1 comment 0 reactions 0 assignees View on GitHub
P2 team-Configurability team-Rules-API type: feature request
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

In theory, [`RuleContext.getToolchainContext`](https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/analysis/RuleContext.java;bpv=1;bpt=1;l=1120?ss=bazel&q=RuleContext&gsn=getToolchainContext&gs=KYTHE%3A%2F%2Fkythe%3A%2F%2Fgithub.com%2Fbazelbuild%2Fbazel%3Flang%3Djava%3Fpath%3Dcom.google.devtools.build.lib.analysis.RuleContext%230725ce045590b002a909a757696908b4d56d671f12829e58b90ee6c328d33a1f) will only return `null` if the rule is not generating actions (as set in [`RuleClass.Builder.useToolchainResolution(ToolchainResolutionMode.DISABLED)`](https://cs.opensource.google/bazel/bazel/+/master:src/main/java/com/google/devtools/build/lib/packages/RuleClass.java;bpv=1;bpt=1;l=1623?ss=bazel&q=RuleClass&gsn=useToolchainResolution&gs=KYTHE%3A%2F%2Fkythe%3A%2F%2Fgithub.com%2Fbazelbuild%2Fbazel%3Flang%3Djava%3Fpath%3Dcom.google.devtools.build.lib.packages.RuleClass.Builder%23d3d2f24cd8e66dd2de269d7fd550f7ddeac599016d8ab4474f700c51b430fb1b)). However, we aren't currently validating this, and it's possible that legacy rules are violating this.

We should add explicit validation around this to ensure that any rule which generates actions has a toolchain context (which includes both the target and exec platforms for that configured target).

Contributor guide

Open the contributing guide

Research direction

Start by reading RuleContext.getToolchainContext and RuleClass.Builder.useToolchainResolution(ToolchainResolutionMode.DISABLED), which define the relevant context and rule configuration. Add validation ensuring action-generating rules have both target and exec platforms in their toolchain context, and verify that rules without toolchain context are rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.