Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions python/private/python.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ def _python_impl(module_ctx):
_internal_bzlmod_toolchain_call = True,
**kwargs
)
host_compatible = []
host_platforms = []
host_os_names = {}
host_archs = {}
for repo_name, (platform_name, platform_info) in register_result.impl_repos.items():
toolchain_impls.append(struct(
# str: The base name to use for the toolchain() target
Expand All @@ -317,12 +319,17 @@ def _python_impl(module_ctx):
set_python_version_constraint = is_last,
))
if _is_compatible_with_host(module_ctx, platform_info):
host_compatible.append(platform_name)
host_key = str(len(host_platforms))
host_platforms.append(platform_name)
host_os_names[host_key] = platform_info.os_name
host_archs[host_key] = platform_info.arch

host_toolchain(
name = toolchain_info.name + "_host",
# NOTE: Order matters. The first found to be compatible is (usually) used.
platforms = host_compatible,
platforms = host_platforms,
os_names = host_os_names,
arch_names = host_archs,
python_version = full_python_version,
)

Expand Down
23 changes: 22 additions & 1 deletion python/private/toolchains_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,16 @@ toolchain_aliases repo because referencing the `python` interpreter target from
this repo causes an eager fetch of the toolchain for the host platform.
""",
attrs = {
"arch_names": attr.string_dict(
doc = """
If set, overrides the platform metadata. Keyed by index in `platforms`
""",
),
"os_names": attr.string_dict(
doc = """
If set, overrides the platform metadata. Keyed by index in `platforms`
""",
),
"platforms": attr.string_list(mandatory = True),
"python_version": attr.string(mandatory = True),
"_rule_name": attr.string(default = "host_toolchain"),
Expand Down Expand Up @@ -436,9 +446,20 @@ def _get_host_platform(*, rctx, logger, python_version, os_name, cpu_name, platf
Returns:
The host platform.
"""
if rctx.attr.os_names:
platform_map = {}
for i, platform_name in enumerate(platforms):
key = str(i)
platform_map[platform_name] = struct(
os_name = rctx.attr.os_names[key],
arch = rctx.attr.arch_names[key],
)
else:
platform_map = PLATFORMS

candidates = []
for platform in platforms:
meta = PLATFORMS[platform]
meta = platform_map[platform]

if meta.os_name == os_name and meta.arch == cpu_name:
candidates.append(platform)
Expand Down