Skip to content

Migrate darwin config_settings to constraint_values for --platforms compatibility #46572

Closed

Description

@phlax

Background

The darwin_x86_64 and darwin_arm64 config_settings in bazel/BUILD are defined using the legacy values = {"cpu": ...} form:

config_setting(
    name = "darwin_x86_64",
    values = {"cpu": "darwin_x86_64"},
)

config_setting(
    name = "darwin_arm64",
    values = {"cpu": "darwin_arm64"},
)

(see bazel/BUILD L686-L694)

This is inconsistent with the linux equivalents, which use the modern constraint_values form, e.g.:

config_setting(
    name = "linux_x86_64",
    constraint_values = [
        "@platforms//cpu:x86_64",
        "@platforms//os:linux",
    ],
)

Problem

Under --platforms-based builds, the legacy values = {"cpu": ...} darwin settings may not match. Any select() keyed on //bazel:darwin_x86_64 / //bazel:darwin_arm64 can therefore silently fall through to //conditions:default on macOS, rather than matching the intended darwin branch.

This was surfaced in review of #46570 (discussion r3735759962), where the prebuilt protoc select mixed constraint-based linux keys with legacy darwin keys. That PR is being kept macos-arm-only to avoid scope creep, but the underlying inconsistency is a pre-existing issue that likely affects other selects across the repo, not just protoc.

Proposed fix

Migrate the darwin config settings to constraint_values, mirroring the linux pattern. Both arm64 and x86_64 should be covered (macOS x86_64 support should be retained):

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

config_setting(
    name = "macos_x86_64",
    constraint_values = [
        "@platforms//cpu:x86_64",
        "@platforms//os:osx",
    ],
)

Considerations

  • The legacy darwin_x86_64 / darwin_arm64 names are referenced in several places in bazel/BUILD (e.g. apple, darwin_any, x86, not_x86_ppc, not_x86 config_setting_groups) and potentially elsewhere in the repo. All usages need to be audited and updated (or the legacy settings kept as aliases during transition).
  • Audit all select()s that key on darwin settings to ensure they behave correctly under --platforms.
  • Confirm the correct @platforms//os constraint name for macOS (osx) matches what the toolchains resolve to.

Activity

  1. dio commented on Aug 11, 2026

    @dio
    Member

    @phlax, are you already working on this? If not, I’d be happy to pick it up. I have a small compatibility-preserving spike ready.

  2. phlax commented on Aug 11, 2026

    @phlax
    MemberAuthor

    i wasnt yet - it surfaced in bot reviews of another pr - so separated out here - would be great if you are up for addressing

  3. dio commented on Aug 11, 2026

    @dio
    Member

    Thanks, I’ll take it.

  4. added a commit that references this issue on Aug 14, 2026
    e95a225
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions