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
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ ament_package(
CONFIG_EXTRAS "python_cmake_module-extras.cmake"
)

include(cmake/Modules/CheckCrossCompilingSoabi.cmake)
CheckCrossCompilingSoabi()
Comment on lines +16 to +17
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).


install(DIRECTORY cmake
DESTINATION share/${PROJECT_NAME})
30 changes: 30 additions & 0 deletions cmake/Modules/CheckCrossCompilingSoabi.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright 2022 Open Source Robotics Foundation, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

function(CheckCrossCompilingSoabi)
if(NOT DEFINED PYTHON_SOABI AND DEFINED CMAKE_SYSROOT)
message(FATAL_ERROR "We detected you defined a sysroot thus crosscompiling.\n"
"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.\n"
""
"To find the correct PYTHON_SOABI value, you can execute the following from the target:\n"
"python3 -c \"${_python_code}\"\n"
""
"Run it with qemu with: (expecting aarch64 as your \n"
"qemu-aarch64-static -L ${CMAKE_SYSROOT} ${CMAKE_SYSROOT}/usr/bin/python3 -c \"${_python_code}\"\n"
""
"The toolchain should look like:\n"
"set(PYTHON_SOABI cpython-39-aarch64-linux-gnu)\n"
)
endif()
endfunction()
2 changes: 2 additions & 0 deletions cmake/Modules/FindPythonExtra.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@ if(PYTHONINTERP_FOUND)
"from sysconfig import get_config_var"
"print(get_config_var('SOABI'))"
)
include(CheckCrossCompilingSoabi)
CheckCrossCompilingSoabi()
execute_process(
COMMAND
"${PYTHON_EXECUTABLE}"
Expand Down