-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Weird behavior with alias and target_compatible_with #17663
Copy link
Copy link
Closed
Labels
P3We're not considering working on this, but happy to review a PR. (No assignee)We're not considering working on this, but happy to review a PR. (No assignee)platform: appleteam-Configurabilityplatforms, toolchains, cquery, select(), config transitionsplatforms, toolchains, cquery, select(), config transitionstype: bug
Description
Description of the bug:
Setting target_compatible_with on alias does not work as expected. See repro below.
What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
Consider the following top-level BUILD.bazel file. (full repro bazel-alias-bug.zip)
filegroup(
name = "source",
srcs = ["foo.c"],
)
alias(
name = "source_alias",
actual = "source",
target_compatible_with = ["@platforms//cpu:x86_64"],
)
alias(
name = "source_alias2",
actual = select({
"@platforms//cpu:x86_64": "source",
"//conditions:default": "source",
}),
target_compatible_with = ["@platforms//cpu:x86_64"],
)
cc_library(
name = "foo",
srcs = ["source_alias"],
)
cc_library(
name = "foo2",
srcs = ["source_alias2"],
)
foo and foo2 should behave the same. However, on an M1 Mac with Bazel 6.0.0, I have
~/tmp/bazel_alias_bug master ───────────────────────────────────────────────────────────────────── system py 22:39:33
> bazel build :foo
INFO: Analyzed target //:foo (0 packages loaded, 0 targets configured).
INFO: Found 1 target...
Target //:foo up-to-date:
bazel-bin/libfoo.a
INFO: Elapsed time: 0.081s, Critical Path: 0.00s
INFO: 1 process: 1 internal.
INFO: Build completed successfully, 1 total action
~/tmp/bazel_alias_bug master ───────────────────────────────────────────────────────────────────── system py 22:39:34
> bazel build :foo2
ERROR: Target //:foo2 is incompatible and cannot be built, but was explicitly requested.
Dependency chain:
//:foo2 (602a7d)
//:source_alias2 (602a7d) <-- target platform (@local_config_platform//:host) didn't satisfy constraint @platforms//cpu:x86_64
INFO: Elapsed time: 0.044s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 0 targets configured)
With Bazel 5.4.0, I have
> bazel build :foo
Starting local Bazel server and connecting to it...
ERROR: Target //:foo is incompatible and cannot be built, but was explicitly requested.
Dependency chain:
//:foo
//:source_alias <-- target platform (null) didn't satisfy constraint @platforms//cpu:x86_64
INFO: Elapsed time: 7.002s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (38 packages loaded, 263 targets configured)
~/tmp/bazel_alias_bug master !1 ────────────────────────────────────────────────────────────── 7s system py 22:40:16
> bazel build :foo2
ERROR: Target //:foo2 is incompatible and cannot be built, but was explicitly requested.
Dependency chain:
//:foo2
//:source_alias2 <-- target platform (@local_config_platform//:host) didn't satisfy constraint @platforms//cpu:x86_64
INFO: Elapsed time: 0.088s
INFO: 0 processes.
FAILED: Build did NOT complete successfully (0 packages loaded, 2 targets configured)
Behavior of foo2 is correct in both cases. foo is both incorrect in 5.4.0 and 6.0.0.
Which operating system are you running Bazel on?
macOS
What is the output of bazel info release?
release 5.4.0 and release 6.0.0
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 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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3We're not considering working on this, but happy to review a PR. (No assignee)We're not considering working on this, but happy to review a PR. (No assignee)platform: appleteam-Configurabilityplatforms, toolchains, cquery, select(), config transitionsplatforms, toolchains, cquery, select(), config transitionstype: bug