From d613e0406ad5f06939dd1848adefcdf7b5798915 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Sun, 23 Nov 2025 13:15:10 -0500 Subject: [PATCH 1/3] Generate fewer targets for platform constraints --- uv/private/constraints/platform/defs.bzl | 13 ++----- uv/private/constraints/platform/macro.bzl | 44 ++++++++++++----------- 2 files changed, 26 insertions(+), 31 deletions(-) diff --git a/uv/private/constraints/platform/defs.bzl b/uv/private/constraints/platform/defs.bzl index bb257927..998410bd 100644 --- a/uv/private/constraints/platform/defs.bzl +++ b/uv/private/constraints/platform/defs.bzl @@ -38,18 +38,9 @@ def supported_platform(platform_tag): # Adapted from rules_python's config_settings.bzl MAJOR_MINOR_FLAG = Label("//uv/private/constraints/platform:platform_version") -def is_platform_version_at_least(name, version = None, visibility = None, **kwargs): - version = version or name - flag_name = "_{}_flag".format(name) - native.config_setting( - name = name, - flag_values = { - flag_name: "true", - }, - visibility = visibility, - ) +def is_platform_version_at_least(name, version, **kwargs): _platform_version_at_least( - name = flag_name, + name = name, at_least = version, visibility = ["//visibility:private"], **kwargs diff --git a/uv/private/constraints/platform/macro.bzl b/uv/private/constraints/platform/macro.bzl index c9d11aff..c257aec6 100644 --- a/uv/private/constraints/platform/macro.bzl +++ b/uv/private/constraints/platform/macro.bzl @@ -75,18 +75,20 @@ def generate_macos(visibility): for major in range(10, 30): for minor in range(0, 20): name = "is_macos_at_least_{}_{}".format(major, minor) + flag_name = "_{}_flag".format(name) is_platform_version_at_least( - name = name, + name = flag_name, version = "{}.{}".format(major, minor), - visibility = ["//visibility:private"], ) for arch in arches: - selects.config_setting_group( + native.config_setting( name = "macosx_{}_{}_{}".format(major, minor, arch), - match_all = [ - name, - ":is_libsystem", + flag_values = { + flag_name: "true", + ":platform_libc": "libsystem", + }, + constraint_values = [ "@platforms//os:osx", "@platforms//cpu:{}".format(platform_repo_name_mangling.get(arch, arch)), ], @@ -136,19 +138,20 @@ def generate_manylinux(visibility): # glibc 1.X ran for not that long and was in the 90s for major in [2]: for minor in range(0, 51): - name = "is_glibc_at_least_{}_{}".format(major, minor) + flag_name = "is_glibc_at_least_{}_{}".format(major, minor) is_platform_version_at_least( - name = name, + name = flag_name, version = "{}.{}".format(major, minor), - visibility = ["//visibility:private"], ) for arch in arches: - selects.config_setting_group( + native.config_setting( name = "manylinux_{}_{}_{}".format(major, minor, arch), - match_all = [ - name, - ":is_glibc", + flag_values = { + flag_name: "true", + ":platform_libc": "glibc", + }, + constraint_values = [ "@platforms//os:linux", "@platforms//cpu:{}".format(platform_repo_name_mangling.get(arch, arch)), ], @@ -199,19 +202,20 @@ def generate_musllinux(visibility): [2, 1], # Hypothetical [2, 2], # Hypothetical ]: - name = "is_musl_at_least_{}_{}".format(major, minor) + flag_name = "is_musl_at_least_{}_{}".format(major, minor) is_platform_version_at_least( - name = name, + name = flag_name, version = "{}.{}".format(major, minor), - visibility = ["//visibility:private"], ) for arch in arches: - selects.config_setting_group( + native.config_setting( name = "musllinux_{}_{}_{}".format(major, minor, arch), - match_all = [ - name, - ":is_musl", + flag_values = { + flag_name: "true", + ":platform_libc": "musl", + }, + constraint_values = [ "@platforms//os:linux", "@platforms//cpu:{}".format(platform_repo_name_mangling.get(arch, arch)), ], From 1c88783d2402f844172d915fef494a5d71313551 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Sun, 23 Nov 2025 13:50:19 -0500 Subject: [PATCH 2/3] Remove ORs --- uv/private/constraints/platform/macro.bzl | 28 +++++++++++++---------- 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/uv/private/constraints/platform/macro.bzl b/uv/private/constraints/platform/macro.bzl index c257aec6..9b0735d0 100644 --- a/uv/private/constraints/platform/macro.bzl +++ b/uv/private/constraints/platform/macro.bzl @@ -2,7 +2,6 @@ """ -load("@bazel_skylib//lib:selects.bzl", "selects") load(":defs.bzl", "is_platform_version_at_least") ## These are defined but we're ignoring them for now. @@ -74,34 +73,39 @@ def generate_macos(visibility): # Go a bit out into the future there for major in range(10, 30): for minor in range(0, 20): - name = "is_macos_at_least_{}_{}".format(major, minor) - flag_name = "_{}_flag".format(name) + major_minor = (major, minor) + flag_name = "_is_macos_at_least_%s_%s_flat" % major_minor is_platform_version_at_least( name = flag_name, - version = "{}.{}".format(major, minor), + version = "%s.%s" % major_minor, ) for arch in arches: native.config_setting( - name = "macosx_{}_{}_{}".format(major, minor, arch), + name = "macosx_%s_%s_%s" % (major, minor, arch), flag_values = { flag_name: "true", ":platform_libc": "libsystem", }, constraint_values = [ "@platforms//os:osx", - "@platforms//cpu:{}".format(platform_repo_name_mangling.get(arch, arch)), + "@platforms//cpu:" + platform_repo_name_mangling.get(arch, arch), ], visibility = visibility, ) for group, members in arch_groups.items(): - selects.config_setting_group( - name = "macosx_{}_{}_{}".format(major, minor, group), - match_any = [ - ":macosx_{}_{}_{}".format(major, minor, it) - for it in members - ], + options = [ + ":macosx_%s_%s_%s" % (major, minor, it) + for it in members + ] + + branches = {opt: opt for opt in options[:-1]} + branches["//conditions:default"] = options[-1] + + native.alias( + name = "macosx_%s_%s_%s" % (major, minor, group), + actual = select(branches), visibility = visibility, ) From a910638a557a8f521bcbafb18fca06cb9deed787 Mon Sep 17 00:00:00 2001 From: David Zbarsky Date: Sun, 23 Nov 2025 14:06:40 -0500 Subject: [PATCH 3/3] cleanup --- uv/private/constraints/platform/defs.bzl | 10 +------ uv/private/constraints/platform/macro.bzl | 32 +++++++++++------------ 2 files changed, 17 insertions(+), 25 deletions(-) diff --git a/uv/private/constraints/platform/defs.bzl b/uv/private/constraints/platform/defs.bzl index 998410bd..93f5803c 100644 --- a/uv/private/constraints/platform/defs.bzl +++ b/uv/private/constraints/platform/defs.bzl @@ -38,14 +38,6 @@ def supported_platform(platform_tag): # Adapted from rules_python's config_settings.bzl MAJOR_MINOR_FLAG = Label("//uv/private/constraints/platform:platform_version") -def is_platform_version_at_least(name, version, **kwargs): - _platform_version_at_least( - name = name, - at_least = version, - visibility = ["//visibility:private"], - **kwargs - ) - def _platform_version_at_least_impl(ctx): flag_value = ctx.attr._major_minor[BuildSettingInfo].value @@ -58,7 +50,7 @@ def _platform_version_at_least_impl(ctx): value = "true" if current >= at_least else "false" return [config_common.FeatureFlagInfo(value = value)] -_platform_version_at_least = rule( +platform_version_at_least = rule( implementation = _platform_version_at_least_impl, attrs = { "at_least": attr.string(mandatory = True), diff --git a/uv/private/constraints/platform/macro.bzl b/uv/private/constraints/platform/macro.bzl index 9b0735d0..94022704 100644 --- a/uv/private/constraints/platform/macro.bzl +++ b/uv/private/constraints/platform/macro.bzl @@ -2,7 +2,7 @@ """ -load(":defs.bzl", "is_platform_version_at_least") +load(":defs.bzl", "platform_version_at_least") ## These are defined but we're ignoring them for now. # android_21_arm64_v8a @@ -74,17 +74,17 @@ def generate_macos(visibility): for major in range(10, 30): for minor in range(0, 20): major_minor = (major, minor) - flag_name = "_is_macos_at_least_%s_%s_flat" % major_minor - is_platform_version_at_least( - name = flag_name, - version = "%s.%s" % major_minor, + version_flag = "_is_macos_at_least_%s_%s_flat" % major_minor + platform_version_at_least( + name = version_flag, + at_least = "%s.%s" % major_minor, ) for arch in arches: native.config_setting( name = "macosx_%s_%s_%s" % (major, minor, arch), flag_values = { - flag_name: "true", + version_flag: "true", ":platform_libc": "libsystem", }, constraint_values = [ @@ -142,17 +142,17 @@ def generate_manylinux(visibility): # glibc 1.X ran for not that long and was in the 90s for major in [2]: for minor in range(0, 51): - flag_name = "is_glibc_at_least_{}_{}".format(major, minor) - is_platform_version_at_least( - name = flag_name, - version = "{}.{}".format(major, minor), + version_flag = "_is_glibc_at_least_{}_{}".format(major, minor) + platform_version_at_least( + name = version_flag, + at_least = "{}.{}".format(major, minor), ) for arch in arches: native.config_setting( name = "manylinux_{}_{}_{}".format(major, minor, arch), flag_values = { - flag_name: "true", + version_flag: "true", ":platform_libc": "glibc", }, constraint_values = [ @@ -206,17 +206,17 @@ def generate_musllinux(visibility): [2, 1], # Hypothetical [2, 2], # Hypothetical ]: - flag_name = "is_musl_at_least_{}_{}".format(major, minor) - is_platform_version_at_least( - name = flag_name, - version = "{}.{}".format(major, minor), + version_flag = "_is_musl_at_least_{}_{}".format(major, minor) + platform_version_at_least( + name = version_flag, + at_least = "{}.{}".format(major, minor), ) for arch in arches: native.config_setting( name = "musllinux_{}_{}_{}".format(major, minor, arch), flag_values = { - flag_name: "true", + version_flag: "true", ":platform_libc": "musl", }, constraint_values = [