Skip to content

Commit 3c3caf5

Browse files
eli-schwartznirbheek
authored andcommitted
python module: stop using distutils "link to libpython" probe on recent python
On python >=3.8, this information is expected to be encoded in the sysconfig vars. In distutils, it is always necessary to link to libpython on Windows; for posix platforms, it depends on the value of LIBPYTHON (which is the library to link to, possibly the empty string) as generated by configure.ac and embedded into python.pc and python-config.sh, and then coded a second time in the distutils python sources. There are a couple of caveats which have ramifications for Cygwin and Android: - python.pc and python-config.sh disagree with distutils when python is not built shared. In that case, the former act the same as a shared build, while the latter *never* links to libpython - python.pc disagrees with python-config.sh and distutils when python is built shared. The former never links to libpython, while the latter do The disagreement is resolved in favor of distutils' behavior in all cases, and python.pc is correct for our purposes on python 3.12; see: python/cpython#100356 python/cpython#100967 Although it was not backported to older releases, Cygwin at least has always patched in a fix for python.pc, which behavior is now declared canonical. We can reliably assume it is always correct. This is the other half of the fix for #7702
1 parent d573c8f commit 3c3caf5

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

mesonbuild/scripts/python_info.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,23 @@ def get_install_paths():
6464
paths, install_paths = get_install_paths()
6565

6666
def links_against_libpython():
67-
from distutils.core import Distribution, Extension
68-
cmd = Distribution().get_command_obj('build_ext')
69-
cmd.ensure_finalized()
70-
return bool(cmd.get_libraries(Extension('dummy', [])))
67+
# on versions supporting python-embed.pc, this is the non-embed lib
68+
#
69+
# PyPy is not yet up to 3.12 and work is still pending to export the
70+
# relevant information (it doesn't automatically provide arbitrary
71+
# Makefile vars)
72+
if sys.version_info >= (3, 8) and not is_pypy:
73+
variables = sysconfig.get_config_vars()
74+
return bool(variables.get('LIBPYTHON', 'yes'))
75+
else:
76+
from distutils.core import Distribution, Extension
77+
cmd = Distribution().get_command_obj('build_ext')
78+
cmd.ensure_finalized()
79+
return bool(cmd.get_libraries(Extension('dummy', [])))
7180

7281
variables = sysconfig.get_config_vars()
7382
variables.update({'base_prefix': getattr(sys, 'base_prefix', sys.prefix)})
83+
is_pypy = '__pypy__' in sys.builtin_module_names
7484

7585
if sys.version_info < (3, 0):
7686
suffix = variables.get('SO')
@@ -88,7 +98,7 @@ def links_against_libpython():
8898
'install_paths': install_paths,
8999
'version': sysconfig.get_python_version(),
90100
'platform': sysconfig.get_platform(),
91-
'is_pypy': '__pypy__' in sys.builtin_module_names,
101+
'is_pypy': is_pypy,
92102
'is_venv': sys.prefix != variables['base_prefix'],
93103
'link_libpython': links_against_libpython(),
94104
'suffix': suffix,

0 commit comments

Comments
 (0)