Skip to content

Commit 758f4d6

Browse files
committed
feat(musl): add musl toolchain
With this users can target `musl` platforms in `whl`-only setups. Fixes bazel-contrib#1211
1 parent 7b95ea6 commit 758f4d6

File tree

7 files changed

+48
-20
lines changed

7 files changed

+48
-20
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ Unreleased changes template.
6060

6161
{#v0-0-0-added}
6262
### Added
63-
* Nothing yet.
63+
* (toolchain) The python interpreters targeting `muslc` libc have been added
64+
for the latest toolchain versions for each minor Python version. You can control
65+
the toolchain selection by using the
66+
{bzl:obj}`//python/config_settings:py_linux_libc` build flag.
6467

6568
{#v0-0-0-removed}
6669
### Removed

docs/toolchains.md

+7
Original file line numberDiff line numberDiff line change
@@ -451,3 +451,10 @@ The toolchain() calls should be in a separate BUILD file from everything else.
451451
This avoids Bazel having to perform unnecessary work when it discovers the list
452452
of available toolchains.
453453
:::
454+
455+
## Toolchain selection flags
456+
457+
Currently the following flags are used to influence toolchain selection:
458+
* {obj}`--@rules_python//python/config_settings:py_linux_libc` for selecting the Linux libc variant.
459+
* {obj}`--@rules_python//python/config_settings:py_freethreaded` for selecting
460+
the freethreaded experimental Python builds available from `3.13.0` onwards.

python/config_settings/BUILD.bazel

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ load(
88
"FreeThreadedFlag",
99
"PrecompileFlag",
1010
"PrecompileSourceRetentionFlag",
11+
"LibcFlag",
1112
)
1213
load(
1314
"//python/private/pypi:flags.bzl",
1415
"UniversalWhlFlag",
1516
"UseWhlFlag",
16-
"WhlLibcFlag",
1717
"define_pypi_internal_flags",
1818
)
1919
load(":config_settings.bzl", "construct_config_settings")
@@ -87,8 +87,8 @@ string_flag(
8787
# This is used for pip and hermetic toolchain resolution.
8888
string_flag(
8989
name = "py_linux_libc",
90-
build_setting_default = WhlLibcFlag.GLIBC,
91-
values = sorted(WhlLibcFlag.__members__.values()),
90+
build_setting_default = LibcFlag.GLIBC,
91+
values = sorted(LibcFlag.__members__.values()),
9292
# NOTE: Only public because it is used in pip hub and toolchain repos.
9393
visibility = ["//visibility:public"],
9494
)

python/private/flags.bzl

+11
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,14 @@ FreeThreadedFlag = enum(
132132
# Do not use freethreaded python toolchain and wheels.
133133
NO = "no",
134134
)
135+
136+
# Determines which libc flavor is preferred when selecting the toolchain and
137+
# linux whl distributions.
138+
#
139+
# buildifier: disable=name-conventions
140+
LibcFlag = enum(
141+
# Prefer glibc wheels (e.g. manylinux_2_17_x86_64 or linux_x86_64)
142+
GLIBC = "glibc",
143+
# Prefer musl wheels (e.g. musllinux_2_17_x86_64)
144+
MUSL = "musl",
145+
)

python/private/pypi/config_settings.bzl

+7-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ Note, that here the specialization of musl vs manylinux wheels is the same in
3939
order to ensure that the matching fails if the user requests for `musl` and we don't have it or vice versa.
4040
"""
4141

42-
load(":flags.bzl", "INTERNAL_FLAGS", "UniversalWhlFlag", "WhlLibcFlag")
42+
load("//python/private:flags.bzl", "LibcFlag")
43+
load(":flags.bzl", "INTERNAL_FLAGS", "UniversalWhlFlag")
4344

4445
FLAGS = struct(
4546
**{
@@ -251,14 +252,14 @@ def _plat_flag_values(os, cpu, osx_versions, glibc_versions, muslc_versions):
251252

252253
elif os == "linux":
253254
for os_prefix, linux_libc in {
254-
os: WhlLibcFlag.GLIBC,
255-
"many" + os: WhlLibcFlag.GLIBC,
256-
"musl" + os: WhlLibcFlag.MUSL,
255+
os: LibcFlag.GLIBC,
256+
"many" + os: LibcFlag.GLIBC,
257+
"musl" + os: LibcFlag.MUSL,
257258
}.items():
258-
if linux_libc == WhlLibcFlag.GLIBC:
259+
if linux_libc == LibcFlag.GLIBC:
259260
libc_versions = glibc_versions
260261
libc_flag = FLAGS.pip_whl_glibc_version
261-
elif linux_libc == WhlLibcFlag.MUSL:
262+
elif linux_libc == LibcFlag.MUSL:
262263
libc_versions = muslc_versions
263264
libc_flag = FLAGS.pip_whl_muslc_version
264265
else:

python/private/pypi/flags.bzl

-10
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@ UniversalWhlFlag = enum(
4444
UNIVERSAL = "universal",
4545
)
4646

47-
# Determines which libc flavor is preferred when selecting the linux whl distributions.
48-
#
49-
# buildifier: disable=name-conventions
50-
WhlLibcFlag = enum(
51-
# Prefer glibc wheels (e.g. manylinux_2_17_x86_64 or linux_x86_64)
52-
GLIBC = "glibc",
53-
# Prefer musl wheels (e.g. musllinux_2_17_x86_64)
54-
MUSL = "musl",
55-
)
56-
5747
INTERNAL_FLAGS = [
5848
"dist",
5949
"whl_plat",

python/versions.bzl

+16
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ TOOL_VERSIONS = {
247247
"x86_64-apple-darwin": "193dc7f0284e4917d52b17a077924474882ee172872f2257cfe3375d6d468ed9",
248248
"x86_64-pc-windows-msvc": "5069008a237b90f6f7a86956903f2a0221b90d471daa6e4a94831eaa399e3993",
249249
"x86_64-unknown-linux-gnu": "c20ee831f7f46c58fa57919b75a40eb2b6a31e03fd29aaa4e8dab4b9c4b60d5d",
250+
"x86_64-unknown-linux-musl": "5c1cc348e317fe7af1acd6a7f665b46eccb554b20d6533f0e76c53f44d4556cc",
250251
},
251252
"strip_prefix": "python",
252253
},
@@ -366,6 +367,7 @@ TOOL_VERSIONS = {
366367
"x86_64-apple-darwin": "90b46dfb1abd98d45663c7a2a8c45d3047a59391d8586d71b459cec7b75f662b",
367368
"x86_64-pc-windows-msvc": "e48952619796c66ec9719867b87be97edca791c2ef7fbf87d42c417c3331609e",
368369
"x86_64-unknown-linux-gnu": "3db2171e03c1a7acdc599fba583c1b92306d3788b375c9323077367af1e9d9de",
370+
"x86_64-unknown-linux-musl": "ed519c47d9620eb916a6f95ec2875396e7b1a9ab993ee40b2f31b837733f318c",
369371
},
370372
"strip_prefix": "python",
371373
},
@@ -480,6 +482,7 @@ TOOL_VERSIONS = {
480482
"x86_64-apple-darwin": "1e23ffe5bc473e1323ab8f51464da62d77399afb423babf67f8e13c82b69c674",
481483
"x86_64-pc-windows-msvc": "647b66ff4552e70aec3bf634dd470891b4a2b291e8e8715b3bdb162f577d4c55",
482484
"x86_64-unknown-linux-gnu": "8b50a442b04724a24c1eebb65a36a0c0e833d35374dbdf9c9470d8a97b164cd9",
485+
"x86_64-unknown-linux-musl": "d36fc77a8dd76155a7530f6235999a693b9e7c48aa11afeb5610a091cae5aa6f",
483486
},
484487
"strip_prefix": "python",
485488
},
@@ -558,6 +561,7 @@ TOOL_VERSIONS = {
558561
"x86_64-apple-darwin": "60c5271e7edc3c2ab47440b7abf4ed50fbc693880b474f74f05768f5b657045a",
559562
"x86_64-pc-windows-msvc": "f05531bff16fa77b53be0776587b97b466070e768e6d5920894de988bdcd547a",
560563
"x86_64-unknown-linux-gnu": "43576f7db1033dd57b900307f09c2e86f371152ac8a2607133afa51cbfc36064",
564+
"x86_64-unknown-linux-musl": "5ed4a4078db3cbac563af66403aaa156cd6e48831d90382a1820db2b120627b5",
561565
},
562566
"strip_prefix": "python",
563567
},
@@ -571,6 +575,7 @@ TOOL_VERSIONS = {
571575
"x86_64-apple-darwin": "cff1b7e7cd26f2d47acac1ad6590e27d29829776f77e8afa067e9419f2f6ce77",
572576
"x86_64-pc-windows-msvc": "b25926e8ce4164cf103bacc4f4d154894ea53e07dd3fdd5ebb16fb1a82a7b1a0",
573577
"x86_64-unknown-linux-gnu": "2c8cb15c6a2caadaa98af51df6fe78a8155b8471cb3dd7b9836038e0d3657fb4",
578+
"x86_64-unknown-linux-musl": "2f61ee3b628a56aceea63b46c7afe2df3e22a61da706606b0c8efda57f953cf4",
574579
"aarch64-apple-darwin-freethreaded": "efc2e71c0e05bc5bedb7a846e05f28dd26491b1744ded35ed82f8b49ccfa684b",
575580
"aarch64-unknown-linux-gnu-freethreaded": "59b50df9826475d24bb7eff781fa3949112b5e9c92adb29e96a09cdf1216d5bd",
576581
"ppc64le-unknown-linux-gnu-freethreaded": "1217efa5f4ce67fcc9f7eb64165b1bd0912b2a21bc25c1a7e2cb174a21a5df7e",
@@ -712,6 +717,17 @@ def _generate_platforms():
712717
os_name = LINUX_NAME,
713718
arch = "x86_64",
714719
),
720+
"x86_64-unknown-linux-musl": struct(
721+
compatible_with = [
722+
"@platforms//os:linux",
723+
"@platforms//cpu:x86_64",
724+
],
725+
flag_values = {
726+
libc: "musl",
727+
},
728+
os_name = LINUX_NAME,
729+
arch = "x86_64",
730+
),
715731
}
716732

717733
freethreaded = Label("//python/config_settings:py_freethreaded")

0 commit comments

Comments
 (0)