bazelbuild / bazelbuild/bazel

Registering toolchains via :all does not work with aliases.

Open
#16,298 10 comments 1 reaction 0 assignees View on GitHub
P2 team-Configurability type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 18h
Merged PRs (30d)
75

Description

### Description of the bug:

Using the `:all` target with `register_toolchain` should register all the toolchains in the package. However, when the package contains aliases to toolchains this no longer works.

### What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

A minimal example can be found here: https://github.com/cameron-martin/bazel-register-all-toolchains-repro

This builds fine when using `register_toolchains("//toolchains:all")`, which directly references the toolchains. However, if this is changed to `register_toolchains("//:all")`, which indirectly references the toolchain via an alias, no toolchains are registered and the following error occurs when building:

```
ERROR: /home/cameron/Repos/bazel-register-all-toolchains-repro/toolchains/BUILD:5:11: While resolving toolchains for target //toolchains:bar_binary: No matching toolchains found for types //toolchains:toolchain_type.
```

### Which operating system are you running Bazel on?

Ubuntu 22.04

### What is the output of `bazel info release`?

release 5.3.0/development version

### If `bazel info release` returns `development version` or `(@non-git)`, tell us how you built Bazel.

Using bazelisk last_green with commit `fae86178fc94f28e509c3e1ed221e63b9fa433d9`. The bug appears in both this version and 5.3.0.

### What's the output of `git remote get-url origin; git rev-parse master; git rev-parse HEAD` ?

_No response_

### 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

Open the contributing guide

Research direction

Start with the linked minimal reproduction and compare register_toolchains("//toolchains:all") with register_toolchains("//:all") when the package contains aliases. Trace Bazel's :all target expansion and toolchain registration until the alias case is handled, then verify that the reproduction builds without the “No matching toolchains found” error.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.