Skip to content

Commit e9d5d86

Browse files
committed
refactor: make bzlmod create host repos
1 parent acf4136 commit e9d5d86

File tree

2 files changed

+18
-7
lines changed

2 files changed

+18
-7
lines changed

python/private/python.bzl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,12 @@ def _python_impl(module_ctx):
315315
# The last toolchain is the default; it can't have version constraints
316316
set_python_version_constraint = is_last,
317317
))
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+
)
318324

319325
# List of the base names ("python_3_10") for the toolchain repos
320326
base_toolchain_repo_names = []
@@ -406,6 +412,11 @@ def _python_impl(module_ctx):
406412
else:
407413
return None
408414

415+
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)
418+
return platform_info.os_name == os_name and platform_info.arch == cpu_name
419+
409420
def _one_or_the_same(first, second, *, onerror = None):
410421
if not first:
411422
return second

python/private/python_register_toolchains.bzl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,26 +170,26 @@ def python_register_toolchains(
170170
platform = platform,
171171
))
172172

173-
host_toolchain(
174-
name = name + "_host",
175-
platforms = loaded_platforms,
176-
python_version = python_version,
177-
)
178-
179173
toolchain_aliases(
180174
name = name,
181175
python_version = python_version,
182176
user_repository_name = name,
183177
platforms = loaded_platforms,
184178
)
185179

186-
# in bzlmod we write out our own toolchain repos
180+
# in bzlmod we write out our own toolchain repos and host repos
187181
if bzlmod_toolchain_call:
188182
return struct(
189183
# dict[str name, tuple[str platform_name, platform_info]]
190184
impl_repos = impl_repos,
191185
)
192186

187+
host_toolchain(
188+
name = name + "_host",
189+
platforms = loaded_platforms,
190+
python_version = python_version,
191+
)
192+
193193
toolchains_repo(
194194
name = toolchain_repo_name,
195195
python_version = python_version,

0 commit comments

Comments
 (0)