Skip to content

Commit 309e93e

Browse files
authored
fix(toolchains): correctly register musl/freethreaded toolchains for workspace (#3314)
The musl/freethreaded runtimes weren't being activated when the flags were set. This was because the toolchains weren't having `target_settings` set, which means extra settings, such as musl/freethreaded-ness were ignored when matching. The net result is the regular toolchain, because it's registered earlier, would always match earlier. To fix, set the target_settings in the toolchain() call. This matches the bzlmod behavior. Also update the toolchain resolution tests to verify resolution. Fixes #3262
1 parent 852e954 commit 309e93e

File tree

3 files changed

+5
-10
lines changed

3 files changed

+5
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ END_UNRELEASED_TEMPLATE
8888
([#3204](https://github.com/bazel-contrib/rules_python/issues/3204)).
8989
* (uv) {obj}`//python/uv:lock.bzl%lock` now works with a local platform
9090
runtime.
91+
* (toolchains) WORKSPACE builds now correctly register musl and freethreaded
92+
variants. Setting {obj}`--py_linux_libc=musl` and `--py_freethreaded=yes` now
93+
activate them, respectively.
94+
([#3262](https://github.com/bazel-contrib/rules_python/issues/3262)).
9195

9296
{#v0-0-0-added}
9397
### Added

python/private/toolchains_repo.bzl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def python_toolchain_build_file_content(
214214
user_repository_name = "{}_{}".format(user_repository_name, platform),
215215
python_version = python_version,
216216
set_python_version_constraint = set_python_version_constraint,
217-
target_settings = [],
217+
target_settings = meta.target_settings,
218218
))
219219
return "\n\n".join(entries)
220220

tests/toolchains/multi_platform_resolution/resolution_tests.bzl

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ load("@bazel_skylib//lib:structs.bzl", "structs")
1010
load("@rules_testing//lib:analysis_test.bzl", "analysis_test")
1111
load("@rules_testing//lib:test_suite.bzl", "test_suite")
1212
load("//python:versions.bzl", "TOOL_VERSIONS")
13-
load("//python/private:bzlmod_enabled.bzl", "BZLMOD_ENABLED") # buildifier: disable=bzl-visibility
1413
load("//python/private:common_labels.bzl", "labels") # buildifier: disable=bzl-visibility
1514
load("//python/private:toolchain_types.bzl", "TARGET_TOOLCHAIN_TYPE") # buildifier: disable=bzl-visibility
1615
load("//python/private:version.bzl", "version") # buildifier: disable=bzl-visibility
@@ -141,13 +140,6 @@ def _test_toolchains(name):
141140
if runtime.libc:
142141
config_settings[labels.PY_LINUX_LIBC] = runtime.libc
143142

144-
# TODO: Workspace isn't correctly registering musl and freethreaded
145-
# toolchains, so skip them for now.
146-
target_compatible_with = []
147-
if not BZLMOD_ENABLED and (runtime.libc == "musl" or
148-
runtime.freethreaded == "yes"):
149-
target_compatible_with = ["@platforms//:incompatible"]
150-
151143
analysis_test(
152144
name = test_name,
153145
target = name + "_current_toolchain",
@@ -165,7 +157,6 @@ def _test_toolchains(name):
165157
"os={}".format(runtime.os),
166158
"arch={}".format(runtime.arch),
167159
],
168-
"target_compatible_with": target_compatible_with,
169160
},
170161
)
171162

0 commit comments

Comments
 (0)