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

Add android cross compiling support #321

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

jcfr
Copy link
Contributor

@jcfr jcfr commented Jan 26, 2023

This corresponds to #280 being rebased against current master (along with extracting documentation into its own CROSS-COMPILING.rst document)

  • Test
  • Consolidate changes proposed here with the one originally suggested by @o01eg in Initial Android support #262
  • Add continuous integration (possibly by leveraging dockcross 1

Footnotes

  1. https://github.com/dockcross/dockcross#readme

@jcfr
Copy link
Contributor Author

jcfr commented Jan 26, 2023

@iyadahmed When (and if) you have the bandwidth, let us know what you think 🙏

Alternatively if time is limited, there is no problem integrating the patch originally suggested in #320 (comment)

@jcfr jcfr added the Project: crosscompilation crosscompilation specific label Jan 26, 2023
@esnosy
Copy link

esnosy commented Jan 27, 2023

I've just tried it, it works great, but it still does not execute the cmTC_* executables in a virtual device automatically, but not a problem, it can be done in a separate patch, also I was going to execute them manually anyways, I think this patch is good to go so far
@jcfr

@esnosy
Copy link

esnosy commented Jan 27, 2023

Here are the results of the binaries on an Android 5.0 arm64 virtual device, I think all of them succeeded except two
image

@esnosy
Copy link

esnosy commented Jan 27, 2023

Yep here are exit codes for each program, there's two extra programs that turned out to not return 0
image

@esnosy
Copy link

esnosy commented Jan 27, 2023

here's the configure command I'm using btw

cmake .. \
-D_download_3.10.9_md5="25eb3686327c157dcb8ac9f01105c306" \
-DPYTHON_VERSION=3.10.9 \
-DCMAKE_INSTALL_PREFIX=/home/iyad/Development/Blender_On_Android/lib/android_aarch64/python \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=21 \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_ANDROID_NDK=/home/iyad/Android/Sdk/ndk/25.1.8937393 \
-DCMAKE_ANDROID_STL_TYPE=c++_static
make install

@esnosy
Copy link

esnosy commented Jan 27, 2023

tests are failing on mac though :/ @jcfr
Let's integrate the other patch instead as it succeeds on MacOS according to CI

@esnosy
Copy link

esnosy commented Jan 27, 2023

for some reason this patch produces different check binaries than master

@esnosy
Copy link

esnosy commented Jan 27, 2023

Here are results of cmTC_* binaries from the other patch
image

@esnosy
Copy link

esnosy commented Jan 27, 2023

the second run of my patch after inputting return codes outputs more binaries

cmake .. \
-D_download_3.10.9_md5="25eb3686327c157dcb8ac9f01105c306" \
-DPYTHON_VERSION=3.10.9 \
-DCMAKE_INSTALL_PREFIX=/home/iyad/Development/Blender_On_Android/lib/android_aarch64/python \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=21 \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_ANDROID_NDK=/home/iyad/Android/Sdk/ndk/25.1.8937393 \
-DCMAKE_ANDROID_STL_TYPE=c++_static \
-DDOUBLE_IS_BIG_ENDIAN_IEEE754=0 \
-DDOUBLE_IS_LITTLE_ENDIAN_IEEE754=0 \
-DPLATFORM_RUN=0 \
-DPLATFORM_RUN__TRYRUN_OUTPUT="aarch64-linux-gnu" \
-DDOUBLE_IS_ARM_MIXED_ENDIAN_IEEE754=0 \
-DHAVE_BROKEN_NICE_EXITCODE=0 \
-DHAVE_BROKEN_POLL_EXITCODE=0 \
-DHAVE_MMAP_DEV_ZERO_EXITCODE=0

so I guess this patch has more fixes for Android, but it breaks MacOSX

returns codes and std output of those newly generated cmTC_* binaries
image

@esnosy
Copy link

esnosy commented Jan 27, 2023

ah for automatic running on virtual device my bad I should have used the instructions from unix docs,
still this CI macos failing hmm

@esnosy
Copy link

esnosy commented Jan 27, 2023

The run_on_android.sh script works great! got Python on the virtual device!
image

now we need to figure out why MacOSX CI fails 😄

@esnosy
Copy link

esnosy commented Jan 27, 2023

here's my final config command, now using the default Python version as Python 3.10 fails for some reason

cmake .. \
-DCMAKE_INSTALL_PREFIX=/home/iyad/Development/Blender_On_Android/lib/android_aarch64/python \
-DCMAKE_SYSTEM_NAME=Android \
-DCMAKE_SYSTEM_VERSION=21 \
-DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
-DCMAKE_ANDROID_NDK=/home/iyad/Android/Sdk/ndk/25.1.8937393 \
-DCMAKE_ANDROID_STL_TYPE=c++_static \
-DCMAKE_CROSSCOMPILING_EMULATOR=../run_on_android.sh \
-DANDROID_ALLOW_UNDEFINED_SYMBOLS=ON \
-DENABLE_DECIMAL=OFF \
-DENABLE_CTYPES=OFF

@esnosy
Copy link

esnosy commented Jan 27, 2023

Things are becoming more clear now, imo,

  • We should not rely on CMAKE_CXX_COMPILER_ID MATCHES "Clang" let's use APPLE OR ANDROID instead, hopefully this fixes the MacOSX CI
  • Let's also use ANDROID instead of ${CMAKE_SYSTEM_NAME} MATCHES "^Android" for sake of consistency and robustness

@jcfr

@jcfr jcfr force-pushed the add-android-cross-compiling-support branch from bf53a65 to 7a07b4d Compare June 28, 2023 22:52
@jcfr jcfr mentioned this pull request Jun 28, 2023
This was linked to issues Jun 28, 2023
o01eg and others added 9 commits June 28, 2023 19:06
It was not effective, and it was visible using Android Studio.
Translated to CMake from a patch on the Yocto project:
http://cgit.openembedded.org/openembedded-core/tree/meta/recipes-devtools/python/python3/0002-Don-t-do-runtime-test-to-get-float-byte-order.patch?h=zeus
It avoids the execution of a program on the target device,
and produces a clearer endianness result.
It avoids the need for checking it by running a program on the target
platform.
…piling

They are already present in source releases, so it is possible to ignore
the regeneration step. We do that only when cross-compiling, because it
is not possible to build for both the host and the target with a single
pass of CMake.
@jcfr jcfr force-pushed the add-android-cross-compiling-support branch from 6d0d7c1 to 6b3e42d Compare June 28, 2023 23:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Project: crosscompilation crosscompilation specific
Development

Successfully merging this pull request may close these issues.

Compile Python for Android? Android Cross-compilation.
3 participants