@@ -55,6 +55,128 @@ def _whl_mods_impl(whl_mods_dict):
5555 whl_mods = whl_mods ,
5656 )
5757
58+ def default_platforms ():
59+ """Return the built-in default platform definitions.
60+
61+ These provide the platform metadata needed for pip wheel resolution
62+ (whl_abi_tags, whl_platform_tags, config_settings, etc.) across all
63+ common OS/arch combinations. They are always used as the starting point
64+ for build_config; root modules can override individual platforms via
65+ pip.default tags.
66+
67+ Returns:
68+ A dict of platform name to platform config dicts.
69+ """
70+ # NOTE @aignas 2025-07-06: we define these platforms to keep backwards compatibility. Whilst we
71+ # stabilize the API this list may be updated with a mention in the CHANGELOG.
72+
73+ platforms = {}
74+
75+ # Linux platforms
76+ for cpu in ["x86_64" , "aarch64" ]:
77+ for freethreaded in ["" , "_freethreaded" ]:
78+ platform_name = "linux_{}{}" .format (cpu , freethreaded )
79+ platforms [platform_name ] = {
80+ "arch_name" : cpu ,
81+ "config_settings" : [
82+ "@platforms//cpu:{}" .format (cpu ),
83+ "@platforms//os:linux" ,
84+ "//python/config_settings:_is_py_freethreaded_{}" .format (
85+ "yes" if freethreaded else "no" ,
86+ ),
87+ ],
88+ "env" : {"platform_version" : "0" },
89+ "marker" : "python_version >= '3.13'" if freethreaded else "" ,
90+ "name" : platform_name ,
91+ "os_name" : "linux" ,
92+ "whl_abi_tags" : ["cp{major}{minor}t" ] if freethreaded else [
93+ "abi3" ,
94+ "cp{major}{minor}" ,
95+ ],
96+ "whl_platform_tags" : [
97+ "linux_{}" .format (cpu ),
98+ "manylinux_*_{}" .format (cpu ),
99+ ],
100+ }
101+
102+ # macOS platforms
103+ for cpu , platform_tag_cpus in {
104+ "aarch64" : ["universal2" , "arm64" ],
105+ "x86_64" : ["universal2" , "x86_64" ],
106+ }.items ():
107+ for freethreaded in ["" , "_freethreaded" ]:
108+ platform_name = "osx_{}{}" .format (cpu , freethreaded )
109+ platforms [platform_name ] = {
110+ "arch_name" : cpu ,
111+ "config_settings" : [
112+ "@platforms//cpu:{}" .format (cpu ),
113+ "@platforms//os:osx" ,
114+ "//python/config_settings:_is_py_freethreaded_{}" .format (
115+ "yes" if freethreaded else "no" ,
116+ ),
117+ ],
118+ "env" : {"platform_version" : "14.0" },
119+ "marker" : "python_version >= '3.13'" if freethreaded else "" ,
120+ "name" : platform_name ,
121+ "os_name" : "osx" ,
122+ "whl_abi_tags" : ["cp{major}{minor}t" ] if freethreaded else [
123+ "abi3" ,
124+ "cp{major}{minor}" ,
125+ ],
126+ "whl_platform_tags" : [
127+ "macosx_*_{}" .format (suffix )
128+ for suffix in platform_tag_cpus
129+ ],
130+ }
131+
132+ # Windows x86_64 platforms
133+ for freethreaded in ["" , "_freethreaded" ]:
134+ platform_name = "windows_x86_64{}" .format (freethreaded )
135+ platforms [platform_name ] = {
136+ "arch_name" : "x86_64" ,
137+ "config_settings" : [
138+ "@platforms//cpu:x86_64" ,
139+ "@platforms//os:windows" ,
140+ "//python/config_settings:_is_py_freethreaded_{}" .format (
141+ "yes" if freethreaded else "no" ,
142+ ),
143+ ],
144+ "env" : {"platform_version" : "0" },
145+ "marker" : "python_version >= '3.13'" if freethreaded else "" ,
146+ "name" : platform_name ,
147+ "os_name" : "windows" ,
148+ "whl_abi_tags" : ["cp{major}{minor}t" ] if freethreaded else [
149+ "abi3" ,
150+ "cp{major}{minor}" ,
151+ ],
152+ "whl_platform_tags" : ["win_amd64" ],
153+ }
154+
155+ # Windows aarch64 platforms
156+ for freethreaded in ["" , "_freethreaded" ]:
157+ platform_name = "windows_aarch64{}" .format (freethreaded )
158+ platforms [platform_name ] = {
159+ "arch_name" : "aarch64" ,
160+ "config_settings" : [
161+ "@platforms//cpu:aarch64" ,
162+ "@platforms//os:windows" ,
163+ "//python/config_settings:_is_py_freethreaded_{}" .format (
164+ "yes" if freethreaded else "no" ,
165+ ),
166+ ],
167+ "env" : {"platform_version" : "0" },
168+ "marker" : "python_version >= '3.13'" if freethreaded else "python_version >= '3.11'" ,
169+ "name" : platform_name ,
170+ "os_name" : "windows" ,
171+ "whl_abi_tags" : ["cp{major}{minor}t" ] if freethreaded else [
172+ "abi3" ,
173+ "cp{major}{minor}" ,
174+ ],
175+ "whl_platform_tags" : ["win_arm64" ],
176+ }
177+
178+ return platforms
179+
58180def _configure (config , * , override = False , ** kwargs ):
59181 """Set the value in the config if the value is provided"""
60182 env = kwargs .get ("env" )
@@ -82,7 +204,7 @@ def build_config(
82204 A struct with the configuration.
83205 """
84206 defaults = {
85- "platforms" : {} ,
207+ "platforms" : default_platforms () ,
86208 }
87209 for mod in module_ctx .modules :
88210 if not (mod .is_root or mod .name == "rules_python" ):
0 commit comments