Skip to content

Commit a1bd4fa

Browse files
authored
Merge pull request #1441 from jeanas/musllinux
Revise platform tags spec, add musllinux
2 parents 045d09a + 2f750a4 commit a1bd4fa

File tree

1 file changed

+80
-42
lines changed

1 file changed

+80
-42
lines changed

source/specifications/platform-compatibility-tags.rst

Lines changed: 80 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,16 @@ platform tag
2525
For example, the tag ``py27-none-any`` indicates compatibility with Python 2.7
2626
(any Python 2.7 implementation) with no abi requirement, on any platform.
2727

28-
Use
29-
===
30-
3128
The ``wheel`` built package format includes these tags in its filenames,
3229
of the form
3330
``{distribution}-{version}(-{build tag})?-{python tag}-{abitag}-{platform tag}.whl``.
3431
Other package formats may have their own conventions.
3532

3633
Any potential spaces in any tag should be replaced with ``_``.
3734

38-
Details
39-
=======
4035

4136
Python Tag
42-
----------
37+
==========
4338

4439
The Python tag indicates the implementation and version required by
4540
a distribution. Major implementations have abbreviated codes, initially:
@@ -66,8 +61,9 @@ intentionally released a cross-version-compatible distribution.
6661
A single-source Python 2/3 compatible distribution can use the compound
6762
tag ``py2.py3``. See `Compressed Tag Sets`_, below.
6863

64+
6965
ABI Tag
70-
-------
66+
=======
7167

7268
The ABI tag indicates which Python ABI is required by any included
7369
extension modules. For implementation-specific ABIs, the implementation
@@ -82,50 +78,49 @@ revision and compiler flags, etc, but will probably not have a great need
8278
to distribute binary distributions. Each implementation's community may
8379
decide how to best use the ABI tag.
8480

81+
8582
Platform Tag
86-
------------
83+
============
84+
85+
Basic platform tags
86+
-------------------
8787

88-
The platform tag is simply ``sysconfig.get_platform()`` with all
89-
hyphens ``-`` and periods ``.`` replaced with underscore ``_``.
88+
In its simplest form, the platform tag is ``sysconfig.get_platform()`` with
89+
all hyphens ``-`` and periods ``.`` replaced with underscore ``_``.
9090
Until the removal of :ref:`distutils` in Python 3.12, this
91-
was ``distutils.util.get_platform()``.
91+
was ``distutils.util.get_platform()``. For example:
9292

9393
* win32
9494
* linux_i386
9595
* linux_x86_64
9696

9797

98-
-------------
98+
.. _manylinux:
99+
99100
``manylinux``
100101
-------------
101-
.. _manylinux:
102102

103-
The scheme defined in :pep:`425` was insufficient for public distribution of
104-
wheel files (and \*nix wheel files in general) to Linux platforms, due to the
105-
large ecosystem of Linux platforms and subtle differences between them.
103+
The simple scheme above is insufficient for public distribution of wheel files
104+
to Linux platforms, due to the large ecosystem of Linux platforms and subtle
105+
differences between them.
106106

107-
Instead, :pep:`600` defines the ``manylinux`` standard, which represents a
108-
common subset of Linux platforms, and allows building wheels tagged with the
107+
Instead, for those platforms, the ``manylinux`` standard represents a common
108+
subset of Linux platforms, and allows building wheels tagged with the
109109
``manylinux`` platform tag which can be used across most common Linux
110110
distributions.
111111

112-
There were multiple iterations of the ``manylinux`` specification, each
113-
representing the common subset of Linux platforms at a given point in time:
112+
The current standard is the future-proof ``manylinux_x_y`` standard. It defines
113+
tags of the form ``manylinux_x_y_arch``, where ``x`` and ``y`` are glibc major
114+
and minor versions supported (e.g. ``manylinux_2_24_xxx`` should work on any
115+
distro using glibc 2.24+), and ``arch`` is the architecture, matching the value
116+
of ``sysconfig.get_platform()`` on the system as in the "simple" form above.
114117

115-
* ``manylinux1`` (:pep:`513`) supports ``x86_64`` and ``i686``
116-
architectures, and is based on a compatible Linux platform from 2007.
117-
* ``manylinux2010`` (:pep:`571`) supports ``x86_64`` and ``i686``
118-
architectures. and updates the previous specification to be based on a
119-
compatible Linux platform from 2010 instead.
120-
* ``manylinux2014`` (:pep:`599`) adds support for a number of
121-
additional architectures (``aarch64``, ``armv7l``, ``ppc64``, ``ppc64le``,
122-
and ``s390x``) and updates the base platform to a compatible Linux platform
123-
from 2014.
118+
The following older tags are still supported for backward compatibility:
124119

125-
``manylinux_x_y`` (:pep:`600`) supersedes all previous PEPs to define a
126-
future-proof standard. It defines ``x`` and ``y`` as glibc major an minor
127-
versions supported (e.g. ``manylinux_2_24`` should work on any distro using
128-
glibc 2.24+). Previous tags are still supported for backward compatibility.
120+
* ``manylinux1`` supports glibc 2.5 on ``x86_64`` and ``i686`` architectures.
121+
* ``manylinux2010`` supports glibc 2.12 on ``x86_64`` and ``i686``.
122+
* ``manylinux2014`` supports glibc 2.17 on ``x86_64``, ``i686``, ``aarch64``,
123+
``armv7l``, ``ppc64``, ``ppc64le``, and ``s390x``.
129124

130125
In general, distributions built for older versions of the specification are
131126
forwards-compatible (meaning that ``manylinux1`` distributions should continue
@@ -138,15 +133,6 @@ possible, with the caveat that the provided build environment for
138133
``manylinux1`` and ``manylinux2010`` have reached end-of-life meaning that
139134
these images will no longer receive security updates.
140135

141-
Manylinux compatibility support
142-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
143-
144-
.. Note::
145-
* The ``manylinux2014`` specification is relatively new and is not yet widely
146-
recognised by install tools.
147-
* The ``manylinux_x_y`` specification is relatively new and is not yet widely
148-
recognised by install tools.
149-
150136
The following table shows the minimum versions of relevant projects to support
151137
the various ``manylinux`` standards:
152138

@@ -159,6 +145,51 @@ auditwheel ``>=1.0.0`` ``>=2.0.0`` ``>=3.0.0`` ``>=3.3.0`` [#
159145

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

@@ -307,3 +338,10 @@ History
307338
- July 2019: The ``manylinux2014`` tag was approved through :pep:`599`.
308339
- November 2019: The ``manylinux_x_y`` perennial tag was approved through
309340
:pep:`600`.
341+
- April 2021: The ``musllinux_x_y`` tag was approved through :pep:`656`.
342+
343+
344+
345+
.. _musl: https://musl.libc.org
346+
.. _ldd: https://www.unix.com/man-page/posix/1/ldd/
347+
.. _elf: https://refspecs.linuxfoundation.org/elf/elf.pdf

0 commit comments

Comments
 (0)