Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/whatsnew/3.16.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ New features
Other language changes
======================

* Stable ABI extensions 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 generate
these multiarch tagged filenames, by default, when targeting
compatibility with at least Python 3.15.
(Contributed by Stefano Rivera in :gh:`122931`.)


New modules
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_importlib/extension/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import unittest
import sys
import sysconfig


class FinderTests(abc.FinderTests):
Expand Down Expand Up @@ -73,6 +74,19 @@ def test_abi3_extension_suffixes(self):
self.assertIn(".abi3.so", suffixes)
self.assertIn(".abi3t.so", suffixes)

@unittest.skipIf(
not (sysconfig.get_config_var("SOABI_PLATFORM") or "").strip('"'),
"Linux-only test"
)
def test_multiarch_abi3_extension_suffixes(self):
suffixes = self.machinery.EXTENSION_SUFFIXES
platform = sysconfig.get_config_var("SOABI_PLATFORM").strip('"')
if Py_GIL_DISABLED:
self.assertNotIn(f".abi3-{platform}.so", suffixes)
else:
self.assertIn(f".abi3-{platform}.so", suffixes)
self.assertIn(f".abi3t-{platform}.so", suffixes)


(Frozen_FinderTests,
Source_FinderTests
Expand Down
Original file line number Diff line number Diff line change
@@ -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``.
6 changes: 6 additions & 0 deletions Python/dynload_shlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,14 @@ const char *_PyImport_DynLoadFiletab[] = {
"." ALT_SOABI ".so",
#endif
#ifndef Py_GIL_DISABLED
#ifdef SOABI_PLATFORM
".abi" PYTHON_ABI_STRING "-" SOABI_PLATFORM ".so",
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just defined the lower level configure variable that SOABI is built from. We could also build something like a STABLE_EXT_SUFFIX=-${SOABI_PLATFORM}.so in configure that could be used directly here, if that's preferable.

#endif /* SOABI_PLATFORM */
".abi" PYTHON_ABI_STRING ".so",
#endif /* Py_GIL_DISABLED */
#ifdef SOABI_PLATFORM
".abi" PYTHON_ABI_STRING "t-" SOABI_PLATFORM ".so",
#endif /* SOABI_PLATFORM */
".abi" PYTHON_ABI_STRING "t.so",
".so",
#endif /* __CYGWIN__ */
Expand Down
4 changes: 4 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1212,6 +1212,8 @@ AS_CASE([$ac_sys_system],
[SOABI_PLATFORM=$PLATFORM_TRIPLET]
)

AC_DEFINE_UNQUOTED([SOABI_PLATFORM], ["${SOABI_PLATFORM}"], [Platform tag, used in binary module extension filenames.])
Comment thread
stefanor marked this conversation as resolved.

if test x$MULTIARCH != x; then
MULTIARCH_CPPFLAGS="-DMULTIARCH=\\\"$MULTIARCH\\\""
fi
Expand Down
3 changes: 3 additions & 0 deletions pyconfig.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,9 @@
/* The size of '_Bool', as computed by sizeof. */
#undef SIZEOF__BOOL

/* Platform tag, used in binary module extension filenames. */
#undef SOABI_PLATFORM

/* Define to 1 if you have the ANSI C header files. */
#undef STDC_HEADERS

Expand Down
Loading