From 64f4e16355bd5bee688b82f5d0ee56caf780784b Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Sun, 11 Aug 2024 10:43:45 +0200 Subject: [PATCH 1/3] gh-122917 Allow stable API extensions to include a multiarch tuple in the filename This permits stable ABI extensions for multiple architectures to be co-installed into the same directory, without clashing with each other, the same way (non-stable ABI) regular extensions can. It is listed below the current .abi3 suffix because setuptools will select the first suffix containing .abi3, as the target filename. We do this to protect older Python versions predating this patch. --- Makefile.pre.in | 1 + .../next/C_API/2024-08-12-09-48-04.gh-issue-122931.QwHc2l.rst | 2 ++ Python/dynload_shlib.c | 3 +++ 3 files changed, 6 insertions(+) create mode 100644 Misc/NEWS.d/next/C_API/2024-08-12-09-48-04.gh-issue-122931.QwHc2l.rst diff --git a/Makefile.pre.in b/Makefile.pre.in index 3ef0c6320c85db..5d5fe2f9448199 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1817,6 +1817,7 @@ Python/interpconfig.o: $(srcdir)/Python/interpconfig.c $(srcdir)/Python/config_c Python/dynload_shlib.o: $(srcdir)/Python/dynload_shlib.c Makefile $(CC) -c $(PY_CORE_CFLAGS) \ -DSOABI='"$(SOABI)"' \ + $(MULTIARCH_CPPFLAGS) \ -o $@ $(srcdir)/Python/dynload_shlib.c Python/dynload_hpux.o: $(srcdir)/Python/dynload_hpux.c Makefile diff --git a/Misc/NEWS.d/next/C_API/2024-08-12-09-48-04.gh-issue-122931.QwHc2l.rst b/Misc/NEWS.d/next/C_API/2024-08-12-09-48-04.gh-issue-122931.QwHc2l.rst new file mode 100644 index 00000000000000..d1caad2e98482d --- /dev/null +++ b/Misc/NEWS.d/next/C_API/2024-08-12-09-48-04.gh-issue-122931.QwHc2l.rst @@ -0,0 +1,2 @@ +Allow importing stable ABI C extensions that include a multiarch tuple +in their filename, e.g. ``foo.abi3-x86-64-linux-gnu.so``. diff --git a/Python/dynload_shlib.c b/Python/dynload_shlib.c index 583c9b752dfd90..cc42818da04422 100644 --- a/Python/dynload_shlib.c +++ b/Python/dynload_shlib.c @@ -45,6 +45,9 @@ const char *_PyImport_DynLoadFiletab[] = { "." ALT_SOABI ".so", #endif ".abi" PYTHON_ABI_STRING ".so", +#ifdef MULTIARCH + ".abi" PYTHON_ABI_STRING "-" MULTIARCH ".so", +#endif ".so", #endif /* __CYGWIN__ */ NULL, From 0dd9addb9f307a4fc47f733e9c725e5caa463aa8 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 28 Aug 2024 14:00:39 +0200 Subject: [PATCH 2/3] What's New entry --- Doc/whatsnew/3.14.rst | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Doc/whatsnew/3.14.rst b/Doc/whatsnew/3.14.rst index a561d3b3383fc5..6f07d51ac80b8d 100644 --- a/Doc/whatsnew/3.14.rst +++ b/Doc/whatsnew/3.14.rst @@ -455,6 +455,15 @@ Other language changes The testbed can also be used to run the test suite of projects other than CPython itself. (Contributed by Russell Keith-Magee in :gh:`127592`.) +* Stable ABI extensions may now include a multiarch tuple in the + filename, e.g. ``foo.abi3-x86-64-linux-gnu.so``. + This permits stable ABI extensions for multiple architectures to be + co-installed into the same directory, without clashing with each + other, as regular dynamic extensions do. Build tools will not generate + these multiarch tagged filenames, by default, while still supporting + older Python versions that don't recognize these filenames. + (Contributed by Stefano Rivera in :gh:`122931`.) + .. _whatsnew314-pep765: PEP 765: Disallow return/break/continue that exit a finally block From 65e83068d4659ca494bda717bdaa574bedef8ec5 Mon Sep 17 00:00:00 2001 From: Stefano Rivera Date: Wed, 28 Aug 2024 14:03:35 +0200 Subject: [PATCH 3/3] Mention in stable ABI documentation --- Doc/c-api/stable.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/c-api/stable.rst b/Doc/c-api/stable.rst index 124e58cf950b7a..25727d9a550ea1 100644 --- a/Doc/c-api/stable.rst +++ b/Doc/c-api/stable.rst @@ -113,7 +113,8 @@ On Windows, extensions that use the Stable ABI should be linked against ``python39.dll``. On some platforms, Python will look for and load shared library files named -with the ``abi3`` tag (e.g. ``mymodule.abi3.so``). +with the ``abi3`` tag (e.g. ``mymodule.abi3.so`` or +``mymodule.abi3-x86-64-linux-gnu.so``). It does not check if such extensions conform to a Stable ABI. The user (or their packaging tools) need to ensure that, for example, extensions built with the 3.10+ Limited API are not installed for lower