Skip to content

Not possible to select() on constraint_value in alias rules #13047

@staalb

Description

@staalb

Description of the problem / feature request:

According to #8583, it should be possible to directly use a constraint_value in a select() expression. This seems not be the case for alias rules though.

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

cc_binary(
    name = "appl",
    srcs = ["main.c"],
)   

constraint_value(
    name = "mycpu",
    constraint_setting = "@platforms//cpu:cpu",
)

alias(
    name = "foo",
    actual = select({
        ":mycpu" : ":appl",
    }),
)

When running bazel build :foo, the following error is produced:

ERROR: /tmp/bzl_alias/BUILD:12:6: //:mycpu is not a valid select() condition for //:foo.
To inspect the select(), run: bazel query --output=build //:foo.
For more help, see https://docs.bazel.build/be/functions.html#select.

ERROR: Analysis of target '//:foo' failed; build aborted: //:mycpu is not a valid select() condition for //:foo.
To inspect the select(), run: bazel query --output=build //:foo.
For more help, see https://docs.bazel.build/be/functions.html#select.

INFO: Elapsed time: 0.077s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 1 target configured)
FAILED: Build did NOT complete successfully (0 packages loaded, 1 target configured)

What operating system are you running Bazel on?

Linux

What's the output of bazel info release?

release 3.7.0, release 4.0.0

Have you found anything relevant by searching the web?

Tried hard, didn't find anything relevant.

Any other information, logs, or outputs that you want to share?

I studied the relevant code a little bit, found a comment that might be interesting:

// If platformInfo == null, that means the owning target doesn't invoke toolchain
// resolution, in which case depending on a constraint_value is nonsensical.

If targetPlatform is null (which apparently is the case if using alias), there's some reason why this doesn't work which I don't fully understand. If this doesn't work by design, then it might be helpful to have this documented.

Workaround for me now is to use a cc_library with a select() on the deps attribute instead of an alias rule.

Metadata

Metadata

Assignees

Labels

P2We'll consider working on this in future. (Assignee optional)team-Configurabilityplatforms, toolchains, cquery, select(), config transitionstype: bug

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions