From 7c2575f1c879dd3c3ab963c0b247511d8c83f881 Mon Sep 17 00:00:00 2001
From: Phil Thompson <phil@riverbankcomputing.com>
Date: Fri, 7 Aug 2026 14:53:45 +0100
Subject: [PATCH] Support for multi-arch stable ABI filenames

Python v3.15 added support for architecture-specific tags in the names of
extension modules that use the stable ABI.  SIP will generate these tags if
they are supported.

This also fixes a regression in SIP v6.16.0.  Resolves #112
---
 sipbuild/buildable.py | 31 ++++++++++++++++++++-----------
 1 file changed, 20 insertions(+), 11 deletions(-)

diff --git a/sipbuild/buildable.py b/sipbuild/buildable.py
index b6bf2903..00023fce 100644
--- a/sipbuild/buildable.py
+++ b/sipbuild/buildable.py
@@ -141,17 +141,26 @@ def get_module_extension(self):
 
         from importlib.machinery import EXTENSION_SUFFIXES
 
-        if self.gil_disabled:
-            target = '.abi3t'
-        elif self.uses_limited_api:
-            target = '.abi3'
-        else:
-            target = None
-
-        if target:
-            for s in EXTENSION_SUFFIXES:
-                if target in s:
-                    return s
+        if self.uses_limited_api:
+            # Prefer an arch-specific extension if present (added in Python
+            # v3.15).
+            abi3 = abi3t = None
+
+            for es in EXTENSION_SUFFIXES:
+                if es.startswith('.abi3t-'):
+                    abi3t = es
+                elif abi3t is None and es.startswith('.abi3t'):
+                    abi3t = es
+                elif es.startswith('.abi3-'):
+                    abi3 = es
+                elif abi3 is None and es.startswith('.abi3'):
+                    abi3 = es
+
+            if self.gil_disabled and abi3t is not None:
+                return abi3t
+
+            if abi3 is not None:
+                return abi3
 
         return EXTENSION_SUFFIXES[0]
 
