aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mesonbuild/dependencies.py49
-rw-r--r--test cases/python3/2 extmodule/meson.build14
-rw-r--r--test cases/python3/3 cython/meson.build7
3 files changed, 49 insertions, 21 deletions
diff --git a/mesonbuild/dependencies.py b/mesonbuild/dependencies.py
index b76c3cb..82d1b75 100644
--- a/mesonbuild/dependencies.py
+++ b/mesonbuild/dependencies.py
@@ -1290,18 +1290,7 @@ class Python3Dependency(Dependency):
pass
if not self.is_found:
if mesonlib.is_windows():
- inc = sysconfig.get_path('include')
- platinc = sysconfig.get_path('platinclude')
- self.cargs = ['-I' + inc]
- if inc != platinc:
- self.cargs.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.libs = ['-L{}/libs'.format(basedir),
- '-lpython{}'.format(vernum)]
- self.is_found = True
- self.version = sysconfig.get_config_var('py_version_short')
+ self._find_libpy3_windows(environment)
elif mesonlib.is_osx():
# In OSX the Python 3 framework does not have a version
# number in its name.
@@ -1315,6 +1304,42 @@ class Python3Dependency(Dependency):
else:
mlog.log('Dependency', mlog.bold(self.name), 'found:', mlog.red('NO'))
+ def _find_libpy3_windows(self, env):
+ '''
+ Find python3 libraries on Windows and also verify that the arch matches
+ what we are building for.
+ '''
+ pyarch = sysconfig.get_platform()
+ arch = detect_cpu_family(env.coredata.compilers)
+ if arch == 'x86':
+ arch = '32'
+ elif arch == 'x86_64':
+ arch = '64'
+ else:
+ # We can't cross-compile Python 3 dependencies on Windows yet
+ mlog.log('Unknown architecture {!r} for'.format(arch),
+ mlog.bold(self.name))
+ self.is_found = False
+ return
+ # Pyarch ends in '32' or '64'
+ if arch != pyarch[-2:]:
+ mlog.log('Need', mlog.bold(self.name),
+ 'for {}-bit, but found {}-bit'.format(arch, pyarch[-2:]))
+ self.is_found = False
+ return
+ inc = sysconfig.get_path('include')
+ platinc = sysconfig.get_path('platinclude')
+ self.cargs = ['-I' + inc]
+ if inc != platinc:
+ self.cargs.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.libs = ['-L{}/libs'.format(basedir),
+ '-lpython{}'.format(vernum)]
+ self.version = sysconfig.get_config_var('py_version_short')
+ self.is_found = True
+
def get_compile_args(self):
return self.cargs
diff --git a/test cases/python3/2 extmodule/meson.build b/test cases/python3/2 extmodule/meson.build
index 858bbea..92a12b2 100644
--- a/test cases/python3/2 extmodule/meson.build
+++ b/test cases/python3/2 extmodule/meson.build
@@ -3,10 +3,14 @@ project('Python extension module', 'c',
# Because Windows Python ships only with optimized libs,
# we must build this project the same way.
-py3_dep = dependency('python3')
+py3_dep = dependency('python3', required : false)
-subdir('ext')
+if py3_dep.found()
+ subdir('ext')
-test('extmod',
- find_program('blaster.py'),
- env : ['PYTHONPATH=' + pypathdir])
+ test('extmod',
+ find_program('blaster.py'),
+ env : ['PYTHONPATH=' + pypathdir])
+else
+ error('MESON_SKIP_TEST: Python3 libraries not found, skipping test.')
+endif
diff --git a/test cases/python3/3 cython/meson.build b/test cases/python3/3 cython/meson.build
index 8729640..22bbf7a 100644
--- a/test cases/python3/3 cython/meson.build
+++ b/test cases/python3/3 cython/meson.build
@@ -2,10 +2,9 @@ project('cython', 'c',
default_options : ['warning_level=3'])
cython = find_program('cython3', required : false)
+py3_dep = dependency('python3', required : false)
-if cython.found()
- py3_dep = dependency('python3')
-
+if cython.found() and py3_dep.found()
subdir('libdir')
test('cython tester',
@@ -13,5 +12,5 @@ if cython.found()
env : ['PYTHONPATH=' + pydir]
)
else
- error('MESON_SKIP_TEST: Cython not found, skipping test.')
+ error('MESON_SKIP_TEST: Cython3 or Python3 libraries not found, skipping test.')
endif