Skip to content

Add refines_constraint_value attribute to constraint_setting#29655

Draft
fmeum wants to merge 2 commits into
bazelbuild:masterfrom
fmeum:hierarchical
Draft

Add refines_constraint_value attribute to constraint_setting#29655
fmeum wants to merge 2 commits into
bazelbuild:masterfrom
fmeum:hierarchical

Conversation

@fmeum
Copy link
Copy Markdown
Collaborator

@fmeum fmeum commented May 26, 2026

Implements Hierarchical constraint settings (discussion #28877).

Adds a new optional, label-valued refines_constraint_value attribute on constraint_setting. This lets a constraint_setting express that any of its constraint_values refine (i.e., imply) a particular constraint_value of another setting (e.g. a //libc/glibc:version setting refining //libc:glibc).

This has two consequences:

  • Platform validation. Any platform that declares a non-default constraint_value for a refining setting must also declare the refined constraint_value (directly or via a parent platform). Bazel reports an actionable error including a buildozer fixup.

  • select() specificity. A condition that matches via a refining constraint_value is treated as more specific than a condition that matches only via the refined constraint_value, so both can co-exist in the same select() without producing an "ambiguous match" error.

Note: the design doc calls this attribute refines_value. It is renamed to refines_constraint_value here for symmetry with default_constraint_value.

RELNOTES: The new refines_constraint_value attribute on constraint_setting can be used to indicate that any non-default value for that setting specified on a platform requires the refined value to also be specified.

@google-cla
Copy link
Copy Markdown

google-cla Bot commented May 26, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Adds a new optional, label-valued `refines_constraint_value` attribute to
`constraint_setting`. This makes it possible to express that a constraint
setting hierarchically refines a constraint value of another setting, e.g.
a glibc version setting refining the libc=glibc value.

Semantics:
* Any platform that declares a non-default constraint_value for a refining
  setting must also declare the refined constraint_value (directly or via a
  parent platform). The error message includes a buildozer fixup command.
  Platforms that resolve to the setting's default value (whether implicitly
  or by declaring it explicitly) do not pull in the refined value, so a
  "no information" default can coexist with refinement.
* In a select(), a condition that matches via a refining constraint_value is
  treated as more specific than a condition that matches via the refined
  constraint_value, so the two can co-exist without producing an "ambiguous
  match" error.

`refines_constraint_value` and `default_constraint_value` may be set on the
same `constraint_setting`.

Implementation:
* `ConstraintSettingInfo` stores the immediate refines label plus a pointer
  to the refined setting; the transitive refinement chain is materialized on
  demand to keep storage linear in the depth of the refinement graph (which
  can be 40+ levels deep in practice).
* `ConfigSetting` includes the refinement chain in
  `ConfigMatchingProvider.constraintValuesSetting`, so the existing
  `refines()` set-containment logic picks up refinement relationships.
* `Platform` validates that refined constraint values are present, checking
  the entire parent chain. Default refining values are exempt.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant