@@ -70,6 +70,7 @@ suffix.
7070:::
7171"""
7272
73+ load ("@bazel_skylib//lib:selects.bzl" , "selects" )
7374load ("//python/private:flags.bzl" , "LibcFlag" )
7475load (":flags.bzl" , "INTERNAL_FLAGS" , "UniversalWhlFlag" )
7576
@@ -112,7 +113,7 @@ def config_settings(
112113 muslc_versions = [],
113114 osx_versions = [],
114115 name = None ,
115- platform_constraint_values = {},
116+ platform_target_settings = {},
116117 ** kwargs ):
117118 """Generate all of the pip config settings.
118119
@@ -126,7 +127,7 @@ def config_settings(
126127 configure config settings for.
127128 osx_versions (list[str]): The list of OSX OS versions to configure
128129 config settings for.
129- platform_constraint_values : {type}`dict[str, list[str]]` the constraint
130+ platform_target_settings : {type}`dict[str, list[str]]` the constraint
130131 values to use instead of the default ones.
131132 **kwargs: Other args passed to the underlying implementations, such as
132133 {obj}`native`.
@@ -140,13 +141,24 @@ def config_settings(
140141 # TODO @aignas 2025-06-15: allowing universal2 and platform specific wheels in one
141142 # closure is making things maybe a little bit too complicated.
142143 "osx_universal2" : ["@platforms//os:osx" ],
143- } | platform_constraint_values
144+ } | platform_target_settings
144145
145146 for python_version in python_versions :
146- for platform_name , constraint_values in target_platforms .items ():
147+ for platform_name , target_settings in target_platforms .items ():
147148 suffix = "_{}" .format (platform_name ) if platform_name else ""
148149 os , _ , cpu = platform_name .partition ("_" )
149150
151+ # We parse the target settings and if there is a "platforms//os" or
152+ # "platforms//cpu" value in here, we also add it into the constraint_values
153+ #
154+ # this is to ensure that we can still pass all of the unit tests for config
155+ # setting specialization.
156+ constraint_values = []
157+ for setting in target_settings :
158+ setting_label = Label (setting )
159+ if setting_label .repo_name == "platforms" and setting_label .package in ["os" , "cpu" ]:
160+ constraint_values .append (setting )
161+
150162 _dist_config_settings (
151163 suffix = suffix ,
152164 plat_flag_values = _plat_flag_values (
@@ -156,6 +168,7 @@ def config_settings(
156168 glibc_versions = glibc_versions ,
157169 muslc_versions = muslc_versions ,
158170 ),
171+ target_settings = target_settings ,
159172 constraint_values = constraint_values ,
160173 python_version = python_version ,
161174 ** kwargs
@@ -316,7 +329,7 @@ def _plat_flag_values(os, cpu, osx_versions, glibc_versions, muslc_versions):
316329
317330 return ret
318331
319- def _dist_config_setting (* , name , compatible_with = None , native = native , ** kwargs ):
332+ def _dist_config_setting (* , name , compatible_with = None , selects = selects , native = native , target_settings = None , ** kwargs ):
320333 """A macro to create a target for matching Python binary and source distributions.
321334
322335 Args:
@@ -325,6 +338,12 @@ def _dist_config_setting(*, name, compatible_with = None, native = native, **kwa
325338 compatible with the given dist config setting. For example, if only
326339 non-freethreaded python builds are allowed, add
327340 FLAGS.is_py_non_freethreaded here.
341+ target_settings: {type}`list[str | Label]` the list of target settings that must
342+ be matched before we try to evaluate the config_setting that we may create in
343+ this function.
344+ selects (struct): The struct containing config_setting_group function
345+ to use for creating config setting groups. Can be overridden for unit tests
346+ reasons.
328347 native (struct): The struct containing alias and config_setting rules
329348 to use for creating the objects. Can be overridden for unit tests
330349 reasons.
@@ -344,4 +363,14 @@ def _dist_config_setting(*, name, compatible_with = None, native = native, **kwa
344363 )
345364 name = dist_config_setting_name
346365
347- native .config_setting (name = name , ** kwargs )
366+ # first define the config setting that has all of the constraint values
367+ _name = "_" + name
368+ native .config_setting (
369+ name = _name ,
370+ ** kwargs
371+ )
372+ selects .config_setting_group (
373+ name = name ,
374+ match_all = target_settings + [_name ],
375+ visibility = kwargs .get ("visibility" ),
376+ )
0 commit comments