Skip to content

Commit b258ce2

Browse files
committed
Add musllinux platform tags from PEP 656
1 parent 74b071b commit b258ce2

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

source/specifications/platform-compatibility-tags.rst

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,50 @@ auditwheel ``>=1.0.0`` ``>=2.0.0`` ``>=3.0.0`` ``>=3.3.0`` [#
149149
.. [#] Only support for ``manylinux_2_24`` has been added in auditwheel 3.3.0
150150
151151
152+
``musllinux``
153+
-------------
154+
155+
The ``musllinux`` family of tags is similar to ``manylinux``, but for Linux
156+
platforms that use the musl_ libc rather than glibc (a prime example being Alpine
157+
Linux). The schema is ``musllinux_x_y_arch``, supporting musl ``x.y`` and higher
158+
on the architecture ``arch``.
159+
160+
The musl version values can be obtained by executing the musl libc shared
161+
library the Python interpreter is currently running on, and parsing the output:
162+
163+
.. code-block:: python
164+
165+
import re
166+
import subprocess
167+
168+
def get_musl_major_minor(so: str) -> tuple[int, int] | None:
169+
"""Detect musl runtime version.
170+
171+
Returns a two-tuple ``(major, minor)`` that indicates musl
172+
library's version, or ``None`` if the given libc .so does not
173+
output expected information.
174+
175+
The libc library should output something like this to stderr::
176+
177+
musl libc (x86_64)
178+
Version 1.2.2
179+
Dynamic Program Loader
180+
"""
181+
proc = subprocess.run([so], stderr=subprocess.PIPE, text=True)
182+
lines = (line.strip() for line in proc.stderr.splitlines())
183+
lines = [line for line in lines if line]
184+
if len(lines) < 2 or lines[0][:4] != "musl":
185+
return None
186+
match = re.match(r"Version (\d+)\.(\d+)", lines[1])
187+
if match:
188+
return (int(match.group(1)), int(match.group(2)))
189+
return None
190+
191+
There are currently two possible ways to find the musl library’s location that a
192+
Python interpreter is running on, either with the system ldd_ command, or by
193+
parsing the ``PT_INTERP`` section’s value from the executable’s ELF_ header.
194+
195+
152196
Use
153197
===
154198

@@ -297,3 +341,10 @@ The following PEPs contributed to this spec:
297341
- :pep:`571`: defined ``manylinux2010``
298342
- :pep:`599`: defined ``manylinux2014``
299343
- :pep:`600`: defined the ``manylinux_x_y`` scheme
344+
- :pep:`656`: defined ``musllinux_x_y``
345+
346+
347+
348+
.. _musl: https://musl.libc.org
349+
.. _ldd: https://www.unix.com/man-page/posix/1/ldd/
350+
.. _elf: https://refspecs.linuxfoundation.org/elf/elf.pdf

0 commit comments

Comments
 (0)