Skip to content
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

Fail if we try to crosscompile while PYTHON_SOABI is not set. #12

Open
wants to merge 5 commits into
base: rolling
Choose a base branch
from

Conversation

AlexisTM
Copy link

@AlexisTM AlexisTM commented Oct 19, 2022

[NOTE: This would be a workaround until python_cmake_module#7, which I couldn't make work locally]

When cross-compiling, we need the PYTHON_SOABI variable to be set.
The current method was using the system python interpreter instead of the target one, causing incorrect variable naming as in: #9 and ros2/pybind11_vendor#16

The current methodology is to provide to people cross-compiling with a sysroot (found using CMAKE_SYSROOT) with an user friendly error message to explain which variable should be set. (PYTHON_SOABI)

The possibly better way would be to execute the target python version with qemu-${ARCH}-static. This means we need to find the arch, check for qemu for this arch, find Python within the sysroot and execute it.
One argument against it is often a the DevOps creating the sysroot will have qemu, but it is not systematic for the developer side, thus creating possibly a "it works on my machine" clash against the DevOps.

Another consideration is, as we are using a sysroot, the python version will likely be fixed;

Sample output:

Starting >>> python_cmake_module
--- stderr: python_cmake_module                            
CMake Error at cmake/Modules/CheckCrossCompilingSoabi.cmake:31 (message):
  We detected you defined a sysroot thus crosscompiling.

  You have to define the PYTHON_SOABI variable in the toolchain file, which
  looks like cpython-39-x86_64-linux-gnu or cpython-39-aarch64-linux-gnu.

  To find the correct PYTHON_SOABI value, you can execute the following from
  the target:

  python3 -c "from sysconfig import
  get_config_var;print(get_config_var('SOABI'))"

  Run it with qemu with: (expecting aarch64 as your

  qemu-aarch64-static -L /opt/bosch/sysroot
  /opt/bosch/sysroot/usr/bin/python3 -c "from sysconfig import
  get_config_var;print(get_config_var('SOABI'))"

  The toolchain should look like:

  set(PYTHON_SOABI cpython-39-aarch64-linux-gnu)

Call Stack (most recent call first):
  CMakeLists.txt:17 (CheckCrossCompilingSoabi)


---
Failed   <<< python_cmake_module [0.23s, exited with code 1]

Summary: 36 packages finished [25.8s]
  1 package failed: python_cmake_module
  2 packages had stderr output: python_cmake_module uncrustify_vendor

Signed-off-by: Alexis Paques <paa1ti@bosch.com>
Comment on lines +16 to +17
include(cmake/Modules/CheckCrossCompilingSoabi.cmake)
CheckCrossCompilingSoabi()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fail early instead of on usage of this library (which is after compiling the rmw middleware).

…rom the CMakelists.txt of this package.

Signed-off-by: Alexis Paques <paa1ti@bosch.com>
@AlexisTM AlexisTM force-pushed the feature/fail_on_missing_SOABI_for_crosscompilation branch from 355300f to 25839ff Compare October 19, 2022 10:06
Signed-off-by: Alexis Paques <paa1ti@bosch.com>
…n crosscompiling to allow Python version upgrades.

Signed-off-by: Alexis Paques <paa1ti@bosch.com>
@AlexisTM AlexisTM force-pushed the feature/fail_on_missing_SOABI_for_crosscompilation branch from a5294be to b1862e2 Compare October 19, 2022 12:23
Comment on lines +233 to +235
if(DEFINED CMAKE_SYSROOT)
set(PYTHON_MODULE_EXTENSION ${PythonExtra_EXTENSION_SUFFIX}${PythonExtra_EXTENSION_EXTENSION})
endif()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we are cross-compiling, we need to bypass the PYTHON_MODULE_EXTENSION definition done by pybind11 too, or this fix will not have effect on libraries using pybind11 directly (aka rclpy).

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 this pull request may close these issues.

2 participants