diff --git a/uv/private/constraints/platform/defs.bzl b/uv/private/constraints/platform/defs.bzl index bb257927..93f5803c 100644 --- a/uv/private/constraints/platform/defs.bzl +++ b/uv/private/constraints/platform/defs.bzl @@ -38,23 +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 = 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, - ) - _platform_version_at_least( - name = flag_name, - at_least = version, - visibility = ["//visibility:private"], - **kwargs - ) - def _platform_version_at_least_impl(ctx): flag_value = ctx.attr._major_minor[BuildSettingInfo].value @@ -67,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 c9d11aff..94022704 100644 --- a/uv/private/constraints/platform/macro.bzl +++ b/uv/private/constraints/platform/macro.bzl @@ -2,8 +2,7 @@ """ -load("@bazel_skylib//lib:selects.bzl", "selects") -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,32 +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) - is_platform_version_at_least( - name = name, - version = "{}.{}".format(major, minor), - visibility = ["//visibility:private"], + major_minor = (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: - selects.config_setting_group( - name = "macosx_{}_{}_{}".format(major, minor, arch), - match_all = [ - name, - ":is_libsystem", + native.config_setting( + name = "macosx_%s_%s_%s" % (major, minor, arch), + flag_values = { + version_flag: "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, ) @@ -136,19 +142,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) - is_platform_version_at_least( - name = name, - version = "{}.{}".format(major, minor), - visibility = ["//visibility:private"], + 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: - selects.config_setting_group( + native.config_setting( name = "manylinux_{}_{}_{}".format(major, minor, arch), - match_all = [ - name, - ":is_glibc", + flag_values = { + version_flag: "true", + ":platform_libc": "glibc", + }, + constraint_values = [ "@platforms//os:linux", "@platforms//cpu:{}".format(platform_repo_name_mangling.get(arch, arch)), ], @@ -199,19 +206,20 @@ def generate_musllinux(visibility): [2, 1], # Hypothetical [2, 2], # Hypothetical ]: - name = "is_musl_at_least_{}_{}".format(major, minor) - is_platform_version_at_least( - name = name, - version = "{}.{}".format(major, minor), - visibility = ["//visibility:private"], + 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: - selects.config_setting_group( + native.config_setting( name = "musllinux_{}_{}_{}".format(major, minor, arch), - match_all = [ - name, - ":is_musl", + flag_values = { + version_flag: "true", + ":platform_libc": "musl", + }, + constraint_values = [ "@platforms//os:linux", "@platforms//cpu:{}".format(platform_repo_name_mangling.get(arch, arch)), ],