summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRalf Gommers <ralf.gommers@gmail.com>2023-04-21 23:39:27 +0100
committerEli Schwartz <eschwartz93@gmail.com>2023-05-05 12:23:52 -0400
commite4f6eeb7d77db7938588e5dd758c73291b40e4ee (patch)
tree5b487b415f9638174a2a16b305b5f7848a173791
parent9fe1efe357dcdb3c0c18e84f6ac27948271f1c53 (diff)
downloadmeson-e4f6eeb7d77db7938588e5dd758c73291b40e4ee.tar.gz
Python module: emit warning for debug buildtypes with MSVC and no debug Python
CPython adds a hard to avoid hardcoded link flag to look for a debug libpython. This results in a very puzzling error, so emit a warning with a clear message. Note that pybind11 has a workaround for this, which undefines `_DEBUG`. So users who use only pybind11 can use non-release buildtypes, but they won't get debug symbols on Windows unless they have a debug build.
-rw-r--r--mesonbuild/dependencies/python.py25
1 files changed, 24 insertions, 1 deletions
diff --git a/mesonbuild/dependencies/python.py b/mesonbuild/dependencies/python.py
index 65fef7f81..4546e8819 100644
--- a/mesonbuild/dependencies/python.py
+++ b/mesonbuild/dependencies/python.py
@@ -13,7 +13,7 @@
# limitations under the License.
from __future__ import annotations
-import functools, json, os
+import functools, json, os, textwrap
from pathlib import Path
import typing as T
@@ -275,6 +275,29 @@ class PythonSystemDependency(SystemDependency, _PythonDependencyBase):
libpath = Path(f'python{vernum}.dll')
else:
libpath = Path('libs') / f'python{vernum}.lib'
+ # For a debug build, pyconfig.h may force linking with
+ # pythonX_d.lib (see meson#10776). This cannot be avoided
+ # and won't work unless we also have a debug build of
+ # Python itself (except with pybind11, which has an ugly
+ # hack to work around this) - so emit a warning to explain
+ # the cause of the expected link error.
+ buildtype = self.env.coredata.get_option(mesonlib.OptionKey('buildtype'))
+ assert isinstance(buildtype, str)
+ debug = self.env.coredata.get_option(mesonlib.OptionKey('debug'))
+ # `debugoptimized` buildtype may not set debug=True currently, see gh-11645
+ is_debug_build = debug or buildtype == 'debug'
+ vscrt_debug = False
+ if mesonlib.OptionKey('b_vscrt') in self.env.coredata.options:
+ vscrt = self.env.coredata.options[mesonlib.OptionKey('b_vscrt')].value
+ if vscrt in {'mdd', 'mtd', 'from_buildtype', 'static_from_buildtype'}:
+ vscrt_debug = True
+ if is_debug_build and vscrt_debug and not self.variables.get('Py_DEBUG'):
+ mlog.warning(textwrap.dedent('''\
+ Using a debug build type with MSVC or an MSVC-compatible compiler
+ when the Python interpreter is not also a debug build will almost
+ certainly result in a failed build. Prefer using a release build
+ type or a debug Python interpreter.
+ '''))
# base_prefix to allow for virtualenvs.
lib = Path(self.variables.get('base_prefix')) / libpath
elif self.platform == 'mingw':