bazelbuild / bazelbuild/bazel

toolchain resolution fails for non-workspace prefixed toolchain_types if workspace name used --extra_toolchains

Open
#13,381 11 comments 0 reactions 1 assignee Claimed by @katre View on GitHub
P2 team-Configurability type: bug
Dominant language
Java
Stars
25.8k
Forks
4.6k
Avg merge
2d 20h
Merged PRs (30d)
72

Description

### Description of the problem / feature request:

When specifying a toolchain via --extra_toolchains which includes a workspace name, toolchain resolution fails to include that toolchain if it toolchain doesn't include a workspace prefix in the toolchain_type attribute.

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

Given a trivial build file and rule implementation (in `dummy_toolchain.bzl`):
```
def _impl(ctx):
return [platform_common.ToolchainInfo()]

dummy_toolchain = rule(implementation = _impl)

def _rule(ctx):
print(ctx.label)

dummy_rule = rule(
implementation = _rule,
# qualification here doesn't appear to matter
toolchains = ["//:dummy_toolchain_type"],
)
```
And corresponding `BUILD` file:
```
load(":dummy_toolchain.bzl", "dummy_rule", "dummy_toolchain")
package(default_visibility=["//visibility:public"])

dummy_toolchain(name = "dumdumdum")

toolchain_type(
name = "dummy_toolchain_type",
)

toolchain(
name = "dummy_toolchain_relative",
toolchain = ":dumdumdum",
toolchain_type = ":dummy_toolchain_type",
)

toolchain(
name = "dummy_toolchain_absolute",
toolchain = ":dumdumdum",
toolchain_type = "//:dummy_toolchain_type",
)

toolchain(
name = "dummy_toolchain_prefix",
toolchain = ":dumdumdum",
toolchain_type = "@//:dummy_toolchain_type",
)

toolchain(
name = "dummy_toolchain_full_prefix",
toolchain = ":dumdumdum",
toolchain_type = "@//:dummy_toolchain_type",
)
dummy_rule(name = "dummy")
```

If the workspace name is included when specifying a toolchain via `--extra_toolchains`, only toolchains which include a workspace prefix will work. For example, given the above:
```
for workspace in "@" "@io_kythe" ""; do
for toolchain in "relative" "absolute" "prefix" "full_prefix"; do
bazel build --extra_toolchains="$workspace//:dummy_toolchain_$toolchain" //:dummy
done
done
```
Gives the results:

| --extra_toolchains prefix | toolchain_type | result |
| ------------------------------ | ------------------| ------- |
| @ | relative | succeeds |
| @ | absolute | succeeds |
| @ | prefix | succeeds |
| @ | full_prefix | succeeds |
| @io_kythe | relative | fails |
| @io_kythe | absolute | fails |
| @io_kythe | prefix | succeeds |
| @io_kythe | full_prefix | succeeds |
| | relative | succeeds |
| | absolute | succeeds |
| | prefix | succeeds |
| | full_prefix | succeeds |

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

Ubuntu Linux

### What's the output of `bazel info release`?

release 4.0.0

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

git@github.com:shahms/kythe.git
160b28af24a477fd75458e033523cf9ce81733ee
160b28af24a477fd75458e033523cf9ce81733ee

### Have you found anything relevant by searching the web?

No, although I found https://github.com/bazelbuild/bazel/issues/10927 which may be related.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.