Skip to content

FindPythonLibsNew.cmake module is not suitable for cross-compilation environment #2139

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
ahesford opened this issue Mar 23, 2020 · 0 comments · Fixed by #2370
Closed

FindPythonLibsNew.cmake module is not suitable for cross-compilation environment #2139

ahesford opened this issue Mar 23, 2020 · 0 comments · Fixed by #2370

Comments

@ahesford
Copy link
Contributor

Issue description

The FindPythonLibsNew.cmake module launches a Python interpreter to determine some key properties for building of pybind11 and any dependent projects that may rely on cmake for configuration. In a cross-compilation environment, this causes at least three issues:

  1. If target-architecture executables are not compatible with the host platform, the cmake module will either fail to execute the Python interpreter or will execute an interpreter on the host. Note that it is generally not possible to invoke the target Python interpreter in a cross-compilation environment because the target executable may not be compatible with the host platform.

  2. When the host and target platforms have different pointer sizes and the cmake module attempts to run the Python interpreter from the host, FindPythonLibsNew.cmake may will fail with a FATAL_ERROR complaining that the bitness of Python and the chosen compiler do not agree if the module falls back to the host interpreter.

  3. The variable PYTHON_MODULE_EXTENSION variable, set from distutils.sysconfig.get_config_var('SO') (note: it seems that the SO variable is deprecated and should be replaced with EXT_SUFFIX) and assigned to the SUFFIX target property in pybind11Tools.cmake, may be wrong when the extension of the host interpreter includes architecture information from the host and the host interpreter is invoked by the module.

If the host and target Python interpreters have compatible version numbers and configurations, all but the PYTHON_SIZEOF_VOID_P and PYTHON_MODULE_EXTENSION variables may be propertly determined from executing the host interpreter. Nevertheless, relying on executing the Python interpreter to determine key configuration values is always prone to error in cross-compilation environments.

What is to be done?

Removing the dependency on FindPythonLibsNew.cmake and instead relying on FindPython.cmake that ships with cmake at least moves the Python configuration discovery problem outside of the pybind11 project back to cmake, where the incentive to support cross-platform and cross-compilation environments is much greater.

At a minimum, removing the PYTHON_SIZEOF_VOID_P check avoids the immediate problem. Allowing manual override of other variables would allow cmake projects that depend on pybind11 to force proper behavior in a cross-compilation environment. (I assume this is mostly an issue for packagers.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant