Skip to content

Commit 1e70b1e

Browse files
committed
create host repo in bzlmod
1 parent ccdfece commit 1e70b1e

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

python/private/python.bzl

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ load(":full_version.bzl", "full_version")
2121
load(":python_register_toolchains.bzl", "python_register_toolchains")
2222
load(":pythons_hub.bzl", "hub_repo")
2323
load(":repo_utils.bzl", "repo_utils")
24-
load(":toolchains_repo.bzl", "multi_toolchain_aliases")
24+
load(":toolchains_repo.bzl", "host_toolchain", "multi_toolchain_aliases")
2525
load(":util.bzl", "IS_BAZEL_6_4_OR_HIGHER")
2626
load(":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

415419
def _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

420424
def _one_or_the_same(first, second, *, onerror = None):

python/private/toolchains_repo.bzl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,8 @@ def _host_toolchain_impl(rctx):
375375
if not rctx.delete(python_tester):
376376
fail("Failed to delete the python tester")
377377

378+
# NOTE: The term "toolchain" is a misnomer for this rule. This doesn't define
379+
# a repo with toolchains or toolchain implementations.
378380
host_toolchain = repository_rule(
379381
_host_toolchain_impl,
380382
doc = """\

0 commit comments

Comments
 (0)