@@ -21,7 +21,7 @@ load(":full_version.bzl", "full_version")
2121load (":python_register_toolchains.bzl" , "python_register_toolchains" )
2222load (":pythons_hub.bzl" , "hub_repo" )
2323load (":repo_utils.bzl" , "repo_utils" )
24- load (":toolchains_repo.bzl" , "multi_toolchain_aliases" )
24+ load (":toolchains_repo.bzl" , "host_toolchain" , " multi_toolchain_aliases" )
2525load (":util.bzl" , "IS_BAZEL_6_4_OR_HIGHER" )
2626load (":version.bzl" , "version" )
2727
@@ -298,6 +298,7 @@ def _python_impl(module_ctx):
298298 _internal_bzlmod_toolchain_call = True ,
299299 ** kwargs
300300 )
301+ host_compatible = []
301302 for repo_name , (platform_name , platform_info ) in register_result .impl_repos .items ():
302303 toolchain_impls .append (struct (
303304 # str: The base name to use for the toolchain() target
@@ -315,12 +316,15 @@ def _python_impl(module_ctx):
315316 # The last toolchain is the default; it can't have version constraints
316317 set_python_version_constraint = is_last ,
317318 ))
318- if _is_compatible_with_host (mctx , platform_info ):
319- host_toolchain (
320- name = toolchain_info .name ,
321- platforms = [platform_name ],
322- python_version = full_python_version ,
323- )
319+ if _is_compatible_with_host (module_ctx , platform_info ):
320+ host_compatible .append (platform_name )
321+
322+ host_toolchain (
323+ name = toolchain_info .name + "_host" ,
324+ # NOTE: Order matters. The first found to be compatible is (usually) used.
325+ platforms = host_compatible ,
326+ python_version = full_python_version ,
327+ )
324328
325329 # List of the base names ("python_3_10") for the toolchain repos
326330 base_toolchain_repo_names = []
@@ -413,8 +417,8 @@ def _python_impl(module_ctx):
413417 return None
414418
415419def _is_compatible_with_host (mctx , platform_info ):
416- os_name = repo_utils .get_platforms_os_name (rctx )
417- cpu_name = repo_utils .get_platforms_cpu_name (rctx )
420+ os_name = repo_utils .get_platforms_os_name (mctx )
421+ cpu_name = repo_utils .get_platforms_cpu_name (mctx )
418422 return platform_info .os_name == os_name and platform_info .arch == cpu_name
419423
420424def _one_or_the_same (first , second , * , onerror = None ):
0 commit comments