From 29b0029ffcedb502ccb1daf7ea2164aa6bc562cd Mon Sep 17 00:00:00 2001 From: Shyamnath Premnadh Date: Tue, 23 Jan 2024 16:33:09 +0100 Subject: Android Deployment: Fix armv7a platform - There were a couple of errors when building Android wheels for this platform mostly caused due to having an extra "eabi" for all the clang compilers, but also that the CMAKE_HOST_PROCESSOR name was wrongly specified. - The api_level passed while creating the cross_compile.sh script was also wrong as this should always be a number. - The CMake FindPython module returns Python_SOABI as empty for armv7a due to a possible bug in the FindPython module. The Python_SOABI is obtained by running `python3-config --extension-suffix`. python3-config be a script can also be run on the host platform and hence for armv7a, the Python_SOABI can be explicitly specified to workaround the CMake bug. Task-number: PYSIDE-1612 Change-Id: I3515db730b8c4f283f4c9f1d2e78fbc9d1aa903a Reviewed-by: Friedemann Kleint (cherry picked from commit 713c75a0b2ec50573dfeb387dcf64dcd763b19a5) Reviewed-by: Qt Cherry-pick Bot --- sources/shiboken6/cmake/ShibokenHelpers.cmake | 6 ++++++ tools/cross_compile_android/main.py | 4 ++-- tools/cross_compile_android/templates/cross_compile.tmpl.sh | 8 +++++++- .../templates/toolchain_default.tmpl.cmake | 12 ++++++++++-- 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/sources/shiboken6/cmake/ShibokenHelpers.cmake b/sources/shiboken6/cmake/ShibokenHelpers.cmake index 6a0351899..1a46e5b26 100644 --- a/sources/shiboken6/cmake/ShibokenHelpers.cmake +++ b/sources/shiboken6/cmake/ShibokenHelpers.cmake @@ -202,6 +202,12 @@ macro(get_python_extension_suffix) # Python_SOABI is only set by CMake 3.17+ # TODO: Lower this to CMake 3.16 if possible. if(SHIBOKEN_IS_CROSS_BUILD) + # For android platform armv7a FindPython module return Python_SOABI as empty because + # it is unable to set Python_CONFIG i.e. find `python3-config` script + # This workaround sets the Python_SOABI manually for this platform. + if(CMAKE_SYSTEM_NAME STREQUAL "Android" AND CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") + set(Python_SOABI "cpython-310}") + endif() if(NOT Python_SOABI) message(FATAL_ERROR "Python_SOABI variable is empty.") endif() diff --git a/tools/cross_compile_android/main.py b/tools/cross_compile_android/main.py index d855802a2..93314de76 100644 --- a/tools/cross_compile_android/main.py +++ b/tools/cross_compile_android/main.py @@ -171,8 +171,8 @@ if __name__ == "__main__": # are named like x86_64-linux-android27-clang platform_data = None if plat_name == "armv7a": - platform_data = PlatformData("armv7a", f"eabi{api_level}", "armeabi-v7a", "armv7", "armv7", - "32") + platform_data = PlatformData("armv7a", api_level, "armeabi-v7a", "armv7", + "armv7", "32") elif plat_name == "aarch64": platform_data = PlatformData("aarch64", api_level, "arm64-v8a", "arm64_v8a", "armv8-a", "64") diff --git a/tools/cross_compile_android/templates/cross_compile.tmpl.sh b/tools/cross_compile_android/templates/cross_compile.tmpl.sh index ccf0cf8ea..85d032e2b 100644 --- a/tools/cross_compile_android/templates/cross_compile.tmpl.sh +++ b/tools/cross_compile_android/templates/cross_compile.tmpl.sh @@ -6,11 +6,17 @@ export HOST_ARCH={{ plat_name }}-linux-android export TOOLCHAIN={{ ndk_path }}/toolchains/llvm/prebuilt/linux-x86_64/bin export TOOL_PREFIX=$TOOLCHAIN/$HOST_ARCH export PLATFORM_API={{ api_level }} +{% if plat_name == "armv7a" -%} +export CXX=${TOOL_PREFIX}eabi${PLATFORM_API}-clang++ +export CPP="${TOOL_PREFIX}eabi${PLATFORM_API}-clang++ -E" +export CC=${TOOL_PREFIX}eabi${PLATFORM_API}-clang +{% else %} export CXX=${TOOL_PREFIX}${PLATFORM_API}-clang++ export CPP="${TOOL_PREFIX}${PLATFORM_API}-clang++ -E" +export CC=${TOOL_PREFIX}${PLATFORM_API}-clang +{% endif %} export AR=$TOOLCHAIN/llvm-ar export RANLIB=$TOOLCHAIN/llvm-ranlib -export CC=$TOOL_PREFIX${PLATFORM_API}-clang export LD=$TOOLCHAIN/ld export READELF=$TOOLCHAIN/llvm-readelf export CFLAGS='-fPIC -DANDROID' diff --git a/tools/cross_compile_android/templates/toolchain_default.tmpl.cmake b/tools/cross_compile_android/templates/toolchain_default.tmpl.cmake index 343389998..a691d50f2 100644 --- a/tools/cross_compile_android/templates/toolchain_default.tmpl.cmake +++ b/tools/cross_compile_android/templates/toolchain_default.tmpl.cmake @@ -5,7 +5,11 @@ cmake_minimum_required(VERSION 3.18) include_guard(GLOBAL) set(CMAKE_SYSTEM_NAME Android) +{% if plat_name == "armv7a" -%} +set(CMAKE_SYSTEM_PROCESSOR armv7-a) +{% else %} set(CMAKE_SYSTEM_PROCESSOR {{ plat_name }}) +{% endif %} set(CMAKE_ANDROID_API {{ api_level }}) set(CMAKE_ANDROID_NDK {{ ndk_path }}) set(CMAKE_ANDROID_ARCH_ABI {{ android_abi }}) @@ -15,8 +19,12 @@ if(NOT DEFINED ANDROID_PLATFORM AND NOT DEFINED ANDROID_NATIVE_API_LEVEL) set(ANDROID_PLATFORM "android-{{ api_level }}" CACHE STRING "") endif() set(ANDROID_SDK_ROOT {{ sdk_path }}) - -set(QT_COMPILER_FLAGS "--target={{ plat_name }}-linux-android{{ api_level }} \ +{% if plat_name == "armv7a" -%} +set(_TARGET_NAME_ENDING "eabi{{ api_level }}") +{% else %} +set(_TARGET_NAME_ENDING "{{ api_level }}") +{% endif %} +set(QT_COMPILER_FLAGS "--target={{ plat_name }}-linux-android${_TARGET_NAME_ENDING} \ -fomit-frame-pointer \ -march={{ gcc_march }} \ -msse4.2 \ -- cgit v1.2.3