bazel: select()'s unambiguous specialization resolution fails with platform constraint_value()s

Hi, wonderful Bazel folks. Thanks for all the great work you do, including extending official support for platforms.

This is a bug report at the intersection of select() and constraint_value() (for platforms). You can definitely work around it, but it’s a bit annoying. I’m guessing it’s just an early rough edge, since platforms are still in flux.

This is easiest by example. Say you have:

config_setting(
    name="ios-aarch64",
    constraint_values = [
        "@platforms//os:ios",
        "@platforms//cpu:aarch64",
    ]
)

And you try to select() between :ios-aarch64 and @platforms//os:ios.

You’ll get an error like:

Illegal ambiguous match on configurable attribute <...>
:ios-aarch64
@platforms//os:ios
Multiple matches are not allowed unless one is unambiguously more specialized.

Despite the former being unambiguously more specialized.

This unambiguous specialization behavior works correctly for normal, non-platform config_setting()s that use the values parameter instead of constraint_values, and is documented here.

I’m seeing this on the latest macOS (12.1) with the latest Bazel rolling (6.0.0-pre.20220112.2).

Thanks so much for taking a peek! Chris (ex-Googler)

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 18 (17 by maintainers)

Commits related to this issue

Most upvoted comments

an update on this. commit https://github.com/bazelbuild/bazel/commit/0e7051a55ab0396feeea7b6f9750594a02ef9c34 was made to allow config_setting to match on constraint_values, but it seems that the implementation for specialization to work with constraint_values were left out. I also doubled checked with katre@ and brandjon@. Since users are expeciting this behavior and it’s better to keep it consistent with the behavior of select(), we should fix this.

Briefly looking at our code, i think we would need to pass the constraint values in the ConfigMatchingProvider here https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/rules/config/ConfigSetting.java#L125

and the information could be used to “refines” a condition here https://github.com/bazelbuild/bazel/blob/master/src/main/java/com/google/devtools/build/lib/analysis/config/ConfigMatchingProvider.java#L77

I probably will have time to work on this in the next iteration.

Yes we can close this one. Thanks!