@@ -34,12 +34,13 @@ def parse_modules(*, module_ctx, _fail = fail):
3434
3535 Returns:
3636 A struct with the following attributes:
37- * `toolchains`: The list of toolchains to register. The last
38- element is special and is treated as the default toolchain.
39- * `defaults`: The default `kwargs` passed to
40- {bzl:obj}`python_register_toolchains`.
41- * `debug_info`: {type}`None | dict` extra information to be passed
42- to the debug repo.
37+ * `toolchains`: The list of toolchains to register. The last
38+ element is special and is treated as the default toolchain.
39+ * `config`: Various toolchain config, see `_get_toolchain_config`.
40+ * `debug_info`: {type}`None | dict` extra information to be passed
41+ to the debug repo.
42+ * `platforms`: {type}`dict[str, platform_info]` of the base set of
43+ platforms toolchains should be created for, if possible.
4344 """
4445 if module_ctx .os .environ .get ("RULES_PYTHON_BZLMOD_DEBUG" , "0" ) == "1" :
4546 debug_info = {
@@ -285,11 +286,12 @@ def _python_impl(module_ctx):
285286 kwargs .update (py .config .kwargs .get (toolchain_info .python_version , {}))
286287 kwargs .update (py .config .kwargs .get (full_python_version , {}))
287288 kwargs .update (py .config .default )
288- loaded_platforms [ full_python_version ] = python_register_toolchains (
289+ toolchain_registered_platforms = python_register_toolchains (
289290 name = toolchain_info .name ,
290291 _internal_bzlmod_toolchain_call = True ,
291292 ** kwargs
292293 )
294+ loaded_platforms [full_python_version ] = toolchain_registered_platforms
293295
294296 # List of the base names ("python_3_10") for the toolchain repos
295297 base_toolchain_repo_names = []
@@ -332,20 +334,19 @@ def _python_impl(module_ctx):
332334 base_name = t .name
333335 base_toolchain_repo_names .append (base_name )
334336 fv = full_version (version = t .python_version , minor_mapping = py .config .minor_mapping )
335- for platform in loaded_platforms [fv ]:
336- if platform not in PLATFORMS :
337- continue
337+ platforms = loaded_platforms [fv ]
338+ for platform_name , platform_info in platforms .items ():
338339 key = str (len (toolchain_names ))
339340
340- full_name = "{}_{}" .format (base_name , platform )
341+ full_name = "{}_{}" .format (base_name , platform_name )
341342 toolchain_names .append (full_name )
342343 toolchain_repo_names [key ] = full_name
343- toolchain_tcw_map [key ] = PLATFORMS [ platform ] .compatible_with
344+ toolchain_tcw_map [key ] = platform_info .compatible_with
344345
345346 # The target_settings attribute may not be present for users
346347 # patching python/versions.bzl.
347- toolchain_ts_map [key ] = getattr (PLATFORMS [ platform ] , "target_settings" , [])
348- toolchain_platform_keys [key ] = platform
348+ toolchain_ts_map [key ] = getattr (platform_info , "target_settings" , [])
349+ toolchain_platform_keys [key ] = platform_name
349350 toolchain_python_versions [key ] = fv
350351
351352 # The last toolchain is the default; it can't have version constraints
@@ -483,9 +484,9 @@ def _process_single_version_overrides(*, tag, _fail = fail, default):
483484 return
484485
485486 for platform in (tag .sha256 or []):
486- if platform not in PLATFORMS :
487+ if platform not in default [ "platforms" ] :
487488 _fail ("The platform must be one of {allowed} but got '{got}'" .format (
488- allowed = sorted (PLATFORMS ),
489+ allowed = sorted (default [ "platforms" ] ),
489490 got = platform ,
490491 ))
491492 return
@@ -602,6 +603,26 @@ def _override_defaults(*overrides, modules, _fail = fail, default):
602603 override .fn (tag = tag , _fail = _fail , default = default )
603604
604605def _get_toolchain_config (* , modules , _fail = fail ):
606+ """Computes the configs for toolchains.
607+
608+ Args:
609+ modules: The modules from module_ctx
610+ _fail: Function to call for failing; only used for testing.
611+
612+ Returns:
613+ A struct with the following:
614+ * `kwargs`: {type}`dict[str, dict[str, object]` custom kwargs to pass to
615+ `python_register_toolchains`, keyed by python version.
616+ The first key is either a Major.Minor or Major.Minor.Patch
617+ string.
618+ * `minor_mapping`: {type}`dict[str, str]` the mapping of Major.Minor
619+ to Major.Minor.Patch.
620+ * `default`: {type}`dict[str, object]` of kwargs passed along to
621+ `python_register_toolchains`. These keys take final precedence.
622+ * `register_all_versions`: {type}`bool` whether all known versions
623+ should be registered.
624+ """
625+
605626 # Items that can be overridden
606627 available_versions = {
607628 version : {
@@ -621,6 +642,7 @@ def _get_toolchain_config(*, modules, _fail = fail):
621642 }
622643 default = {
623644 "base_url" : DEFAULT_RELEASE_BASE_URL ,
645+ "platforms" : dict (PLATFORMS ), # Copy so it's mutable.
624646 "tool_versions" : available_versions ,
625647 }
626648
0 commit comments