From ad1d0d4309c66eb9fe817ed1af29e0886329fed1 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Fri, 19 Mar 2021 20:49:40 +0800 Subject: [PATCH 1/6] musllinux only applies to dy-linked interpreters --- pep-0656.rst | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/pep-0656.rst b/pep-0656.rst index 83546ad6037..172478f3225 100644 --- a/pep-0656.rst +++ b/pep-0656.rst @@ -14,9 +14,9 @@ Abstract ======== This PEP proposes a new platfrom tag series ``musllinux`` for -binary Python package distributions for a Python installation linked -against musl on a Linux distribution. The tag works similarly to the -"perennial manylinux" platform tags specified in :pep:`600`, but +binary Python package distributions for a Python installation that +depends on musl on a Linux distribution. The tag works similarly to +the "perennial manylinux" platform tags specified in :pep:`600`, but targeting platforms based on musl instead. @@ -46,6 +46,14 @@ Logic behind the new platform tag largely follows :pep:`600`, and require wheels using this tag make similar promises. Please refer to the PEP for more details on rationale and reasoning behind the design. +The ``musllinux`` platform tags only apply to Python interpreters +dynamically linked aginst the musl libc and executed on the runtime +shared library, on a Linux operating system. Statically linked +interpreters or mixed builds with other libc implementations (such as +glibc) are out of scope and not supported by platform tags defined in +this document. Such interpreters should not claim compatibility with +``musllinux`` platform tags. + Specification ============= From 6c9d97c9334d630fd1eb15e0275b2b87194b5b67 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Fri, 19 Mar 2021 20:50:23 +0800 Subject: [PATCH 2/6] Add notes on musl detection and version extraction --- pep-0656.rst | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/pep-0656.rst b/pep-0656.rst index 172478f3225..eeb6c9b836d 100644 --- a/pep-0656.rst +++ b/pep-0656.rst @@ -62,6 +62,48 @@ Tags using the new scheme will take the form:: musllinux_${MUSLMAJOR}_${MUSLMINOR}_${ARCH} +Reading the musl version +------------------------ + +The musl version values can be obtains by executing the musl libc +shared library the Python interpreter is currently running on, and +parsing the output:: + + import re + import subprocess + + def get_musl_major_minor(so: str) -> Optional[Tuple[int, int]]: + """Detect musl runtime version. + + Returns a two-tuple ``(major, minor)`` that indicates musl + library's version, or ``None`` if the given value does not + output expected information. + + The libc library should output something like this to stderr:: + + musl libc (x86_64) + Version 1.2.2 + Dynamic Program Loader + """ + proc = subprocess.run([so], stderr=subprocess.PIPE, text=True) + lines = (line.strip() for line in proc.stderr.splitlines()) + lines = [line for line in lines if line] + if len(lines) < 2 or lines[0][:4] != "musl": + return None + match = re.match(r"Version (\d+)\.(\d+)", lines[1]) + if match: + return (int(match.group(1)), int(match.group(2))) + return None + +There are currently two possible ways to find the musl library's +location that a Python interpreter is running on, either with the +system ``ldd`` command [ldd]_, or by parsing the ``PT_INTERP`` +section's value from the executable's ELF header [elf]_. + + +Formatting the tag +------------------ + Distributions using the tag make similar promises to those described in :pep:`600`, including: @@ -85,6 +127,9 @@ The value can be formatted with the following Python code:: arch = arch.replace("-", "_") return f"musllinux_{musl_version[0]}_{musl_version[1]}_{arch}" +Recommendations to package indexes +---------------------------------- + It is recommended for Python package repositories, including PyPI, to accept platform tags matching the following regular expression:: @@ -93,7 +138,8 @@ accept platform tags matching the following regular expression:: Python package repositories may impose additional requirements to reject Wheels with known issues, including but not limited to: -* A ``musllinux_1_1`` wheel containing symbols only available in musl 1.2. +* A ``musllinux_1_1`` wheel containing symbols only available in musl + 1.2 or later. * Wheel that depends on external libraries not considered generally available to the intended audience of the package index. * A platform tag claiming compatibility to a non-existent musl version @@ -134,6 +180,10 @@ References .. [musl-compat-ml] https://mail.python.org/archives/list/distutils-sig@python.org/message/VRXSTNXWHPAVUW253ZCWWMP7WDTBAQDL/ +.. [ldd] https://www.unix.com/man-page/posix/1/ldd/ + +.. [elf] https://refspecs.linuxfoundation.org/elf/elf.pdf + Copyright ========= From ab90dfb66cea7c8d1fac362f57ed533db113ef51 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Fri, 19 Mar 2021 21:29:14 +0800 Subject: [PATCH 3/6] Use newer type hint syntax --- pep-0656.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pep-0656.rst b/pep-0656.rst index eeb6c9b836d..c779f01fca6 100644 --- a/pep-0656.rst +++ b/pep-0656.rst @@ -72,7 +72,7 @@ parsing the output:: import re import subprocess - def get_musl_major_minor(so: str) -> Optional[Tuple[int, int]]: + def get_musl_major_minor(so: str) -> tuple[int, int] | None: """Detect musl runtime version. Returns a two-tuple ``(major, minor)`` that indicates musl From 8c82c7a5fe28b9051acfecade9b7711b5bed001a Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Sat, 20 Mar 2021 01:54:17 +0800 Subject: [PATCH 4/6] Typo --- pep-0656.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pep-0656.rst b/pep-0656.rst index c779f01fca6..219c417b5bc 100644 --- a/pep-0656.rst +++ b/pep-0656.rst @@ -47,7 +47,7 @@ require wheels using this tag make similar promises. Please refer to the PEP for more details on rationale and reasoning behind the design. The ``musllinux`` platform tags only apply to Python interpreters -dynamically linked aginst the musl libc and executed on the runtime +dynamically linked against the musl libc and executed on the runtime shared library, on a Linux operating system. Statically linked interpreters or mixed builds with other libc implementations (such as glibc) are out of scope and not supported by platform tags defined in From 559085503d590f7cb99e495ba7184df3ba49d0d0 Mon Sep 17 00:00:00 2001 From: Tzu-ping Chung Date: Sat, 20 Mar 2021 01:55:14 +0800 Subject: [PATCH 5/6] Clarify what does not output expected information --- pep-0656.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pep-0656.rst b/pep-0656.rst index 219c417b5bc..c5e11cc0c5a 100644 --- a/pep-0656.rst +++ b/pep-0656.rst @@ -76,7 +76,7 @@ parsing the output:: """Detect musl runtime version. Returns a two-tuple ``(major, minor)`` that indicates musl - library's version, or ``None`` if the given value does not + library's version, or ``None`` if the given libc .so does not output expected information. The libc library should output something like this to stderr:: From 7ce9f81a7fe9b7e3c99d25ba75b895b37feb5731 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Fri, 19 Mar 2021 14:10:09 -0700 Subject: [PATCH 6/6] Update pep-0656.rst --- pep-0656.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pep-0656.rst b/pep-0656.rst index c5e11cc0c5a..87abd432942 100644 --- a/pep-0656.rst +++ b/pep-0656.rst @@ -65,7 +65,7 @@ Tags using the new scheme will take the form:: Reading the musl version ------------------------ -The musl version values can be obtains by executing the musl libc +The musl version values can be obtained by executing the musl libc shared library the Python interpreter is currently running on, and parsing the output::