aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEli Schwartz <eschwartz@archlinux.org>2023-02-13 22:59:17 -0500
committerEli Schwartz <eschwartz@archlinux.org>2023-02-22 14:52:02 -0500
commitb2bb4573fb54cf4f0c7193a6ab75df64de0eced9 (patch)
tree2dfdb534a38a61168647d40f7b5bd0229ced7008
parentcedbf5db2c96dcd80287bc7d0d16a5af9afb6f7f (diff)
downloadmeson-b2bb4573fb54cf4f0c7193a6ab75df64de0eced9.zip
meson-b2bb4573fb54cf4f0c7193a6ab75df64de0eced9.tar.gz
meson-b2bb4573fb54cf4f0c7193a6ab75df64de0eced9.tar.bz2
python dependency: fix embed handling for system dependency
Only search for and provide linkage to libpython, if the dependency expects to be linked to it. Fixes overlinking on Linux / macOS when pkg-config isn't installed and the sysconfig lookup is used instead. This was correctly handled for pkg-config rather than deferring it until use, since commit bf832743441a1171518d7a436164c989be679410 -- but that handling neglected to cover sysconfig dependencies. And sysconfig would always try to link to libpython, it just respected the dependency configuration barely enough to allow falling back to "don't link" if both link_libpython=False and the library wasn't found. (cherry picked from commit d3148efe4f469412fbd1d7771b36e3082467979d) [backported to apply pre-code move] # Conflicts: # mesonbuild/dependencies/python.py
-rw-r--r--mesonbuild/modules/python.py25
1 files changed, 15 insertions, 10 deletions
diff --git a/mesonbuild/modules/python.py b/mesonbuild/modules/python.py
index 7e4469e..9aa7705 100644
--- a/mesonbuild/modules/python.py
+++ b/mesonbuild/modules/python.py
@@ -96,7 +96,15 @@ class _PythonDependencyBase(_Base):
self.platform = python_holder.platform
self.variables = python_holder.variables
self.paths = python_holder.paths
- self.link_libpython = python_holder.link_libpython
+ # The "-embed" version of python.pc / python-config was introduced in 3.8,
+ # and distutils extension linking was changed to be considered a non embed
+ # usage. Before then, this dependency always uses the embed=True handling
+ # because that is the only one that exists.
+ #
+ # On macOS and some Linux distros (Debian) distutils doesn't link extensions
+ # against libpython, even on 3.7 and below. We call into distutils and
+ # mirror its behavior. See https://github.com/mesonbuild/meson/issues/4117
+ self.link_libpython = python_holder.link_libpython or embed
self.info: T.Optional[T.Dict[str, str]] = None
if mesonlib.version_compare(self.version, '>= 3.0'):
self.major_version = 3
@@ -120,15 +128,8 @@ class PythonPkgConfigDependency(PkgConfigDependency, _PythonDependencyBase):
if libpc and not self.is_found:
mlog.debug(f'"python-{self.version}" could not be found in LIBPC, this is likely due to a relocated python installation')
- # The "-embed" version of python.pc was introduced in 3.8, and distutils
- # extension linking was changed to be considered a non embed usage. Before
- # then, this dependency always uses the embed=True file because that is the
- # only one that exists,
- #
- # On macOS and some Linux distros (Debian) distutils doesn't link extensions
- # against libpython, even on 3.7 and below. We call into distutils and
- # mirror its behavior. See https://github.com/mesonbuild/meson/issues/4117
- if not self.embed and not self.link_libpython and mesonlib.version_compare(self.version, '< 3.8'):
+ # pkg-config files are usually accurate starting with python 3.8
+ if not self.link_libpython and mesonlib.version_compare(self.version, '< 3.8'):
self.link_args = []
@@ -152,6 +153,10 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase):
else:
self._find_libpy(installation, environment)
+ if not self.link_libpython:
+ # match pkg-config behavior
+ self.link_args = []
+
if not self.clib_compiler.has_header('Python.h', '', environment, extra_args=self.compile_args):
self.is_found = False