dependencies: Fix detection of link args on MSYS2
The sysconfig config variables are different on MSYS2 and the paths
are also different. We now also use the full path to the import or
static library instead of using -Lfoo -lpython35 etc.
Also obey the value of the 'static' keyword argument.
@@ -21,6 +21,8 @@ import shlex
import shutil
import sysconfig
+from pathlib import Path
+
from .. import mlog
from .. import mesonlib
from ..mesonlib import Popen_safe, extract_as_list
@@ -603,6 +605,7 @@ class Python3Dependency(ExternalDependency):
def __init__(self, environment, kwargs):
super().__init__('python3', environment, None, kwargs)
self.name = 'python3'
+ self.static = kwargs.get('static', False)
# We can only be sure that it is Python 3 at this point
self.version = '3'
self.pkgdep = None
@@ -658,6 +661,26 @@ class Python3Dependency(ExternalDependency):
mlog.log('Unknown Windows Python platform {!r}'.format(pyplat))
return None
+ def get_windows_link_args(self):
+ pyplat = sysconfig.get_platform()
+ if pyplat.startswith('win'):
+ vernum = sysconfig.get_config_var('py_version_nodot')
+ if self.static:
+ libname = 'libpython{}.a'.format(vernum)
+ else:
+ libname = 'python{}.lib'.format(vernum)
+ lib = Path(sysconfig.get_config_var('base')) / 'libs' / libname
+ elif pyplat == 'mingw':
+ if self.static:
+ libname = sysconfig.get_config_var('LIBRARY')
+ else:
+ libname = sysconfig.get_config_var('LDLIBRARY')
+ lib = Path(sysconfig.get_config_var('LIBDIR')) / libname
+ if not lib.exists():
+ mlog.log('Could not find Python3 library {!r}'.format(str(lib)))
+ return None
+ return [str(lib)]
+
def _find_libpy3_windows(self, env):
'''
Find python3 libraries on Windows and also verify that the arch matches
@@ -684,17 +707,19 @@ class Python3Dependency(ExternalDependency):
'found {}-bit'.format(arch, pyarch))
self.is_found = False
return
+ # This can fail if the library is not found
+ largs = self.get_windows_link_args()
+ if largs is None:
+ self.is_found = False
+ return
+ self.link_args = largs
+ # Compile args
inc = sysconfig.get_path('include')
platinc = sysconfig.get_path('platinclude')
self.compile_args = ['-I' + inc]
if inc != platinc:
self.compile_args.append('-I' + platinc)
- # Nothing exposes this directly that I coulf find
- basedir = sysconfig.get_config_var('base')
- vernum = sysconfig.get_config_var('py_version_nodot')
- self.link_args = ['-L{}/libs'.format(basedir),
- '-lpython{}'.format(vernum)]
- self.version = sysconfig.get_config_var('py_version_short')
+ self.version = sysconfig.get_config_var('py_version')
self.is_found = True
def get_methods(self):
