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

[python3] cross compile python3 for android on linux #33078

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
e80c8e2
cross compile python3 for android on linux
Arlen-LT Aug 9, 2023
b7b0541
add port-version
Arlen-LT Aug 9, 2023
352a97f
disable soversion for android to avoid ld link error in android runtime
Arlen-LT Aug 9, 2023
aef67be
merge to OPTIONS
Arlen-LT Aug 9, 2023
578dc87
use x-add-version to generate the corresponding json
Arlen-LT Aug 10, 2023
44304ff
Update ports/python3/portfile.cmake
Arlen-LT Aug 10, 2023
0cd257c
use sys.getandroidapilevel to judge if is running on Android
Arlen-LT Aug 10, 2023
08f1ef2
delete patch to auto generated configure file
Arlen-LT Aug 10, 2023
fb3b720
apply 0015 and 0016 always
Arlen-LT Aug 10, 2023
3ee21d2
merge master to this branch
Arlen-LT Aug 10, 2023
1f2450c
run ./vcpkg x-add-version python3 --overwrite-version
Arlen-LT Aug 10, 2023
5cf00f0
rename patch files to resolve conflict
Arlen-LT Aug 10, 2023
eb97247
use vcpkg_cmake_get_vars to pick appropriate compiler
Arlen-LT Aug 10, 2023
02beb3b
fix: use auto detected vars instead of magic number
Arlen-LT Aug 10, 2023
f2cdc84
add port-version:2
Arlen-LT Aug 10, 2023
dfee2f2
running ./vcpkg x-add-version --all
Arlen-LT Aug 10, 2023
c21ed1a
test CI
Arlen-LT Aug 10, 2023
610bf93
test CI
Arlen-LT Aug 11, 2023
3548a4d
add version
Arlen-LT Aug 11, 2023
babb351
Merge branch 'microsoft:master' into cross-build-python3-for-android
Arlen-LT Aug 11, 2023
e839a29
delete platform of vcpkg-cmake-get-vars
Arlen-LT Aug 11, 2023
baff5a7
Revert "delete platform of vcpkg-cmake-get-vars"
Arlen-LT Aug 11, 2023
a2a35e3
Update portfile.cmake
Arlen-LT Aug 11, 2023
77d4cd1
overwrite versions
Arlen-LT Aug 11, 2023
1df1eba
Revert "Update portfile.cmake"
Arlen-LT Aug 11, 2023
919fe67
update git-tree
Arlen-LT Aug 11, 2023
f2a060c
fix patch
Arlen-LT Aug 14, 2023
1632872
update git-tree
Arlen-LT Aug 14, 2023
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
16 changes: 16 additions & 0 deletions ports/python3/0017-disable-SOVERSION-for-Android.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/configure.ac b/configure.ac
index 73ee71c6d2..a62edaebae 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1153,7 +1153,10 @@
LDLIBRARY='libpython$(LDVERSION).so'
BLDLIBRARY='-L. -lpython$(LDVERSION)'
RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}
- INSTSONAME="$LDLIBRARY".$SOVERSION
+ if test $ac_sys_system != Linux-android
+ then
+ INSTSONAME="$LDLIBRARY".$SOVERSION
+ fi
if test "$with_pydebug" != yes
then
PY3LIBRARY=libpython3.so
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -460,6 +460,8 @@
pythonapi = PyDLL("python dll", None, _sys.dllhandle)
elif _sys.platform == "cygwin":
pythonapi = PyDLL("libpython%d.%d.dll" % _sys.version_info[:2])
+elif hasattr(_sys, 'getandroidapilevel'):
+ pythonapi = PyDLL("libpython%d.%d.so" % _sys.version_info[:2])
else:
pythonapi = PyDLL(None)

39 changes: 39 additions & 0 deletions ports/python3/portfile.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ set(PATCHES
0015-dont-use-WINDOWS-def.patch
)

if(VCPKG_CROSSCOMPILING AND VCPKG_TARGET_IS_ANDROID)
list(APPEND PATCHES
0017-disable-SOVERSION-for-Android.patch
0018-explicit-define-ctypes_pythonapi-for-Android.patch
)
endif()

if(VCPKG_LIBRARY_LINKAGE STREQUAL "static")
list(APPEND PATCHES 0002-static-library.patch)
endif()
Expand Down Expand Up @@ -250,6 +257,38 @@ else()
if(VCPKG_CROSSCOMPILING)
set(_python_for_build "${CURRENT_HOST_INSTALLED_DIR}/tools/python3/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}")
list(APPEND OPTIONS "--with-build-python=${_python_for_build}")

if(VCPKG_TARGET_IS_ANDROID)
vcpkg_cmake_get_vars(cmake_vars_file)
include("${cmake_vars_file}")
cmake_path(GET VCPKG_DETECTED_CMAKE_C_COMPILER PARENT_PATH llvm_dir)

if(VCPKG_DETECTED_CMAKE_ANDROID_ARCH STREQUAL "arm")
set(clang_arch_prefix "armv7a")
elseif(VCPKG_DETECTED_CMAKE_ANDROID_ARCH STREQUAL "arm64")
set(clang_arch_prefix "aarch64")
elseif(VCPKG_DETECTED_CMAKE_ANDROID_ARCH STREQUAL "x86_64")
set(clang_arch_prefix "x86_64")
elseif(VCPKG_DETECTED_CMAKE_ANDROID_ARCH STREQUAL "x86")
set(clang_arch_prefix "i686")
endif()

if(DEFINED clang_arch_prefix)
set(clang_c_compiler ${llvm_dir}/${clang_arch_prefix}-linux-android${VCPKG_DETECTED_CMAKE_SYSTEM_VERSION}-clang)
else()
set(clang_c_compiler ${VCPKG_DETECTED_CMAKE_C_COMPILER})
endif()

list(APPEND OPTIONS
"--build=${VCPKG_DETECTED_CMAKE_HOST_SYSTEM_PROCESSOR}-linux-gnu"
"CC=${clang_c_compiler}"
"READELF=${llvm_dir}/llvm-readelf"
# For CONFIG_SITE property needed while cross-compile: https://docs.python.org/3/using/configure.html#cmdoption-arg-CONFIG_SITE
"ac_cv_file__dev_ptmx=yes"
"ac_cv_file__dev_ptc=no"
"ac_cv_buggy_getaddrinfo=no"
)
endif()
else()
vcpkg_find_acquire_program(PYTHON3)
list(APPEND OPTIONS "ac_cv_prog_PYTHON_FOR_REGEN=${PYTHON3}")
Expand Down
7 changes: 6 additions & 1 deletion ports/python3/vcpkg.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "python3",
"version": "3.11.4",
"port-version": 1,
"port-version": 2,
"description": "The Python programming language",
"homepage": "https://github.com/python/cpython",
"license": "Python-2.0",
Expand Down Expand Up @@ -44,6 +44,11 @@
"name": "sqlite3",
"platform": "!(windows & static)"
},
{
"name": "vcpkg-cmake-get-vars",
"host": true,
"platform": "android"
},
{
"name": "vcpkg-msbuild",
"host": true,
Expand Down
2 changes: 1 addition & 1 deletion versions/baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -6602,7 +6602,7 @@
},
"python3": {
"baseline": "3.11.4",
"port-version": 1
"port-version": 2
},
"qca": {
"baseline": "2.3.5",
Expand Down
5 changes: 5 additions & 0 deletions versions/p-/python3.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
{
"versions": [
{
"git-tree": "96df607e3b806c6c3c877804e3a0ed2dbf1af00a",
"version": "3.11.4",
"port-version": 2
},
{
"git-tree": "531061b4485adebb80364473d227b0edf4ee8ed9",
"version": "3.11.4",
Expand Down