FindPython 3.26's SOSABI always empty, not producing SOABI extension for Stable ABI
The new support for the Limited API / Stable ABI (see #24141 (closed)) seems to be broken. According to the docs:
When option
WITH_SOABI
is also specified, the module suffix will include thePython3_SOSABI
value, if any.
Besides the typo (it should say Python_SOSABI
, all other values assume FindPython
rather than FindPython3
), the Python[3]_SOSABI
is always empty. It's being set from sysconfig.get_config_var("SOSABI")
, which is a non-existent config value (no mention of it in the CPython code base at all).
It should be set to "abi3"
on all Unix systems and ""
on Windows. It is not available in sysconfig as far as I can tell (print(*[(k, v) for k, v in sysconfig.get_config_vars().items() if isinstance(v, str) and "abi" in v])
does not print anything). You can find it (as one of several) in importlib.machinery.EXTENSION_SUFFIXES
. For me, I get ['.cpython-311-darwin.so', '.abi3.so', '.so']
; you can see the SOABI based suffix, the ABI3 suffix, and the generic suffix. PyPy returns ['.pypy37-pp73-darwin.so']
- it can't load something without SOABI (clash with CPython), and it doesn't support the limited ABI. Maybe checking to see if any suffix in importlib.machinery.EXTENSION_SUFFIXES
starts with .abi3
should be the thing that fills this with abi3
?
Example:
cmake_minimum_required(VERSION 3.26)
project(abi3_example LANGUAGES C)
find_package(Python COMPONENTS Interpreter Development.SABIModule)
python_add_library(abi3_example MODULE abi3_example.c WITH_SOABI USE_SABI 3.7)
#define PY_SSIZE_T_CLEAN
#include <Python.h>
float square(float x) { return x * x; }
static PyObject *square_wrapper(PyObject *self, PyObject *args) {
float input, result;
if (!PyArg_ParseTuple(args, "f", &input)) {
return NULL;
}
result = square(input);
return PyFloat_FromDouble(result);
}
static PyMethodDef pysimple_methods[] = {
{"square", square_wrapper, METH_VARARGS, "Square function"},
{NULL, NULL, 0, NULL}};
static struct PyModuleDef pysimple_module = {PyModuleDef_HEAD_INIT, "pysimple",
NULL, -1, pysimple_methods};
PyMODINIT_FUNC PyInit_abi3_example(void) {
return PyModule_Create(&pysimple_module);
}
This should produce abi3_example.abi3.so
on macOS and Linux, but instead it produces abi3_example.so
. Python_SOSABI
and Python3_SOSABI
are empty.