I'm trying to cross-compile an application using Meson. The application has a Python dependency. I'm building on a Linux system (the build machine) and I'm building a Windows executable (the host machine).
I cannot make Meson detect the Python dependency.
This is what I have tried. My meson.build is using Meson's Python module:
pymod = import('python')
python = pymod.find_installation('python3')
pybind11_include_dir = include_directories('./include')
pybind11_dep = declare_dependency(
compile_args : [
# see https://github.com/pybind/pybind11/issues/1604
'-fsized-deallocation',
'-fvisibility=hidden'
],
include_directories : pybind11_include_dir,
dependencies : [
python.dependency()
],
)
This works when I build a native Linux executable. When I cross-compile for Windows I have a Windows version of Python locally. I point to that in my cross_file.txt like this (I left out the mingw64 toolchain parts and host and build machine settings):
[binaries]
python = '/home/user/src/mingw/py38/python.exe'
[built-in options]
c_args = ['-I/home/user/src/mingw/py38/include', '-L/home/user/src/mingw/py38']
cpp_args = ['-I/home/user/src/mingw/py38/include', '-L/home/user/src/mingw/py38']
Now when I run meson setup build_win64 --buildtype=debugoptimized --cross-file cross_file.txt
meson finds the python executable, but then tries to execute. Which won't work because it's a Windows binary:
Program python3 found: YES (/home/user/src/mingw/py38/python.exe)
OPENING: ['/home/user/src/mingw/py38/python.exe', '-c', "import sysconfig\nimport json\nimport sys\n\ninstall_paths = sysconfig.get_paths(scheme='posix_prefix', vars={'base': '', 'platbase': '', 'installed_base': ''})\n\ndef links_against_libpython():\n from distutils.core import Distribution, Extension\n cmd = Distribution().get_command_obj('build_ext')\n cmd.ensure_finalized()\n return bool(cmd.get_libraries(Extension('dummy', [])))\n\nprint (json.dumps ({\n 'variables': sysconfig.get_config_vars(),\n 'paths': sysconfig.get_paths(),\n 'install_paths': install_paths,\n 'version': sysconfig.get_python_version(),\n 'platform': sysconfig.get_platform(),\n 'is_pypy': '__pypy__' in sys.builtin_module_names,\n 'link_libpython': links_against_libpython(),\n}))\n"]
Traceback (most recent call last):
-- snip ---
File "/usr/lib64/python3.6/subprocess.py", line 1364, in _execute_child
raise child_exception_type(errno_num, err_msg, err_filename)
OSError: [Errno 8] Exec format error: '/home/user/src/mingw/py38/python.exe'
The Meson Python module documentation does not mention cross compilation at all.
What is the correct way to make Meson find the Windows Python dependency settings under Linux?