Skip to content

Commit b2bb457

Browse files
committed
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 bf83274 -- 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 d3148ef) [backported to apply pre-code move] # Conflicts: # mesonbuild/dependencies/python.py
1 parent cedbf5d commit b2bb457

File tree

1 file changed

+15
-10
lines changed

1 file changed

+15
-10
lines changed

mesonbuild/modules/python.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,15 @@ def __init__(self, python_holder: 'PythonInstallation', embed: bool):
9696
self.platform = python_holder.platform
9797
self.variables = python_holder.variables
9898
self.paths = python_holder.paths
99-
self.link_libpython = python_holder.link_libpython
99+
# The "-embed" version of python.pc / python-config was introduced in 3.8,
100+
# and distutils extension linking was changed to be considered a non embed
101+
# usage. Before then, this dependency always uses the embed=True handling
102+
# because that is the only one that exists.
103+
#
104+
# On macOS and some Linux distros (Debian) distutils doesn't link extensions
105+
# against libpython, even on 3.7 and below. We call into distutils and
106+
# mirror its behavior. See https://github.com/mesonbuild/meson/issues/4117
107+
self.link_libpython = python_holder.link_libpython or embed
100108
self.info: T.Optional[T.Dict[str, str]] = None
101109
if mesonlib.version_compare(self.version, '>= 3.0'):
102110
self.major_version = 3
@@ -120,15 +128,8 @@ def __init__(self, name: str, environment: 'Environment',
120128
if libpc and not self.is_found:
121129
mlog.debug(f'"python-{self.version}" could not be found in LIBPC, this is likely due to a relocated python installation')
122130

123-
# The "-embed" version of python.pc was introduced in 3.8, and distutils
124-
# extension linking was changed to be considered a non embed usage. Before
125-
# then, this dependency always uses the embed=True file because that is the
126-
# only one that exists,
127-
#
128-
# On macOS and some Linux distros (Debian) distutils doesn't link extensions
129-
# against libpython, even on 3.7 and below. We call into distutils and
130-
# mirror its behavior. See https://github.com/mesonbuild/meson/issues/4117
131-
if not self.embed and not self.link_libpython and mesonlib.version_compare(self.version, '< 3.8'):
131+
# pkg-config files are usually accurate starting with python 3.8
132+
if not self.link_libpython and mesonlib.version_compare(self.version, '< 3.8'):
132133
self.link_args = []
133134

134135

@@ -152,6 +153,10 @@ def __init__(self, name: str, environment: 'Environment',
152153
else:
153154
self._find_libpy(installation, environment)
154155

156+
if not self.link_libpython:
157+
# match pkg-config behavior
158+
self.link_args = []
159+
155160
if not self.clib_compiler.has_header('Python.h', '', environment, extra_args=self.compile_args):
156161
self.is_found = False
157162

0 commit comments

Comments
 (0)