Skip to content

[9.3.0] Don't crash on a constraint value repeated via an alias (https://github.com/bazelbuild/bazel/pull/30488) - #30534

Open
bazel-io wants to merge 1 commit into
bazelbuild:release-9.3.0from
bazel-io:cp30488-9.3.0-224951
Open

[9.3.0] Don't crash on a constraint value repeated via an alias (https://github.com/bazelbuild/bazel/pull/30488)#30534
bazel-io wants to merge 1 commit into
bazelbuild:release-9.3.0from
bazel-io:cp30488-9.3.0-224951

Conversation

@bazel-io

Copy link
Copy Markdown
Member

Description

ConstraintCollection.validateConstraints explicitly permits multiple instances of the same constraint value and only rejects different values for the same constraint setting. ConstraintCollection.Builder#build then collected the values into an ImmutableMap keyed by constraint setting without a merge function, so any repetition crashed Bazel with

Multiple entries with same key: ConstraintSettingInfo(...)=ConstraintValueInfo(...)

This is easy to hit accidentally when a constraint value is referenced both directly and through an alias, e.g. @bazel_tools//tools/cpp:mingw and @rules_cc//cc/private/toolchain:mingw in a toolchain's target_compatible_with.

Since validation guarantees that all values for a given setting are equal at this point, keep the first one.

Motivation

Fixes bazel-contrib/rules_go#4665

Build API Changes

No

Checklist

  • I have added tests for the new use cases (if any).
  • I have updated the documentation (if applicable).

Release Notes

RELNOTES: None

Closes #30488.

PiperOrigin-RevId: 956129840
Change-Id: Ic5771803e104d1e3550527a11e6403dcb3cfe535

Commit afd06ce

…0488)

### Description
`ConstraintCollection.validateConstraints` explicitly permits multiple instances of the *same* constraint value and only rejects different values for the same constraint setting. `ConstraintCollection.Builder#build` then collected the values into an `ImmutableMap` keyed by constraint setting without a merge function, so any repetition crashed Bazel with

    Multiple entries with same key: ConstraintSettingInfo(...)=ConstraintValueInfo(...)

This is easy to hit accidentally when a constraint value is referenced both directly and through an `alias`, e.g. `@bazel_tools//tools/cpp:mingw` and `@rules_cc//cc/private/toolchain:mingw` in a `toolchain`'s `target_compatible_with`.

Since validation guarantees that all values for a given setting are equal at this point, keep the first one.

### Motivation
Fixes bazel-contrib/rules_go#4665

### Build API Changes

No

### Checklist

- [x] I have added tests for the new use cases (if any).
- [x] I have updated the documentation (if applicable).

### Release Notes

RELNOTES: None

Closes bazelbuild#30488.

PiperOrigin-RevId: 956129840
Change-Id: Ic5771803e104d1e3550527a11e6403dcb3cfe535
@bazel-io
bazel-io requested a review from a team as a code owner July 29, 2026 22:50
@bazel-io bazel-io added team-Configurability platforms, toolchains, cquery, select(), config transitions awaiting-review PR is awaiting review from an assigned reviewer labels Jul 29, 2026
@bazel-io
bazel-io requested review from gregestren and katre July 29, 2026 22:51
@iancha1992
iancha1992 enabled auto-merge July 30, 2026 00:36
@iancha1992
iancha1992 removed the request for review from katre July 30, 2026 00:36
@github-actions github-actions Bot added the community-reviewed Reviewed by a trusted community contributor label Jul 30, 2026
@iancha1992
iancha1992 added this pull request to the merge queue Jul 30, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to no response for status checks Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting-review PR is awaiting review from an assigned reviewer community-reviewed Reviewed by a trusted community contributor team-Configurability platforms, toolchains, cquery, select(), config transitions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants