@@ -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_config_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_config_settings : {type}`dict[str, list[str]]` the constraint
130131 values to use instead of the default ones. Key are platform names
131132 (a human-friendly platform string). Values are lists of
132133 `constraint_value` label strings.
@@ -142,13 +143,24 @@ def config_settings(
142143 # TODO @aignas 2025-06-15: allowing universal2 and platform specific wheels in one
143144 # closure is making things maybe a little bit too complicated.
144145 "osx_universal2" : ["@platforms//os:osx" ],
145- } | platform_constraint_values
146+ } | platform_config_settings
146147
147148 for python_version in python_versions :
148- for platform_name , constraint_values in target_platforms .items ():
149+ for platform_name , config_settings in target_platforms .items ():
149150 suffix = "_{}" .format (platform_name ) if platform_name else ""
150151 os , _ , cpu = platform_name .partition ("_" )
151152
153+ # We parse the target settings and if there is a "platforms//os" or
154+ # "platforms//cpu" value in here, we also add it into the constraint_values
155+ #
156+ # this is to ensure that we can still pass all of the unit tests for config
157+ # setting specialization.
158+ constraint_values = []
159+ for setting in config_settings :
160+ setting_label = Label (setting )
161+ if setting_label .repo_name == "platforms" and setting_label .package in ["os" , "cpu" ]:
162+ constraint_values .append (setting )
163+
152164 _dist_config_settings (
153165 suffix = suffix ,
154166 plat_flag_values = _plat_flag_values (
@@ -158,6 +170,7 @@ def config_settings(
158170 glibc_versions = glibc_versions ,
159171 muslc_versions = muslc_versions ,
160172 ),
173+ config_settings = config_settings ,
161174 constraint_values = constraint_values ,
162175 python_version = python_version ,
163176 ** kwargs
@@ -318,7 +331,7 @@ def _plat_flag_values(os, cpu, osx_versions, glibc_versions, muslc_versions):
318331
319332 return ret
320333
321- def _dist_config_setting (* , name , compatible_with = None , native = native , ** kwargs ):
334+ def _dist_config_setting (* , name , compatible_with = None , selects = selects , native = native , config_settings = None , ** kwargs ):
322335 """A macro to create a target for matching Python binary and source distributions.
323336
324337 Args:
@@ -327,6 +340,12 @@ def _dist_config_setting(*, name, compatible_with = None, native = native, **kwa
327340 compatible with the given dist config setting. For example, if only
328341 non-freethreaded python builds are allowed, add
329342 FLAGS._is_py_freethreaded_no here.
343+ config_settings: {type}`list[str | Label]` the list of target settings that must
344+ be matched before we try to evaluate the config_setting that we may create in
345+ this function.
346+ selects (struct): The struct containing config_setting_group function
347+ to use for creating config setting groups. Can be overridden for unit tests
348+ reasons.
330349 native (struct): The struct containing alias and config_setting rules
331350 to use for creating the objects. Can be overridden for unit tests
332351 reasons.
@@ -346,4 +365,14 @@ def _dist_config_setting(*, name, compatible_with = None, native = native, **kwa
346365 )
347366 name = dist_config_setting_name
348367
349- native .config_setting (name = name , ** kwargs )
368+ # first define the config setting that has all of the constraint values
369+ _name = "_" + name
370+ native .config_setting (
371+ name = _name ,
372+ ** kwargs
373+ )
374+ selects .config_setting_group (
375+ name = name ,
376+ match_all = config_settings + [_name ],
377+ visibility = kwargs .get ("visibility" ),
378+ )
0 commit comments