From c7308076966c1c55bc117ce9f7a7f49ac96acfa6 Mon Sep 17 00:00:00 2001 From: Andrew McNulty Date: Mon, 24 Apr 2023 09:52:28 +0200 Subject: Python: Add 'limited_api' kwarg to extension_module This commit adds a new keyword arg to extension_module() that enables a user to target the Python Limited API, declaring the version of the limited API that they wish to target. Two new unittests have been added to test this functionality. --- mesonbuild/scripts/python_info.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'mesonbuild/scripts/python_info.py') diff --git a/mesonbuild/scripts/python_info.py b/mesonbuild/scripts/python_info.py index 9c3a079..0f7787c 100755 --- a/mesonbuild/scripts/python_info.py +++ b/mesonbuild/scripts/python_info.py @@ -65,6 +65,20 @@ elif sys.version_info < (3, 8, 7): else: suffix = variables.get('EXT_SUFFIX') +limited_api_suffix = None +if sys.version_info >= (3, 2): + try: + from importlib.machinery import EXTENSION_SUFFIXES + limited_api_suffix = EXTENSION_SUFFIXES[1] + except Exception: + pass + +# pypy supports modules targetting the limited api but +# does not use a special suffix to distinguish them: +# https://doc.pypy.org/en/latest/cpython_differences.html#permitted-abi-tags-in-extensions +if '__pypy__' in sys.builtin_module_names: + limited_api_suffix = suffix + print(json.dumps({ 'variables': variables, 'paths': paths, @@ -76,4 +90,5 @@ print(json.dumps({ 'is_venv': sys.prefix != variables['base_prefix'], 'link_libpython': links_against_libpython(), 'suffix': suffix, + 'limited_api_suffix': limited_api_suffix, })) -- cgit v1.1