`exec` config not applied when selecting in rule attribute of toolchain config target
- Dominant language
- Java
- Stars
- 25.8k
- Forks
- 4.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 72
Description
### Description of the bug:
Assume a arbitrary tooolchain constellation with a select on the exec platform like so to reduce duplication ([Full example in repro repo](https://github.com/FaBrand/bazel-select-exec-dependency/blob/main/BUILD)):
- Target Platform is neither linux/windows (aka when building for e.g. an embedded target)
- Host platfrom tested under linux
```Starlark
toolchain_config(
name = "broken_toolchain_config",
tool = select({
"@platforms//os:linux": "//:linux_tool.bash",
"@platforms//os:windows": "//:windows_tool.bat",
}),
)
toolchain(
name = "broken_toolchain",
exec_compatible_with = [
"@platforms//cpu:x86_64",
],
toolchain = ":broken_toolchain_config",
toolchain_type = TOOLCHAIN_TYPE,
)
```
The select fails with no matched condition. Upon inspection of the dumped bazel config, it shows that it is being evaluated in `target` platform context:
```
Conditions checked:
@@platforms//os:linux
@@platforms//os:windows
To see a condition's definition, run: bazel query --output=build .
This instance of //:broken_toolchain_config has configuration identifier a36e1a6. To inspect its configuration, run: bazel config a36e1a6.
For more help, see https://bazel.build/docs/configurable-attributes#faq-select-choose-condition.
ERROR: Analysis of target '//:toolchain_consumer' failed; build aborted: Analysis failed
```
However, if the same tool is referred through an alias it gets evaluated successfully, aka the
```Starlark
toolchain_config(
name = "broken_toolchain_config",
tool = ":tool",
)
alias(
name = "tool",
actual = select({
"@platforms//os:linux": "//:linux_tool.bash",
"@platforms//os:windows": "//:windows_tool.bat",
}),
)
```
It analyzes successfully:
```
$ bazel build --config working
WARNING: Build option --host_platform has changed, discarding analysis cache (this can be expensive, see https://bazel.build/advanced/performance/iteration-speed).
INFO: ToolchainResolution: Performing resolution of //:my_toolchain_type for target platform //:my_platform
ToolchainResolution: Toolchain //:working_toolchain_config is compatible with target platform, searching for execution platforms:
ToolchainResolution: Compatible execution platform @@platforms//host:host
ToolchainResolution: All execution platforms have been assigned a //:my_toolchain_type toolchain, stopping
ToolchainResolution: Recap of selected //:my_toolchain_type toolchains for target platform //:my_platform:
ToolchainResolution: Selected //:working_toolchain_config to run on execution platform @@platforms//host:host
INFO: ToolchainResolution: Target platform //:my_platform: Selected execution platform @@platforms//host:host, type //:my_toolchain_type -> toolchain //:working_toolchain_config
DEBUG: ~/bazel-exec-select/toolchain_user.bzl:19:10: Used tool
INFO: Analyzed target //:toolchain_consumer (0 packages loaded, 425 targets configured).
INFO: Found 1 target...
Target //:toolchain_consumer up-to-date:
bazel-bin/output.txt
INFO: Elapsed time: 0.245s, Critical Path: 0.00s
INFO: 1 process: 1 action cache hit, 1 internal.
INFO: Build completed successfully, 1 total action
```
### Which category does this issue belong to?
Configurability
### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
git clone https://github.com/FaBrand/bazel-select-exec-dependency bug
cd bug
bazel build --config broken
### Which operating system are you running Bazel on?
Ubuntu 24.04 in WSL
### What is the output of `bazel info release`?
release 8.4.2
### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.
_No response_
### What's the output of `git remote get-url origin; git rev-parse HEAD` ?
```text
https://github.com/FaBrand/bazel-select-exec-dependency.git
6afb45e14a02f6f2a541b249a61de362c7d255b2
```
### If this is a regression, please try to identify the Bazel commit where the bug was introduced with bazelisk --bisect.
I could not identify a working version (5.0.0 was the oldest i stopped testing with)
### Have you found anything relevant by searching the web?
_No response_
### Any other information, logs, or outputs that you want to share?
_No response_
Contributor guide
Research direction
Clone the linked repro repository and run `bazel build --config broken`; inspect its BUILD file and compare the direct `select()` in `toolchain_config` with the working alias-based configuration. Then trace Bazel's toolchain configuration and configurable-attribute handling, using the dumped configuration and the reported analysis failure as reference. Done means the direct selection resolves the execution-platform conditions without breaking the existing alias case.
Written by the indexing model from the issue text.
Assessment
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100