镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[galactic] [BUG] When cross compiling to aarch64 from x86_64 host PYTHON_MODULE_EXTENSION is not set #9

Open

Description

@siposcsaba89

Hi,

I set PYTHON_SOABI cmake variable in the toolchain, but the name of the libraries were not set correctly.
Expected behavior:
<lib_name>.cpython-36m-aarch64-linux-gnu.so

Actual behavior:
<lib_name>.cpython-36m-x86_64-linux-gnu.so

I fixed the problem by setting PYTHON_MODULE_EXTENSION variable, which is used by pybind11, to PYTHON_SOABI here

if(PYTHON_SOABI STREQUAL "" OR PYTHON_SOABI STREQUAL "None")

  if(PYTHON_SOABI STREQUAL "" OR PYTHON_SOABI STREQUAL "None")
    set(PythonExtra_EXTENSION_SUFFIX
      ""
      CACHE INTERNAL
      "The full suffix for Python native extensions. See PEP-3149: https://www.python.org/dev/peps/pep-3149/."
     )
    set(PYTHON_MODULE_EXTENSION "" CACHE INTERNAL "pybind suffix setting") # <------------------------------
  else()
    set(PythonExtra_EXTENSION_SUFFIX
       ".${PYTHON_SOABI}"
       CACHE INTERNAL
       "The full suffix for Python native extensions. See PEP-3149: https://www.python.org/dev/peps/pep-3149/."
    )
    set(PYTHON_MODULE_EXTENSION ".${PYTHON_SOABI}" CACHE INTERNAL "pybind11 suffix settings") # <------------------------------
  endif()

I don't know if this is an optimal solution or not, but it fixed the problem for me.

Activity

  1. AlexisTM commented on Oct 18, 2022

    @AlexisTM

    It seems to be quite a long standing issue ;)

    I have been getting the same issue. The core problem being the suffix is being computed in the host instead of the target python interpreter.

    The logic is close to Pybind11's version:

    https://github.com/pybind/pybind11/blob/914c06fb252b6cc3727d0eedab6736e88a3fcb01/tools/pybind11NewTools.cmake#L110-L116

      execute_process(
        COMMAND
          "${${_Python}_EXECUTABLE}" "-c"
          "import sys, importlib; s = importlib.import_module('distutils.sysconfig' if sys.version_info < (3, 10) else 'sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))"
        OUTPUT_VARIABLE _PYTHON_MODULE_EXTENSION
        ERROR_VARIABLE _PYTHON_MODULE_EXTENSION_ERR
        OUTPUT_STRIP_TRAILING_WHITESPACE)

    This could (not in a portable way) be done by using qemu and running the sysroot's version of Python instead, under the rationale you need qemu to create the sysroot. (But some might just have the sysroot built for them)

  2. AlexisTM commented on Oct 18, 2022

    @AlexisTM

    Our quick solution is to fix those variables according to the python command executed on target (or though chroot & qemu in the sysroot)

    python3 -c "import sys, importlib; s = importlib.import_module('distutils.sysconfig' if sys.version_info < (3, 10) else 'sysconfig'); print(s.get_config_var('EXT_SUFFIX') or s.get_config_var('SO'))"
    
    # See: https://github.com/ros2/pybind11_vendor to have pybind11 version, then
    # See: https://github.com/pybind/pybind11/blob/8a4bca8216f94f64d9582997db5e7eaf2e4660b3/tools/pybind11NewTools.cmake#L98-L111
    # Note the point!
    set(PYTHON_MODULE_EXTENSION ".cpython-39-aarch64-linux-gnu.so")
    # python_cmake_module workaround, PYTHON_MODULE_EXTENSION is set to PYTHON_SOABI
    # See: https://github.com/ros2/python_cmake_module/blob/d31a0b13225786e076e537a6f1ba67ba5cb2e620/cmake/Modules/FindPythonExtra.cmake#L159-L197
    # Note the lack of point & .so
    set(PYTHON_SOABI cpython-39-aarch64-linux-gnu)

    Linked to ros2/pybind11_vendor#16

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions