From ed7a5cba65df000085343467f44ae469c5b16050 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Thu, 26 Sep 2024 12:26:33 -0700 Subject: [PATCH 01/26] Run fake build --- .appveyor.yml | 65 ++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 56 insertions(+), 9 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index b2b7edc..6ea1180 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -1,14 +1,61 @@ -image: ubuntu2004 + +skip_branch_with_pr: true environment: - ANDROID_SDK_ROOT: /usr/lib/android-sdk + python_stack: python 3.12 + + matrix: + # - job_name: Build Python for Linux + # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu + + - job_name: Build Python for Windows + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + +matrix: + fast_finish: true + +stack: $python_stack + +for: + # ====================================== + # Build Python for Linux + # ====================================== + + - matrix: + only: + - job_name: Build Python for Linux + + install: + - echo install + + build_script: + - sh: | + echo build + + # ====================================== + # Build Python for Windows + # ====================================== + + - matrix: + only: + - job_name: Build Python for Windows + + install: + - echo install + + build_script: + - echo build -install: -- ls -al $ANDROID_SDK_ROOT + test: off -build_script: -- git clone https://github.com/beeware/cpython-android-source-deps -- cd cpython-android-source-deps -- ./build.sh + # artifacts: + # - path: client\build\windows\x64\runner\flet-windows.zip + # - path: sdk\python\packages\flet-desktop\dist\*.whl -test: off \ No newline at end of file + # deploy: + # provider: GitHub + # auth_token: $(GITHUB_TOKEN) + # release: $(APPVEYOR_REPO_TAG_NAME) + # artifact: flet_windows + # on: + # APPVEYOR_REPO_TAG: true \ No newline at end of file From 5a15776d21e3777ae68c9db0a985a48355c80c1c Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Thu, 26 Sep 2024 12:33:40 -0700 Subject: [PATCH 02/26] install python 3.12 --- .appveyor.yml | 9 +++++---- windows/unattend.xml | 23 +++++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 windows/unattend.xml diff --git a/.appveyor.yml b/.appveyor.yml index 6ea1180..b9e8ec1 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -3,6 +3,7 @@ skip_branch_with_pr: true environment: python_stack: python 3.12 + PYTHON_VERSION: 3.12.6 matrix: # - job_name: Build Python for Linux @@ -40,11 +41,11 @@ for: only: - job_name: Build Python for Windows - install: - - echo install - build_script: - - echo build + - cd windows + - curl -OL https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-amd64.exe + - start /wait python-%PYTHON_VERSION%-amd64.exe /quiet + - dir C:\python312-dist test: off diff --git a/windows/unattend.xml b/windows/unattend.xml new file mode 100644 index 0000000..286ae72 --- /dev/null +++ b/windows/unattend.xml @@ -0,0 +1,23 @@ + + + \ No newline at end of file From e17f14184b70871bda8d19852264265d657f3513 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Thu, 26 Sep 2024 12:41:21 -0700 Subject: [PATCH 03/26] Try uninstall --- .appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index b9e8ec1..c9f133b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -44,8 +44,11 @@ for: build_script: - cd windows - curl -OL https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-amd64.exe + - start /wait python-%PYTHON_VERSION%-amd64.exe /uninstall /quiet - start /wait python-%PYTHON_VERSION%-amd64.exe /quiet - dir C:\python312-dist + - cd C:\python312-dist + - 7z a python-windows-for-dart-%PYTHON_VERSION%.zip * test: off From 509539037862610ceee9acd3031d5ebd224406a5 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Thu, 26 Sep 2024 12:46:11 -0700 Subject: [PATCH 04/26] python --version --- .appveyor.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.appveyor.yml b/.appveyor.yml index c9f133b..71dceaa 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -41,6 +41,9 @@ for: only: - job_name: Build Python for Windows + install: + - C:\Python312\python --version + build_script: - cd windows - curl -OL https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-amd64.exe From 95e8596d0a845be2fb684517722d19266caa628d Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Thu, 26 Sep 2024 12:51:04 -0700 Subject: [PATCH 05/26] uninstall 3.12.5 --- .appveyor.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 71dceaa..3479d79 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -46,8 +46,10 @@ for: build_script: - cd windows + - curl -OL https://www.python.org/ftp/python/3.12.5/python-3.12.5-amd64.exe + - start /wait python-3.12.5-amd64.exe /uninstall /quiet + - curl -OL https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-amd64.exe - - start /wait python-%PYTHON_VERSION%-amd64.exe /uninstall /quiet - start /wait python-%PYTHON_VERSION%-amd64.exe /quiet - dir C:\python312-dist - cd C:\python312-dist From b6d0884422ee19c1b305c868c95cca237c1e1703 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Thu, 26 Sep 2024 12:55:35 -0700 Subject: [PATCH 06/26] upload artifact --- .appveyor.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 3479d79..0c8d867 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -57,9 +57,8 @@ for: test: off - # artifacts: - # - path: client\build\windows\x64\runner\flet-windows.zip - # - path: sdk\python\packages\flet-desktop\dist\*.whl + artifacts: + - path: windows\python-windows-for-dart-*.zip # deploy: # provider: GitHub From 35bcfd443d8844aa8acc746fdc5ec790865b0fb1 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Thu, 26 Sep 2024 13:02:02 -0700 Subject: [PATCH 07/26] Fix 7z --- .appveyor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 0c8d867..8cc98be 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -52,8 +52,7 @@ for: - curl -OL https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-amd64.exe - start /wait python-%PYTHON_VERSION%-amd64.exe /quiet - dir C:\python312-dist - - cd C:\python312-dist - - 7z a python-windows-for-dart-%PYTHON_VERSION%.zip * + - 7z a python-windows-for-dart-%PYTHON_VERSION%.zip C:\python312-dist\* test: off From 9499a64fe54c2a828187795c3d3db73e691acaa4 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Thu, 26 Sep 2024 13:16:28 -0700 Subject: [PATCH 08/26] compile lib --- .appveyor.yml | 3 ++- windows/exclude.txt | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 windows/exclude.txt diff --git a/.appveyor.yml b/.appveyor.yml index 8cc98be..296b609 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -52,7 +52,8 @@ for: - curl -OL https://www.python.org/ftp/python/%PYTHON_VERSION%/python-%PYTHON_VERSION%-amd64.exe - start /wait python-%PYTHON_VERSION%-amd64.exe /quiet - dir C:\python312-dist - - 7z a python-windows-for-dart-%PYTHON_VERSION%.zip C:\python312-dist\* + - C:\python312-dist\python -m compileall -b C:\python312-dist\Lib + - 7z a -xr@exclude.txt python-windows-for-dart-%PYTHON_VERSION%.zip C:\python312-dist\* test: off diff --git a/windows/exclude.txt b/windows/exclude.txt new file mode 100644 index 0000000..98cb92f --- /dev/null +++ b/windows/exclude.txt @@ -0,0 +1,3 @@ +__pycache__ +*.py +*.exe \ No newline at end of file From 396191745f211771aa703bc19a2860791ca070e0 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 10:01:52 -0700 Subject: [PATCH 09/26] Build Python for Android --- .appveyor.yml | 44 +++- android/.gitignore | 13 ++ android/README.md | 33 +++ android/android-env.sh | 107 +++++++++ android/build-all.sh | 9 + android/build.sh | 237 ++++++++++++++++++++ android/package-for-dart.sh | 55 +++++ android/patches/bldlibrary.patch | 49 ++++ android/patches/dynload_shlib.patch | 12 + android/patches/grp.patch | 16 ++ android/patches/lfs.patch | 16 ++ android/patches/python_for_build_deps.patch | 16 ++ android/patches/soname.patch | 17 ++ android/patches/sysroot_paths.patch | 14 ++ android/python-android-dart.exclude | 27 +++ 15 files changed, 656 insertions(+), 9 deletions(-) create mode 100644 android/.gitignore create mode 100644 android/README.md create mode 100644 android/android-env.sh create mode 100755 android/build-all.sh create mode 100755 android/build.sh create mode 100755 android/package-for-dart.sh create mode 100644 android/patches/bldlibrary.patch create mode 100644 android/patches/dynload_shlib.patch create mode 100644 android/patches/grp.patch create mode 100644 android/patches/lfs.patch create mode 100644 android/patches/python_for_build_deps.patch create mode 100644 android/patches/soname.patch create mode 100644 android/patches/sysroot_paths.patch create mode 100644 android/python-android-dart.exclude diff --git a/.appveyor.yml b/.appveyor.yml index 296b609..5c866fa 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,13 +4,16 @@ skip_branch_with_pr: true environment: python_stack: python 3.12 PYTHON_VERSION: 3.12.6 + GITHUB_TOKEN: + secure: 9SKIwc3VSfYJ5IChvNR74rlTF9BMbAfhCGu1/TmYJBMtC6lkY+UDDkZNK7rC9xnQFUxMrNgoo9kNcNAbKbU8XAcrSwkP2H4mX04FI7P+YbxfiWC8nVHhGNxR4LzO+GO0 matrix: - # - job_name: Build Python for Linux - # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu + - job_name: Build Python for Android + APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c + NDK_VERSION: r27 - - job_name: Build Python for Windows - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + # - job_name: Build Python for Windows + # APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 matrix: fast_finish: true @@ -19,19 +22,42 @@ stack: $python_stack for: # ====================================== - # Build Python for Linux + # Build Python for Android # ====================================== - matrix: only: - - job_name: Build Python for Linux + - job_name: Build Python for Android install: - - echo install + - read ver_maj ver_min < <(echo $PYTHON_VERSION | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/') + - export PYTHON_VERSION_SHORT="$ver_maj.$ver_min" build_script: - - sh: | - echo build + - cd android + + # Build all Python ABIs + - ./build-all.sh $PYTHON_VERSION + + # Package support package for use with mobile-forge + - mkdir -p dist + - tar -czf dist/python-android-mobile-forge-$PYTHON_VERSION_SHORT.tar.gz install support + + # Package individual ABIs for use with serious_python Flutter package + - ./package-for-dart.sh install $PYTHON_VERSION arm64-v8a + - ./package-for-dart.sh install $PYTHON_VERSION armeabi-v7a + - ./package-for-dart.sh install $PYTHON_VERSION x86_64 + + # Push all archives to artifacts + - find dist -maxdepth 1 -type f -iname python-android-*.tar.gz -exec appveyor PushArtifact -DeploymentName python-android {} \; + + test: off + + deploy: + provider: GitHub + auth_token: $(GITHUB_TOKEN) + release: v$(PYTHON_VERSION_SHORT) + artifact: python-android # ====================================== # Build Python for Windows diff --git a/android/.gitignore b/android/.gitignore new file mode 100644 index 0000000..96992bd --- /dev/null +++ b/android/.gitignore @@ -0,0 +1,13 @@ +.envrc +.vscode/ +build +dist +downloads +install +local +support +*.dist-info +__pycache__ +*.log +*.gz +*.DS_Store \ No newline at end of file diff --git a/android/README.md b/android/README.md new file mode 100644 index 0000000..37aa5ef --- /dev/null +++ b/android/README.md @@ -0,0 +1,33 @@ +# Python for Android + +Scripts and CI jobs for building Python 3 for Android. + +* Can be run on both Linux and macOS. +* Build Python 3.12 - specific or the last minor version. +* Installs NDK r26d or use pre-installed one with path configured by `NDK_HOME` variable. +* Creates Python installation with a structure suitable for https://github.com/flet-dev/mobile-forge + +## Usage + +To build the latest minor version of Python 3.12 for selected Android API: + +``` +./build.sh 3.12 arm64-v8a +``` + +To build all ABIs: + +``` +./build-all.sh 3.12 +``` + +## Credits + +Build process depends on: +* https://github.com/beeware/cpython-android-source-deps + +Based on the work from: +* https://github.com/chaquo/chaquopy/tree/master/target +* https://github.com/beeware/Python-Android-support +* https://github.com/beeware/cpython-android-source-deps +* https://github.com/GRRedWings/python3-android \ No newline at end of file diff --git a/android/android-env.sh b/android/android-env.sh new file mode 100644 index 0000000..19f60bd --- /dev/null +++ b/android/android-env.sh @@ -0,0 +1,107 @@ +fail() { + echo "$1" >&2 + exit 1 +} + +if [[ -z "${NDK_HOME-}" ]]; then + NDK_HOME=$HOME/ndk/$NDK_VERSION + echo "NDK_HOME environment variable is not set." + if [ ! -d $NDK_HOME ]; then + echo "Installing NDK $NDK_VERSION to $NDK_HOME" + + if [ $(uname) = "Darwin" ]; then + seven_zip=$downloads/7zip/7zz + if ! test -f $seven_zip; then + echo "Installing 7-zip" + mkdir -p $(dirname $seven_zip) + cd $(dirname $seven_zip) + curl -#OL https://www.7-zip.org/a/7z2301-mac.tar.xz + tar -xf 7z2301-mac.tar.xz + cd - + fi + + ndk_dmg=android-ndk-$NDK_VERSION-darwin.dmg + if ! test -f $downloads/$ndk_dmg; then + echo ">>> Downloading $ndk_dmg" + curl -#L -o $downloads/$ndk_dmg https://dl.google.com/android/repository/$ndk_dmg + fi + + cd $downloads + $seven_zip x -snld $ndk_dmg + mkdir -p $(dirname $NDK_HOME) + mv Android\ NDK\ */AndroidNDK*.app/Contents/NDK $NDK_HOME + rm -rf Android\ NDK\ * + cd - + else + ndk_zip=android-ndk-$NDK_VERSION-linux.zip + if ! test -f $downloads/$ndk_zip; then + echo ">>> Downloading $ndk_zip" + curl -#L -o $downloads/$ndk_zip https://dl.google.com/android/repository/$ndk_zip + fi + cd $downloads + unzip -oq $ndk_zip + mkdir -p $(dirname $NDK_HOME) + mv android-ndk-$NDK_VERSION $NDK_HOME + cd - + echo "NDK installed to $NDK_HOME" + fi + else + echo "NDK $NDK_VERSION is already installed in $NDK_HOME" + fi +else + echo "NDK home: $NDK_HOME" +fi + +if [ $host_triplet = "arm-linux-androideabi" ]; then + clang_triplet=armv7a-linux-androideabi +else + clang_triplet=$host_triplet +fi + +# These variables are based on BuildSystemMaintainers.md above, and +# $NDK_HOME/build/cmake/android.toolchain.cmake. +toolchain=$(echo $NDK_HOME/toolchains/llvm/prebuilt/*) +export AR="$toolchain/bin/llvm-ar" +export AS="$toolchain/bin/llvm-as" +export CC="$toolchain/bin/${clang_triplet}$api_level-clang" +export CXX="${CC}++" +export LD="$toolchain/bin/ld" +export NM="$toolchain/bin/llvm-nm" +export RANLIB="$toolchain/bin/llvm-ranlib" +export READELF="$toolchain/bin/llvm-readelf" +export STRIP="$toolchain/bin/llvm-strip" + +# The quotes make sure the wildcard in the `toolchain` assignment has been expanded. +for path in "$AR" "$AS" "$CC" "$CXX" "$LD" "$NM" "$RANLIB" "$READELF" "$STRIP"; do + if ! [ -e "$path" ]; then + fail "$path does not exist" + fi +done + +# Use -idirafter so that package-specified -I directories take priority. For example, +# grpcio provides its own BoringSSL headers which must be used rather than our OpenSSL. +export CFLAGS="-idirafter ${prefix:?}/include" +export LDFLAGS="-L${prefix:?}/lib -Wl,--build-id=sha1 -Wl,--no-rosegment" + +# Many packages get away with omitting this on standard Linux, but Android is stricter. +LDFLAGS+=" -lm" + +case $abi in + armeabi-v7a) + CFLAGS+=" -march=armv7-a -mthumb" + ;; + x86) + # -mstackrealign is unnecessary because it's included in the clang launcher script + # which is pointed to by $CC. + ;; +esac + +export PKG_CONFIG="pkg-config --define-prefix" +export PKG_CONFIG_LIBDIR="$prefix/lib/pkgconfig" + +# conda-build variable name +if [ $(uname) = "Darwin" ]; then + export CPU_COUNT=$(sysctl -n hw.ncpu) +else + export CPU_COUNT=$(nproc) +fi diff --git a/android/build-all.sh b/android/build-all.sh new file mode 100755 index 0000000..3297b77 --- /dev/null +++ b/android/build-all.sh @@ -0,0 +1,9 @@ +#!/bin/bash +set -eu + +python_version=${1:?} +abis="arm64-v8a armeabi-v7a x86_64 x86" + +for abi in $abis; do + ./build.sh $python_version $abi +done \ No newline at end of file diff --git a/android/build.sh b/android/build.sh new file mode 100755 index 0000000..3205faa --- /dev/null +++ b/android/build.sh @@ -0,0 +1,237 @@ +#!/bin/bash +set -eu + +python_version=${1:?} +abi=${2:?} +NDK_VERSION=r27 +api_level=24 + +bzip2_version=1.0.8-1 +xz_version=5.4.6-0 +libffi_version=3.4.4-2 +openssl_version=3.0.15-0 +sqlite_version=3.45.2-0 + +os=android +build=custom + +project_dir=$(dirname $(realpath $0)) +downloads=$project_dir/downloads + +# build short Python version +read python_version_major python_version_minor < <(echo $python_version | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/') +if [[ $python_version =~ ^[0-9]+\.[0-9]+$ ]]; then + python_version=$(curl --silent "https://www.python.org/ftp/python/" | sed -nr "s/^.*\"($python_version_major\.$python_version_minor\.[0-9]+)\/\".*$/\1/p" | sort -rV | head -n 1) + echo "Python version: $python_version" +fi +python_version_short=$python_version_major.$python_version_minor +python_version_int=$(($python_version_major * 100 + $python_version_minor)) + +curl_flags="--disable --fail --location --create-dirs --progress-bar" +mkdir -p $downloads + +case $abi in + armeabi-v7a) + host_triplet=arm-linux-androideabi + ;; + arm64-v8a) + host_triplet=aarch64-linux-android + ;; + x86) + host_triplet=i686-linux-android + ;; + x86_64) + host_triplet=x86_64-linux-android + ;; + *) + fail "Unknown ABI: '$abi'" + ;; +esac + +# create VERSIONS support file +support_versions=$project_dir/support/$python_version_short/$os/VERSIONS +mkdir -p $(dirname $support_versions) +echo ">>> Create VERSIONS file for $os" +echo "Python version: $python_version " > $support_versions +echo "Build: $build" >> $support_versions +echo "Min $os version: $api_level" >> $support_versions +echo "---------------------" >> $support_versions +echo "libFFI: $libffi_version" >> $support_versions +echo "BZip2: $bzip2_version" >> $support_versions +echo "OpenSSL: $openssl_version" >> $support_versions +echo "XZ: $xz_version" >> $support_versions + +# BZip2 +# =============== +bzip2_install=$project_dir/install/$os/$abi/bzip2-$bzip2_version +bzip2_lib=$bzip2_install/lib/libbz2.a +bzip2_filename=bzip2-$bzip2_version-$host_triplet.tar.gz + +echo ">>> Download BZip2 for $abi" +curl $curl_flags -o $downloads/$bzip2_filename \ + https://github.com/beeware/cpython-android-source-deps/releases/download/bzip2-$bzip2_version/$bzip2_filename + +echo ">>> Install BZip2 for $abi" +mkdir -p $bzip2_install +tar zxvf $downloads/$bzip2_filename -C $bzip2_install +touch $bzip2_lib + +# XZ (LZMA) +# ================= +xz_install=$project_dir/install/$os/$abi/xz-$xz_version +xz_lib=$xz_install/lib/liblzma.a +xz_filename=xz-$xz_version-$host_triplet.tar.gz + +echo ">>> Download XZ for $abi" +curl $curl_flags -o $downloads/$xz_filename \ + https://github.com/beeware/cpython-android-source-deps/releases/download/xz-$xz_version/$xz_filename + +echo ">>> Install XZ for $abi" +mkdir -p $xz_install +tar zxvf $downloads/$xz_filename -C $xz_install +touch $xz_lib + +# LibFFI +# ================= +libffi_install=$project_dir/install/$os/$abi/libffi-$libffi_version +libffi_lib=$libffi_install/lib/libffi.a +libffi_filename=libffi-$libffi_version-$host_triplet.tar.gz + +echo ">>> Download LibFFI for $abi" +curl $curl_flags -o $downloads/$libffi_filename \ + https://github.com/beeware/cpython-android-source-deps/releases/download/libffi-$libffi_version/$libffi_filename + +echo ">>> Install LibFFI for $abi" +mkdir -p $libffi_install +tar zxvf $downloads/$libffi_filename -C $libffi_install +touch $libffi_lib + +# OpenSSL +# ================= +openssl_install=$project_dir/install/$os/$abi/openssl-$openssl_version +openssl_lib=$openssl_install/lib/libssl.a +openssl_filename=openssl-$openssl_version-$host_triplet.tar.gz + +echo ">>> Download OpenSSL for $abi" +curl $curl_flags -o $downloads/$openssl_filename \ + https://github.com/beeware/cpython-android-source-deps/releases/download/openssl-$openssl_version/$openssl_filename + +echo ">>> Install OpenSSL for $abi" +mkdir -p $openssl_install +tar zxvf $downloads/$openssl_filename -C $openssl_install +touch $openssl_lib + +# SQLite +# ================= +sqlite_install=$project_dir/install/$os/$abi/sqlite-$sqlite_version +sqlite_lib=$sqlite_install/lib/libsqlite3.la +sqlite_filename=sqlite-$sqlite_version-$host_triplet.tar.gz + +echo ">>> Download SQLite for $abi" +curl $curl_flags -o $downloads/$sqlite_filename \ + https://github.com/beeware/cpython-android-source-deps/releases/download/sqlite-$sqlite_version/$sqlite_filename + +echo ">>> Install SQLite for $abi" +mkdir -p $sqlite_install +tar zxvf $downloads/$sqlite_filename -C $sqlite_install +touch $sqlite_lib + +# Python +# =============== + +build_dir=$project_dir/build/$os/$abi +python_build_dir=$project_dir/build/$os/$abi/python-$python_version +python_install=$project_dir/install/$os/$abi/python-$python_version +python_lib=$sqlite_install/lib/libpython$python_version_short.a +python_filename=Python-$python_version.tgz + +echo ">>> Download Python for $abi" +curl $curl_flags -o $downloads/$python_filename \ + https://www.python.org/ftp/python/$python_version/$python_filename + +echo ">>> Unpack Python for $abi" +rm -rf $build_dir +mkdir -p $build_dir +tar zxvf $downloads/$python_filename -C $build_dir +mv $build_dir/Python-$python_version $python_build_dir +touch $python_build_dir/configure + +echo ">>> Configuring Python build environment for $abi" + +# configure build environment +prefix=$python_build_dir +. $project_dir/android-env.sh + +cd $python_build_dir + +# apply patches +echo ">>> Patching Python for $abi" +patches="dynload_shlib lfs soname" +if [ $python_version_int -le 311 ]; then + patches+=" sysroot_paths" +fi +if [ $python_version_int -ge 311 ]; then + patches+=" python_for_build_deps" +fi +if [ $python_version_int -ge 312 ]; then + patches+=" bldlibrary grp" +fi +for name in $patches; do + patch -p1 -i $project_dir/patches/$name.patch +done + +# Add sysroot paths, otherwise Python 3.8's setup.py will think libz is unavailable. +CFLAGS+=" -I$toolchain/sysroot/usr/include" +LDFLAGS+=" -L$toolchain/sysroot/usr/lib/$host_triplet/$api_level" + +# The configure script omits -fPIC on Android, because it was unnecessary on older versions of +# the NDK (https://bugs.python.org/issue26851). But it's definitely necessary on the current +# version, otherwise we get linker errors like "Parser/myreadline.o: relocation R_386_GOTOFF +# against preemptible symbol PyOS_InputHook cannot be used when making a shared object". +export CCSHARED="-fPIC" + +# Override some tests. +cat > config.site <>> Configuring Python for $abi" +./configure \ + LIBLZMA_CFLAGS="-I$xz_install/include" \ + LIBLZMA_LIBS="-L$xz_install/lib -llzma" \ + BZIP2_CFLAGS="-I$bzip2_install/include" \ + BZIP2_LIBS="-L$bzip2_install/lib -lbz2" \ + LIBFFI_CFLAGS="-I$libffi_install/include" \ + LIBFFI_LIBS="-L$libffi_install/lib -lffi" \ + --host=$host_triplet \ + --build=$(./config.guess) \ + --with-build-python=yes \ + --prefix="$python_install" \ + --enable-ipv6 \ + --with-openssl="$openssl_install" \ + --enable-shared \ + --without-ensurepip \ + 2>&1 | tee -a ../python-$python_version.config.log + +echo ">>> Building Python for $abi" +make all \ + 2>&1 | tee -a ../python-$python_version.build.log + +echo ">>> Installing Python for $abi" +make install \ + 2>&1 | tee -a ../python-$python_version.install.log + +echo ">>> Copying Python dependencies $abi" +cp {$openssl_install,$sqlite_install}/lib/*_python.so $python_install/lib + +echo ">>> Stripping dynamic libraries for $abi" +find $python_install -type f -iname "*.so" -exec $STRIP --strip-unneeded {} \; + +echo ">>> Replacing host platform" +sed -i -e "s/_PYTHON_HOST_PLATFORM=.*/_PYTHON_HOST_PLATFORM=android-$api_level-$abi/" $python_install/lib/python$python_version_short/config-$python_version_short/Makefile + +# the end! \ No newline at end of file diff --git a/android/package-for-dart.sh b/android/package-for-dart.sh new file mode 100755 index 0000000..759bf86 --- /dev/null +++ b/android/package-for-dart.sh @@ -0,0 +1,55 @@ +#!/bin/bash +set -eu + +install_root=${1:?} +python_version=${2:?} +abi=${3:?} + +script_dir=$(dirname $(realpath $0)) + +# build short Python version +read python_version_major python_version_minor < <(echo $python_version | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/') +python_version_short=$python_version_major.$python_version_minor + +# create build dir +build_dir=build/python-$python_version/$abi +rm -rf $build_dir +mkdir -p $build_dir +build_dir=$(realpath $build_dir) + +# create dist dir +mkdir -p dist + +# copy files to build +rsync -av --exclude-from=$script_dir/python-android-dart.exclude $install_root/android/$abi/python-$python_version/* $build_dir + +# create libpythonbundle.so +bundle_dir=$build_dir/libpythonbundle +mkdir -p $bundle_dir + +# modules with *.so files +mv $build_dir/lib/python$python_version_short/lib-dynload $bundle_dir/modules + +# stdlib +# stdlib_zip=$bundle_dir/stdlib.zip +cd $build_dir/lib/python$python_version_short +python -m compileall -b . +find . \( -name '*.so' -or -name '*.py' -or -name '*.typed' \) -type f -delete +rm -rf __pycache__ +rm -rf **/__pycache__ +# zip -r $stdlib_zip . +cd - +mv $build_dir/lib/python$python_version_short $bundle_dir/stdlib + +# compress libpythonbundle +cd $bundle_dir +zip -r ../libpythonbundle.so . +cd - +rm -rf $bundle_dir + +# copy *.so from lib +cp $build_dir/lib/*.so $build_dir +rm -rf $build_dir/lib + +# final archive +tar -czf dist/python-android-dart-$python_version_short-$abi.tar.gz -C $build_dir . \ No newline at end of file diff --git a/android/patches/bldlibrary.patch b/android/patches/bldlibrary.patch new file mode 100644 index 0000000..4dda79f --- /dev/null +++ b/android/patches/bldlibrary.patch @@ -0,0 +1,49 @@ +--- Python-3.12.0-original/configure 2023-11-22 09:33:49 ++++ Python-3.12.0/configure 2023-11-22 10:13:05 +@@ -7476,6 +7476,7 @@ + case $ac_sys_system in + CYGWIN*) + LDLIBRARY='libpython$(LDVERSION).dll.a' ++ BLDLIBRARY='-L. -lpython$(LDVERSION)' + DLLLIBRARY='libpython$(LDVERSION).dll' + ;; + SunOS*) +@@ -24374,7 +24375,7 @@ + # On Android and Cygwin the shared libraries must be linked with libpython. + + if test "$PY_ENABLE_SHARED" = "1" && ( test -n "$ANDROID_API_LEVEL" || test "$MACHDEP" = "cygwin"); then +- LIBPYTHON="-lpython${VERSION}${ABIFLAGS}" ++ LIBPYTHON="$BLDLIBRARY" + else + LIBPYTHON='' + fi +--- Python-3.12.0-original/Modules/makesetup 2023-10-02 12:48:14 ++++ Python-3.12.0/Modules/makesetup 2023-11-22 10:11:40 +@@ -86,18 +86,6 @@ + # Newline for sed i and a commands + NL='\ + ' +- +-# Setup to link with extra libraries when making shared extensions. +-# Currently, only Cygwin needs this baggage. +-case `uname -s` in +-CYGWIN*) if test $libdir = . +- then +- ExtraLibDir=. +- else +- ExtraLibDir='$(LIBPL)' +- fi +- ExtraLibs="-L$ExtraLibDir -lpython\$(LDVERSION)";; +-esac + + # Main loop + for i in ${*-Setup} +@@ -286,7 +274,7 @@ + ;; + esac + rule="$file: $objs" +- rule="$rule; \$(BLDSHARED) $objs $libs $ExtraLibs -o $file" ++ rule="$rule; \$(BLDSHARED) $objs $libs \$(LIBPYTHON) -o $file" + echo "$rule" >>$rulesf + done + done diff --git a/android/patches/dynload_shlib.patch b/android/patches/dynload_shlib.patch new file mode 100644 index 0000000..4260a05 --- /dev/null +++ b/android/patches/dynload_shlib.patch @@ -0,0 +1,12 @@ +--- a/Python/dynload_shlib.c ++++ b/Python/dynload_shlib.c +@@ -66,7 +66,8 @@ _PyImport_FindSharedFuncptr(const char *prefix, + char pathbuf[260]; + int dlopenflags=0; + +- if (strchr(pathname, '/') == NULL) { ++ // Chaquopy disabled: this interferes with our workaround in importer.prepare_dlopen. ++ if (0 && strchr(pathname, '/') == NULL) { + /* Prefix bare filename with "./" */ + PyOS_snprintf(pathbuf, sizeof(pathbuf), "./%-.255s", pathname); + pathname = pathbuf; diff --git a/android/patches/grp.patch b/android/patches/grp.patch new file mode 100644 index 0000000..70ab19b --- /dev/null +++ b/android/patches/grp.patch @@ -0,0 +1,16 @@ +--- Python-3.12.0-original/configure 2023-11-20 18:40:13 ++++ Python-3.12.0/configure 2023-11-20 19:06:42 +@@ -28545,6 +28545,13 @@ + py_cv_module__scproxy=n/a + py_cv_module_spwd=n/a + ;; #( ++ ++ # Chaquopy: we can't build the grp module, because getgrent and setgrent aren't ++ # available until API level 26. ++ Linux-android) ++ py_cv_module_grp=n/a ++ ;; ++ + Emscripten|WASI) : + + diff --git a/android/patches/lfs.patch b/android/patches/lfs.patch new file mode 100644 index 0000000..4f32859 --- /dev/null +++ b/android/patches/lfs.patch @@ -0,0 +1,16 @@ +--- a/configure ++++ b/configure +@@ -8373,7 +8373,12 @@ $as_echo "#define HAVE_HTOLE64 1" >>confdefs.h + + fi + +-use_lfs=yes ++# Chaquopy: changed "yes" to "no". _LARGEFILE_SOURCE has no effect on Android, and ++# _FILE_OFFSET_BITS=64 has no effect on 64-bit ABIs, but on 32-bit ABIs it causes many critical ++# functions to disappear on API levels older than 24. See ++# https://android.googlesource.com/platform/bionic/+/master/docs/32-bit-abi.md. ++use_lfs=no ++ + # Don't use largefile support for GNU/Hurd + case $ac_sys_system in GNU*) + use_lfs=no diff --git a/android/patches/python_for_build_deps.patch b/android/patches/python_for_build_deps.patch new file mode 100644 index 0000000..820dd58 --- /dev/null +++ b/android/patches/python_for_build_deps.patch @@ -0,0 +1,16 @@ +--- a/Makefile.pre.in 2022-10-24 17:35:39.000000000 +0000 ++++ b/Makefile.pre.in 2022-11-01 18:20:18.472102145 +0000 +@@ -292,7 +292,12 @@ + PYTHON_FOR_BUILD=@PYTHON_FOR_BUILD@ + # Single-platform builds depend on $(BUILDPYTHON). Cross builds use an + # external "build Python" and have an empty PYTHON_FOR_BUILD_DEPS. +-PYTHON_FOR_BUILD_DEPS=@PYTHON_FOR_BUILD_DEPS@ ++# ++# Chaquopy: Was PYTHON_FOR_BUILD_DEPS from the configure script, which is empty when ++# cross-compiling (https://github.com/python/cpython/pull/93977). But this means that in ++# parallel builds, the sharedmods target can start running before libpython is available ++# (https://github.com/beeware/briefcase-android-gradle-template/pull/55). ++PYTHON_FOR_BUILD_DEPS=$(LDLIBRARY) + + # Single-platform builds use Programs/_freeze_module.c for bootstrapping and + # ./_bootstrap_python Programs/_freeze_module.py for remaining modules diff --git a/android/patches/soname.patch b/android/patches/soname.patch new file mode 100644 index 0000000..a348464 --- /dev/null +++ b/android/patches/soname.patch @@ -0,0 +1,17 @@ +--- Python-3.12.0-original/configure 2023-11-20 19:18:30 ++++ Python-3.12.0/configure 2023-11-21 08:37:46 +@@ -7492,7 +7492,13 @@ + LDLIBRARY='libpython$(LDVERSION).so' + BLDLIBRARY='-L. -lpython$(LDVERSION)' + RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} +- INSTSONAME="$LDLIBRARY".$SOVERSION ++ ++ # Chaquopy: the Android Gradle plugin will only package libraries whose names end ++ # with ".so". ++ if [ $ac_sys_system != "Linux-android" ]; then ++ INSTSONAME="$LDLIBRARY".$SOVERSION ++ fi ++ + if test "$with_pydebug" != yes + then + PY3LIBRARY=libpython3.so diff --git a/android/patches/sysroot_paths.patch b/android/patches/sysroot_paths.patch new file mode 100644 index 0000000..a649dbc --- /dev/null +++ b/android/patches/sysroot_paths.patch @@ -0,0 +1,14 @@ +--- Python-3.11.0rc1-original/setup.py 2022-08-05 14:45:18.000000000 +0000 ++++ Python-3.11.0rc1/setup.py 2022-09-15 18:11:38.898125188 +0000 +@@ -166,6 +166,11 @@ + for var_name in make_vars: + var = sysconfig.get_config_var(var_name) + if var is not None: ++ # Chaquopy: also detect -L and -I. ++ for path in re.findall(r'-[LI]\s*(\S+)', var): ++ if os.path.isdir(path): ++ dirs.append(path) ++ + m = re.search(r'--sysroot=([^"]\S*|"[^"]+")', var) + if m is not None: + sysroot = m.group(1).strip('"') diff --git a/android/python-android-dart.exclude b/android/python-android-dart.exclude new file mode 100644 index 0000000..42e6b31 --- /dev/null +++ b/android/python-android-dart.exclude @@ -0,0 +1,27 @@ +# Files to exclude for Android distro +# +lib/*.a +lib/*.la +lib/python*/lib-dynload/_test*.so +lib/python*/lib-dynload/_ctypes_test*.so +lib/python*/lib-dynload/xxlimited*.so +lib/python*/lib-dynload/_xxtestfuzz*.so +lib/python*/curses +lib/python*/ensurepip +lib/python*/idlelib +lib/python*/pydoc_data +lib/python*/test +lib/python*/tkinter +lib/python*/turtle* +lib/python*/wsgiref +man +share +*/__pycache__ +# +# +# Other files that we don't need in a mobile distro +lib/python*/config-* +lib/pkgconfig +lib/python*/site-packages +include +bin \ No newline at end of file From 8a77985c6abe6031218aa3454352a211f8425bcf Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 10:46:25 -0700 Subject: [PATCH 10/26] Build python for linux --- .appveyor.yml | 53 +++++++++++++++++++++++++-------- linux/package-for-linux.sh | 16 ++++++++++ linux/python-linux-dart.exclude | 25 ++++++++++++++++ 3 files changed, 81 insertions(+), 13 deletions(-) create mode 100755 linux/package-for-linux.sh create mode 100644 linux/python-linux-dart.exclude diff --git a/.appveyor.yml b/.appveyor.yml index 5c866fa..c48c748 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -8,9 +8,13 @@ environment: secure: 9SKIwc3VSfYJ5IChvNR74rlTF9BMbAfhCGu1/TmYJBMtC6lkY+UDDkZNK7rC9xnQFUxMrNgoo9kNcNAbKbU8XAcrSwkP2H4mX04FI7P+YbxfiWC8nVHhGNxR4LzO+GO0 matrix: - - job_name: Build Python for Android + # - job_name: Build Python for Android + # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c + # NDK_VERSION: r27 + + - job_name: Build Python for Linux APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c - NDK_VERSION: r27 + PYTHON_DIST_RELEASE: 20240909 # - job_name: Build Python for Windows # APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 @@ -20,6 +24,10 @@ matrix: stack: $python_stack +install: +- read ver_maj ver_min < <(echo $PYTHON_VERSION | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/') +- export PYTHON_VERSION_SHORT="$ver_maj.$ver_min" + for: # ====================================== # Build Python for Android @@ -29,10 +37,6 @@ for: only: - job_name: Build Python for Android - install: - - read ver_maj ver_min < <(echo $PYTHON_VERSION | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/') - - export PYTHON_VERSION_SHORT="$ver_maj.$ver_min" - build_script: - cd android @@ -59,6 +63,30 @@ for: release: v$(PYTHON_VERSION_SHORT) artifact: python-android + # ====================================== + # Build Python for Linux + # ====================================== + + - matrix: + only: + - job_name: Build Python for Linux + + build_script: + - cd linux + - ./package-for-linux.sh x86_64 + - ./package-for-linux.sh aarch64 + + # Push all archives to artifacts + - find dist -maxdepth 1 -type f -iname python-linux-*.tar.gz -exec appveyor PushArtifact -DeploymentName python-linux {} \; + + test: off + + deploy: + provider: GitHub + auth_token: $(GITHUB_TOKEN) + release: v$(PYTHON_VERSION_SHORT) + artifact: python-linux + # ====================================== # Build Python for Windows # ====================================== @@ -85,11 +113,10 @@ for: artifacts: - path: windows\python-windows-for-dart-*.zip + name: python-windows - # deploy: - # provider: GitHub - # auth_token: $(GITHUB_TOKEN) - # release: $(APPVEYOR_REPO_TAG_NAME) - # artifact: flet_windows - # on: - # APPVEYOR_REPO_TAG: true \ No newline at end of file + deploy: + provider: GitHub + auth_token: $(GITHUB_TOKEN) + release: v$(PYTHON_VERSION_SHORT) + artifact: python-windows \ No newline at end of file diff --git a/linux/package-for-linux.sh b/linux/package-for-linux.sh new file mode 100755 index 0000000..463edfd --- /dev/null +++ b/linux/package-for-linux.sh @@ -0,0 +1,16 @@ +PYTHON_ARCH=${1:?} + +DIST_FILE=cpython-${PYTHON_VERSION}+${PYTHON_DIST_RELEASE}-${PYTHON_ARCH}_v4-unknown-linux-gnu-install_only.tar.gz +curl -OL https://github.com/indygreg/python-build-standalone/releases/download/${PYTHON_DIST_RELEASE}/${DIST_FILE} +mkdir -p $PYTHON_ARCH/build +tar zxvf $DIST_FILE -C $PYTHON_ARCH/build + +# copy build to dist +mkdir -p $PYTHON_ARCH/dist +rsync -av --exclude-from=python-linux-dart.exclude $PYTHON_ARCH/build/* $PYTHON_ARCH/dist + +# compile lib +python -m compileall -b $PYTHON_ARCH/dist/lib/python3.12 + +# archive +tar -czf python-linux-dart-$PYTHON_VERSION_SHORT-$PYTHON_ARCH.tar.gz -C $PYTHON_ARCH/dist . \ No newline at end of file diff --git a/linux/python-linux-dart.exclude b/linux/python-linux-dart.exclude new file mode 100644 index 0000000..d691871 --- /dev/null +++ b/linux/python-linux-dart.exclude @@ -0,0 +1,25 @@ +# Files to exclude for Linux distro +# +lib/python*/lib-dynload/_test*.so +lib/python*/lib-dynload/_ctypes_test*.so +lib/python*/lib-dynload/xxlimited*.so +lib/python*/lib-dynload/_xxtestfuzz*.so +lib/python*/curses +lib/python*/ensurepip +lib/python*/idlelib +lib/python*/pydoc_data +lib/python*/test +lib/python*/tkinter +lib/python*/turtle* +lib/python*/wsgiref +lib/itcl* +lib/tcl* +lib/thread* +lib/Tix* +lib/tk* +share +*/__pycache__ +lib/python*/config-* +lib/pkgconfig +lib/python*/site-packages +bin \ No newline at end of file From 7b82d579a661ca46cfa46e1cab96724f481a9364 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 10:50:46 -0700 Subject: [PATCH 11/26] Fix download URL --- linux/package-for-linux.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/linux/package-for-linux.sh b/linux/package-for-linux.sh index 463edfd..07fe5fb 100755 --- a/linux/package-for-linux.sh +++ b/linux/package-for-linux.sh @@ -1,13 +1,13 @@ PYTHON_ARCH=${1:?} -DIST_FILE=cpython-${PYTHON_VERSION}+${PYTHON_DIST_RELEASE}-${PYTHON_ARCH}_v4-unknown-linux-gnu-install_only.tar.gz +DIST_FILE=cpython-${PYTHON_VERSION}+${PYTHON_DIST_RELEASE}-${PYTHON_ARCH}-unknown-linux-gnu-install_only.tar.gz curl -OL https://github.com/indygreg/python-build-standalone/releases/download/${PYTHON_DIST_RELEASE}/${DIST_FILE} mkdir -p $PYTHON_ARCH/build tar zxvf $DIST_FILE -C $PYTHON_ARCH/build # copy build to dist mkdir -p $PYTHON_ARCH/dist -rsync -av --exclude-from=python-linux-dart.exclude $PYTHON_ARCH/build/* $PYTHON_ARCH/dist +rsync -av --exclude-from=python-linux-dart.exclude $PYTHON_ARCH/build/python/* $PYTHON_ARCH/dist # compile lib python -m compileall -b $PYTHON_ARCH/dist/lib/python3.12 From dcf2acd129ebec79263f8197f89427393027c2d9 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 10:52:28 -0700 Subject: [PATCH 12/26] Fix find --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index c48c748..0e65f00 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -77,7 +77,7 @@ for: - ./package-for-linux.sh aarch64 # Push all archives to artifacts - - find dist -maxdepth 1 -type f -iname python-linux-*.tar.gz -exec appveyor PushArtifact -DeploymentName python-linux {} \; + - find . -maxdepth 1 -type f -iname python-linux-*.tar.gz -exec appveyor PushArtifact -DeploymentName python-linux {} \; test: off From 1987f2904686bcb80ffe8de1d49a192248a4f8c2 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 10:55:33 -0700 Subject: [PATCH 13/26] ls and find --- .appveyor.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 0e65f00..3fbc5ae 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -77,7 +77,8 @@ for: - ./package-for-linux.sh aarch64 # Push all archives to artifacts - - find . -maxdepth 1 -type f -iname python-linux-*.tar.gz -exec appveyor PushArtifact -DeploymentName python-linux {} \; + - ls + - find . -maxdepth 1 -type f -iname python-linux-dart-*.tar.gz -exec appveyor PushArtifact -DeploymentName python-linux {} \; test: off From 719a0a16ecea1048cc4833347431c5ed87e0dae3 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 10:58:05 -0700 Subject: [PATCH 14/26] quote pattern --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 3fbc5ae..9784a86 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -78,7 +78,7 @@ for: # Push all archives to artifacts - ls - - find . -maxdepth 1 -type f -iname python-linux-dart-*.tar.gz -exec appveyor PushArtifact -DeploymentName python-linux {} \; + - find . -maxdepth 1 -type f -iname "python-linux-dart-*.tar.gz" -exec appveyor PushArtifact -DeploymentName python-linux {} \; test: off From 0fc0a1397203738abfdf1d1f5c43752e58189484 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 11:03:07 -0700 Subject: [PATCH 15/26] Download stripped version --- linux/package-for-linux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/package-for-linux.sh b/linux/package-for-linux.sh index 07fe5fb..13b3543 100755 --- a/linux/package-for-linux.sh +++ b/linux/package-for-linux.sh @@ -1,6 +1,6 @@ PYTHON_ARCH=${1:?} -DIST_FILE=cpython-${PYTHON_VERSION}+${PYTHON_DIST_RELEASE}-${PYTHON_ARCH}-unknown-linux-gnu-install_only.tar.gz +DIST_FILE=cpython-${PYTHON_VERSION}+${PYTHON_DIST_RELEASE}-${PYTHON_ARCH}-unknown-linux-gnu-install_only_stripped.tar.gz curl -OL https://github.com/indygreg/python-build-standalone/releases/download/${PYTHON_DIST_RELEASE}/${DIST_FILE} mkdir -p $PYTHON_ARCH/build tar zxvf $DIST_FILE -C $PYTHON_ARCH/build From b30fe083aa29979139040974aaf6675135a816ca Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 11:07:54 -0700 Subject: [PATCH 16/26] Download v4 --- .appveyor.yml | 4 ++-- linux/package-for-linux.sh | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 9784a86..06ac30d 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -73,8 +73,8 @@ for: build_script: - cd linux - - ./package-for-linux.sh x86_64 - - ./package-for-linux.sh aarch64 + - ./package-for-linux.sh x86_64 "_v4" + - ./package-for-linux.sh aarch64 "" # Push all archives to artifacts - ls diff --git a/linux/package-for-linux.sh b/linux/package-for-linux.sh index 13b3543..7595360 100755 --- a/linux/package-for-linux.sh +++ b/linux/package-for-linux.sh @@ -1,6 +1,7 @@ PYTHON_ARCH=${1:?} +PYTHON_ARCH_VER=${2:?} -DIST_FILE=cpython-${PYTHON_VERSION}+${PYTHON_DIST_RELEASE}-${PYTHON_ARCH}-unknown-linux-gnu-install_only_stripped.tar.gz +DIST_FILE=cpython-${PYTHON_VERSION}+${PYTHON_DIST_RELEASE}-${PYTHON_ARCH}${PYTHON_ARCH_VER}-unknown-linux-gnu-install_only_stripped.tar.gz curl -OL https://github.com/indygreg/python-build-standalone/releases/download/${PYTHON_DIST_RELEASE}/${DIST_FILE} mkdir -p $PYTHON_ARCH/build tar zxvf $DIST_FILE -C $PYTHON_ARCH/build From e4ce4a83e993cdc52faf756914a47a3daf9a0ee8 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 11:10:19 -0700 Subject: [PATCH 17/26] Make optional arg --- linux/package-for-linux.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linux/package-for-linux.sh b/linux/package-for-linux.sh index 7595360..258d384 100755 --- a/linux/package-for-linux.sh +++ b/linux/package-for-linux.sh @@ -1,5 +1,5 @@ PYTHON_ARCH=${1:?} -PYTHON_ARCH_VER=${2:?} +PYTHON_ARCH_VER=${2:-""} DIST_FILE=cpython-${PYTHON_VERSION}+${PYTHON_DIST_RELEASE}-${PYTHON_ARCH}${PYTHON_ARCH_VER}-unknown-linux-gnu-install_only_stripped.tar.gz curl -OL https://github.com/indygreg/python-build-standalone/releases/download/${PYTHON_DIST_RELEASE}/${DIST_FILE} From 881a0633b3eddfdf944ef2f742c1f4fdf892298a Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 11:12:59 -0700 Subject: [PATCH 18/26] Use v3 intel --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 06ac30d..9c8b48e 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -73,7 +73,7 @@ for: build_script: - cd linux - - ./package-for-linux.sh x86_64 "_v4" + - ./package-for-linux.sh x86_64 "_v3" - ./package-for-linux.sh aarch64 "" # Push all archives to artifacts From cc184c84b8a7c4a3d05d6beb2bed12f80f60c56e Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 11:20:47 -0700 Subject: [PATCH 19/26] Build darwin --- .appveyor.yml | 40 +++++++++ darwin/.gitignore | 5 ++ darwin/LICENSE | 19 +++++ darwin/Modules/module.modulemap | 112 +++++++++++++++++++++++++ darwin/README.rst | 4 + darwin/package-ios-for-dart.sh | 71 ++++++++++++++++ darwin/package-macos-for-dart.sh | 45 ++++++++++ darwin/python-darwin-framework.exclude | 13 +++ darwin/python-darwin-stdlib.exclude | 15 ++++ darwin/xcframework_utils.sh | 90 ++++++++++++++++++++ 10 files changed, 414 insertions(+) create mode 100644 darwin/.gitignore create mode 100644 darwin/LICENSE create mode 100644 darwin/Modules/module.modulemap create mode 100644 darwin/README.rst create mode 100755 darwin/package-ios-for-dart.sh create mode 100755 darwin/package-macos-for-dart.sh create mode 100644 darwin/python-darwin-framework.exclude create mode 100644 darwin/python-darwin-stdlib.exclude create mode 100644 darwin/xcframework_utils.sh diff --git a/.appveyor.yml b/.appveyor.yml index 9c8b48e..afdef9b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -8,6 +8,9 @@ environment: secure: 9SKIwc3VSfYJ5IChvNR74rlTF9BMbAfhCGu1/TmYJBMtC6lkY+UDDkZNK7rC9xnQFUxMrNgoo9kNcNAbKbU8XAcrSwkP2H4mX04FI7P+YbxfiWC8nVHhGNxR4LzO+GO0 matrix: + # - job_name: Build Python for iOS and macOS + # APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma + # - job_name: Build Python for Android # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c # NDK_VERSION: r27 @@ -27,8 +30,45 @@ stack: $python_stack install: - read ver_maj ver_min < <(echo $PYTHON_VERSION | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/') - export PYTHON_VERSION_SHORT="$ver_maj.$ver_min" +- python --version for: + # ====================================== + # Build Python for iOS and macOS + # ====================================== + + - matrix: + only: + - job_name: Build Python for iOS and macOS + + build_script: + - cd darwin + + # Build Python for iOS and macOS + - git clone --branch=$PYTHON_VERSION_SHORT https://github.com/beeware/Python-Apple-support.git + - mkdir -p dist + - sh: | + pushd Python-Apple-support + make iOS || exit 1 + tar -czf ../dist/python-ios-mobile-forge-$PYTHON_VERSION_SHORT.tar.gz install support -C . + make macOS || exit 1 + popd + + # Package for Dart + - ./package-ios-for-dart.sh Python-Apple-support $PYTHON_VERSION_SHORT + - ./package-macos-for-dart.sh Python-Apple-support $PYTHON_VERSION_SHORT + + # Push all archives to artifacts + - find dist -maxdepth 1 -type f -iname python-*.tar.gz -exec appveyor PushArtifact -DeploymentName python-darwin {} \; + + test: off + + deploy: + provider: GitHub + auth_token: $(GITHUB_TOKEN) + release: v$(PYTHON_VERSION) + artifact: python-darwin + # ====================================== # Build Python for Android # ====================================== diff --git a/darwin/.gitignore b/darwin/.gitignore new file mode 100644 index 0000000..21778b2 --- /dev/null +++ b/darwin/.gitignore @@ -0,0 +1,5 @@ + +/Python-Apple-support +/dist +/build +.DS_Store \ No newline at end of file diff --git a/darwin/LICENSE b/darwin/LICENSE new file mode 100644 index 0000000..8fc42c2 --- /dev/null +++ b/darwin/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2014-2018 Russell Keith-Magee, Appveyor Systems Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/darwin/Modules/module.modulemap b/darwin/Modules/module.modulemap new file mode 100644 index 0000000..cf58b60 --- /dev/null +++ b/darwin/Modules/module.modulemap @@ -0,0 +1,112 @@ +framework module Python { + umbrella header "Python.h" + export * + exclude header "cpython/frameobject.h" + exclude header "cpython/interpreteridobject.h" + exclude header "cpython/pthread_stubs.h" + exclude header "datetime.h" + exclude header "dynamic_annotations.h" + exclude header "errcode.h" + exclude header "frameobject.h" + exclude header "internal/pycore_abstract.h" + exclude header "internal/pycore_asdl.h" + exclude header "internal/pycore_ast_state.h" + exclude header "internal/pycore_ast.h" + exclude header "internal/pycore_atexit.h" + exclude header "internal/pycore_atomic_funcs.h" + exclude header "internal/pycore_atomic.h" + exclude header "internal/pycore_bitutils.h" + exclude header "internal/pycore_blocks_output_buffer.h" + exclude header "internal/pycore_bytes_methods.h" + exclude header "internal/pycore_bytesobject.h" + exclude header "internal/pycore_call.h" + exclude header "internal/pycore_ceval_state.h" + exclude header "internal/pycore_ceval.h" + exclude header "internal/pycore_code.h" + exclude header "internal/pycore_compile.h" + exclude header "internal/pycore_condvar.h" + exclude header "internal/pycore_context.h" + exclude header "internal/pycore_descrobject.h" + exclude header "internal/pycore_dict_state.h" + exclude header "internal/pycore_dict.h" + exclude header "internal/pycore_dtoa.h" + exclude header "internal/pycore_emscripten_signal.h" + exclude header "internal/pycore_exceptions.h" + exclude header "internal/pycore_faulthandler.h" + exclude header "internal/pycore_fileutils_windows.h" + exclude header "internal/pycore_fileutils.h" + exclude header "internal/pycore_floatobject.h" + exclude header "internal/pycore_flowgraph.h" + exclude header "internal/pycore_format.h" + exclude header "internal/pycore_frame.h" + exclude header "internal/pycore_function.h" + exclude header "internal/pycore_gc.h" + exclude header "internal/pycore_genobject.h" + exclude header "internal/pycore_getopt.h" + exclude header "internal/pycore_gil.h" + exclude header "internal/pycore_global_objects_fini_generated.h" + exclude header "internal/pycore_global_objects.h" + exclude header "internal/pycore_global_strings.h" + exclude header "internal/pycore_hamt.h" + exclude header "internal/pycore_hashtable.h" + exclude header "internal/pycore_import.h" + exclude header "internal/pycore_initconfig.h" + exclude header "internal/pycore_instruments.h" + exclude header "internal/pycore_interp.h" + exclude header "internal/pycore_intrinsics.h" + exclude header "internal/pycore_list.h" + exclude header "internal/pycore_long.h" + exclude header "internal/pycore_memoryobject.h" + exclude header "internal/pycore_moduleobject.h" + exclude header "internal/pycore_namespace.h" + exclude header "internal/pycore_object_state.h" + exclude header "internal/pycore_object.h" + exclude header "internal/pycore_obmalloc_init.h" + exclude header "internal/pycore_obmalloc.h" + exclude header "internal/pycore_opcode_utils.h" + exclude header "internal/pycore_opcode.h" + exclude header "internal/pycore_parser.h" + exclude header "internal/pycore_pathconfig.h" + exclude header "internal/pycore_pyarena.h" + exclude header "internal/pycore_pyerrors.h" + exclude header "internal/pycore_pyhash.h" + exclude header "internal/pycore_pylifecycle.h" + exclude header "internal/pycore_pymath.h" + exclude header "internal/pycore_pymem_init.h" + exclude header "internal/pycore_pymem.h" + exclude header "internal/pycore_pystate.h" + exclude header "internal/pycore_pythread.h" + exclude header "internal/pycore_range.h" + exclude header "internal/pycore_runtime_init_generated.h" + exclude header "internal/pycore_runtime_init.h" + exclude header "internal/pycore_runtime.h" + exclude header "internal/pycore_signal.h" + exclude header "internal/pycore_sliceobject.h" + exclude header "internal/pycore_strhex.h" + exclude header "internal/pycore_structseq.h" + exclude header "internal/pycore_symtable.h" + exclude header "internal/pycore_sysmodule.h" + exclude header "internal/pycore_time.h" + exclude header "internal/pycore_token.h" + exclude header "internal/pycore_traceback.h" + exclude header "internal/pycore_tracemalloc.h" + exclude header "internal/pycore_tuple.h" + exclude header "internal/pycore_typeobject.h" + exclude header "internal/pycore_typevarobject.h" + exclude header "internal/pycore_ucnhash.h" + exclude header "internal/pycore_unicodeobject_generated.h" + exclude header "internal/pycore_unicodeobject.h" + exclude header "internal/pycore_unionobject.h" + exclude header "internal/pycore_warnings.h" + exclude header "interpreteridobject.h" + exclude header "marshal.h" + exclude header "opcode.h" + exclude header "osdefs.h" + exclude header "py_curses.h" + exclude header "pyconfig-arm64.h" + exclude header "pyconfig-x86_64.h" + exclude header "pydtrace.h" + exclude header "pyexpat.h" + exclude header "structmember.h" + exclude header "token.h" +} \ No newline at end of file diff --git a/darwin/README.rst b/darwin/README.rst new file mode 100644 index 0000000..7fd495f --- /dev/null +++ b/darwin/README.rst @@ -0,0 +1,4 @@ +Python Apple Support +==================== + +Building iOS and macOS "support" builds out of https://github.com/beeware/Python-Apple-support to use with Flet. \ No newline at end of file diff --git a/darwin/package-ios-for-dart.sh b/darwin/package-ios-for-dart.sh new file mode 100755 index 0000000..111a615 --- /dev/null +++ b/darwin/package-ios-for-dart.sh @@ -0,0 +1,71 @@ +#!/bin/bash +set -eu + +python_apple_support_root=${1:?} +python_version=${2:?} + +script_dir=$(dirname $(realpath $0)) + +. xcframework_utils.sh + +# build short Python version +read python_version_major python_version_minor < <(echo $python_version | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/') +python_version_short=$python_version_major.$python_version_minor + +# create build directory +build_dir=build/python-$python_version +rm -rf $build_dir +mkdir -p $build_dir +build_dir=$(realpath $build_dir) + +# create dist directory +mkdir -p dist + +frameworks_dir=$build_dir/xcframeworks +python_frameworks_dir=$build_dir/python-xcframeworks +stdlib_dir=$build_dir/python-stdlib +mkdir -p $frameworks_dir +mkdir -p $python_frameworks_dir +mkdir -p $stdlib_dir + +# copy Python.xcframework +rsync -av --exclude-from=$script_dir/python-darwin-framework.exclude $python_apple_support_root/support/$python_version_short/iOS/Python.xcframework $frameworks_dir +cp -r $script_dir/Modules $frameworks_dir/Python.xcframework/ios-arm64/Python.framework +cp -r $script_dir/Modules $frameworks_dir/Python.xcframework/ios-arm64_x86_64-simulator/Python.framework + +# copy stdlibs +for arch in "${archs[@]}"; do + rsync -av --exclude-from=$script_dir/python-darwin-stdlib.exclude $python_apple_support_root/install/iOS/$arch/python-*/lib/python$python_version_short/* $stdlib_dir/$arch +done + +echo "Converting lib-dynload to xcframeworks..." +find "$stdlib_dir/${archs[0]}/lib-dynload" -name "*.$dylib_ext" | while read full_dylib; do + dylib_relative_path=${full_dylib#$stdlib_dir/${archs[0]}/lib-dynload/} + create_xcframework_from_dylibs \ + "$stdlib_dir/${archs[0]}/lib-dynload" \ + "$stdlib_dir/${archs[1]}/lib-dynload" \ + "$stdlib_dir/${archs[2]}/lib-dynload" \ + $dylib_relative_path \ + "Frameworks/serious_python_darwin.framework/python-stdlib/lib-dynload" \ + $python_frameworks_dir + #break # run for one lib only - for tests +done + +mv $stdlib_dir/${archs[0]}/* $stdlib_dir + +# cleanup +for arch in "${archs[@]}"; do + find $stdlib_dir/$arch -name _sysconfigdata__*.py -exec cp {} $stdlib_dir \; + rm -rf $stdlib_dir/$arch +done + +# compile stdlib +cd $stdlib_dir +python -m compileall -b . +find . \( -name '*.so' -or -name "*.$dylib_ext" -or -name '*.py' -or -name '*.typed' \) -type f -delete +rm -rf __pycache__ +rm -rf **/__pycache__ +cd - + +# final archive +tar -czf dist/python-ios-dart-$python_version_short.tar.gz -C $build_dir . \ No newline at end of file diff --git a/darwin/package-macos-for-dart.sh b/darwin/package-macos-for-dart.sh new file mode 100755 index 0000000..81803fb --- /dev/null +++ b/darwin/package-macos-for-dart.sh @@ -0,0 +1,45 @@ +#!/bin/bash +set -eu + +python_apple_support_root=${1:?} +python_version=${2:?} + +script_dir=$(dirname $(realpath $0)) + +# build short Python version +read python_version_major python_version_minor < <(echo $python_version | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/') +python_version_short=$python_version_major.$python_version_minor + +# create build directory +build_dir=build/python-$python_version +rm -rf $build_dir +mkdir -p $build_dir +build_dir=$(realpath $build_dir) + +# create dist directory +mkdir -p dist + +frameworks_dir=$build_dir/xcframeworks +stdlib_dir=$build_dir/python-stdlib +mkdir -p $frameworks_dir +mkdir -p $stdlib_dir + +# copy Python.xcframework +rsync -av --exclude-from=$script_dir/python-darwin-framework.exclude $python_apple_support_root/support/$python_version_short/macOS/Python.xcframework $frameworks_dir +cp -r $script_dir/Modules $frameworks_dir/Python.xcframework/macos-arm64_x86_64/Python.framework +mkdir -p $frameworks_dir/Python.xcframework/macos-arm64_x86_64/Python.framework/Headers +cp -r $python_apple_support_root/support/$python_version_short/macOS/Python.xcframework/macos-arm64_x86_64/Python.framework/Versions/$python_version_short/include/python$python_version_short/* $frameworks_dir/Python.xcframework/macos-arm64_x86_64/Python.framework/Headers + +# copy stdlibs +rsync -av --exclude-from=$script_dir/python-darwin-stdlib.exclude $python_apple_support_root/install/macOS/macosx/python-*/Python.framework/Versions/Current/lib/python$python_version_short/* $stdlib_dir + +# compile stdlib +cd $stdlib_dir +python -m compileall -b . +find . \( -name '*.py' -or -name '*.typed' \) -type f -delete +rm -rf __pycache__ +rm -rf **/__pycache__ +cd - + +# final archive +tar -czf dist/python-macos-dart-$python_version.tar.gz -C $build_dir . \ No newline at end of file diff --git a/darwin/python-darwin-framework.exclude b/darwin/python-darwin-framework.exclude new file mode 100644 index 0000000..5e5a095 --- /dev/null +++ b/darwin/python-darwin-framework.exclude @@ -0,0 +1,13 @@ +ios-arm64/bin +ios-arm64/include +ios-arm64/lib +ios-arm64_x86_64-simulator/bin +ios-arm64_x86_64-simulator/include +ios-arm64_x86_64-simulator/lib +macos-arm64_x86_64/Python.framework/Headers +macos-arm64_x86_64/Python.framework/Versions/*/_CodeSignature +macos-arm64_x86_64/Python.framework/Versions/*/Headers +macos-arm64_x86_64/Python.framework/Versions/*/include +macos-arm64_x86_64/Python.framework/Versions/*/lib +iphoneos +iphonesimulator \ No newline at end of file diff --git a/darwin/python-darwin-stdlib.exclude b/darwin/python-darwin-stdlib.exclude new file mode 100644 index 0000000..5df694e --- /dev/null +++ b/darwin/python-darwin-stdlib.exclude @@ -0,0 +1,15 @@ +lib-dynload/_test*.so +lib-dynload/_ctypes_test*.so +lib-dynload/xxlimited*.so +lib-dynload/_xxtestfuzz*.so +config-* +curses +ensurepip +idlelib +pydoc_data +site-packages +test +tkinter +turtle* +wsgiref +*/__pycache__ \ No newline at end of file diff --git a/darwin/xcframework_utils.sh b/darwin/xcframework_utils.sh new file mode 100644 index 0000000..66b6d94 --- /dev/null +++ b/darwin/xcframework_utils.sh @@ -0,0 +1,90 @@ +archs=("iphoneos.arm64" "iphonesimulator.arm64" "iphonesimulator.x86_64") + +dylib_ext=so + +create_plist() { + name=$1 + identifier=$2 + plist_file=$3 + + cat > $plist_file << PLIST_TEMPLATE + + + + + CFBundleDevelopmentRegion + en + CFBundleName + $name + CFBundleExecutable + $name + CFBundleIdentifier + $identifier + CFBundleInfoDictionaryVersion + 6.0 + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleSupportedPlatforms + + iPhoneOS + + MinimumOSVersion + 12.0 + CFBundleVersion + 1 + + +PLIST_TEMPLATE +} + +# convert lib-dynloads to xcframeworks +create_xcframework_from_dylibs() { + iphone_dir=$1 + simulator_arm64_dir=$2 + simulator_x86_64_dir=$3 + dylib_relative_path=$4 + origin_prefix=$5 + out_dir=$6 + + tmp_dir=$(mktemp -d) + pushd -- "${tmp_dir}" >/dev/null + + echo "Creating framework for $dylib_relative_path" + dylib_without_ext=$(echo $dylib_relative_path | cut -d "." -f 1) + framework=$(echo $dylib_without_ext | tr "/" ".") + framework_identifier=${framework//_/-} + + # creating "iphoneos" framework + fd=iphoneos/$framework.framework + mkdir -p $fd + mv "$iphone_dir/$dylib_relative_path" $fd/$framework + echo "Frameworks/$framework.framework/$framework" > "$iphone_dir/$dylib_without_ext.fwork" + install_name_tool -id @rpath/$framework.framework/$framework $fd/$framework + create_plist $framework "org.python.$framework_identifier" $fd/Info.plist + echo "$origin_prefix/$dylib_without_ext.fwork" > $fd/$framework.origin + + # creating "iphonesimulator" framework + fd=iphonesimulator/$framework.framework + mkdir -p $fd + lipo -create \ + "$simulator_arm64_dir/$dylib_without_ext".*.$dylib_ext \ + "$simulator_x86_64_dir/$dylib_without_ext".*.$dylib_ext \ + -output $fd/$framework + rm "$simulator_arm64_dir/$dylib_without_ext".*.$dylib_ext + rm "$simulator_x86_64_dir/$dylib_without_ext".*.$dylib_ext + install_name_tool -id @rpath/$framework.framework/$framework $fd/$framework + create_plist $framework "org.python.$framework_identifier" $fd/Info.plist + echo "$origin_prefix/$dylib_without_ext.fwork" > $fd/$framework.origin + + # merge frameworks info xcframework + xcodebuild -create-xcframework \ + -framework "iphoneos/$framework.framework" \ + -framework "iphonesimulator/$framework.framework" \ + -output $out_dir/$framework.xcframework + + # cleanup + popd >/dev/null + rm -rf "${tmp_dir}" >/dev/null +} \ No newline at end of file From 915577c6464474be327d092b29aa83d6fd0bb192 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 11:21:02 -0700 Subject: [PATCH 20/26] Compile .py and do not copy originals --- linux/package-for-linux.sh | 6 +++--- linux/python-linux-dart.exclude | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/linux/package-for-linux.sh b/linux/package-for-linux.sh index 258d384..5c29211 100755 --- a/linux/package-for-linux.sh +++ b/linux/package-for-linux.sh @@ -6,12 +6,12 @@ curl -OL https://github.com/indygreg/python-build-standalone/releases/download/$ mkdir -p $PYTHON_ARCH/build tar zxvf $DIST_FILE -C $PYTHON_ARCH/build +# compile lib +python -m compileall -b $PYTHON_ARCH/build/python/lib/python3.12 + # copy build to dist mkdir -p $PYTHON_ARCH/dist rsync -av --exclude-from=python-linux-dart.exclude $PYTHON_ARCH/build/python/* $PYTHON_ARCH/dist -# compile lib -python -m compileall -b $PYTHON_ARCH/dist/lib/python3.12 - # archive tar -czf python-linux-dart-$PYTHON_VERSION_SHORT-$PYTHON_ARCH.tar.gz -C $PYTHON_ARCH/dist . \ No newline at end of file diff --git a/linux/python-linux-dart.exclude b/linux/python-linux-dart.exclude index d691871..fca773a 100644 --- a/linux/python-linux-dart.exclude +++ b/linux/python-linux-dart.exclude @@ -1,5 +1,6 @@ # Files to exclude for Linux distro # +*.py lib/python*/lib-dynload/_test*.so lib/python*/lib-dynload/_ctypes_test*.so lib/python*/lib-dynload/xxlimited*.so From 7f2c4828617bd341ea7d3843d5895ac554ffe6d0 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 11:53:24 -0700 Subject: [PATCH 21/26] Build darwin --- .appveyor.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index afdef9b..ce06d2b 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -8,16 +8,16 @@ environment: secure: 9SKIwc3VSfYJ5IChvNR74rlTF9BMbAfhCGu1/TmYJBMtC6lkY+UDDkZNK7rC9xnQFUxMrNgoo9kNcNAbKbU8XAcrSwkP2H4mX04FI7P+YbxfiWC8nVHhGNxR4LzO+GO0 matrix: - # - job_name: Build Python for iOS and macOS - # APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma + - job_name: Build Python for iOS and macOS + APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma # - job_name: Build Python for Android # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c # NDK_VERSION: r27 - - job_name: Build Python for Linux - APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c - PYTHON_DIST_RELEASE: 20240909 + # - job_name: Build Python for Linux + # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c + # PYTHON_DIST_RELEASE: 20240909 # - job_name: Build Python for Windows # APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 From 0d754bba390fd91b1afaf9b85adec282d830f521 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 11:57:50 -0700 Subject: [PATCH 22/26] Build windows --- .appveyor.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index ce06d2b..97ad571 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -8,8 +8,8 @@ environment: secure: 9SKIwc3VSfYJ5IChvNR74rlTF9BMbAfhCGu1/TmYJBMtC6lkY+UDDkZNK7rC9xnQFUxMrNgoo9kNcNAbKbU8XAcrSwkP2H4mX04FI7P+YbxfiWC8nVHhGNxR4LzO+GO0 matrix: - - job_name: Build Python for iOS and macOS - APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma + # - job_name: Build Python for iOS and macOS + # APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma # - job_name: Build Python for Android # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c @@ -19,8 +19,8 @@ environment: # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c # PYTHON_DIST_RELEASE: 20240909 - # - job_name: Build Python for Windows - # APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + - job_name: Build Python for Windows + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 matrix: fast_finish: true From daa5dd018c644bbd15cef9b61e6ca312ef1c9523 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 12:02:54 -0700 Subject: [PATCH 23/26] set PYTHON_VERSION_SHORT --- .appveyor.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 97ad571..4d3e91c 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -4,6 +4,7 @@ skip_branch_with_pr: true environment: python_stack: python 3.12 PYTHON_VERSION: 3.12.6 + PYTHON_VERSION_SHORT: 3.12 GITHUB_TOKEN: secure: 9SKIwc3VSfYJ5IChvNR74rlTF9BMbAfhCGu1/TmYJBMtC6lkY+UDDkZNK7rC9xnQFUxMrNgoo9kNcNAbKbU8XAcrSwkP2H4mX04FI7P+YbxfiWC8nVHhGNxR4LzO+GO0 @@ -28,8 +29,6 @@ matrix: stack: $python_stack install: -- read ver_maj ver_min < <(echo $PYTHON_VERSION | sed -E 's/^([0-9]+)\.([0-9]+).*/\1 \2/') -- export PYTHON_VERSION_SHORT="$ver_maj.$ver_min" - python --version for: From 3b8298e72f6adc994e237e92a49e4bf3319dd52d Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 12:07:38 -0700 Subject: [PATCH 24/26] Re-build windows with PYTHON_VERSION_SHORT --- .appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.appveyor.yml b/.appveyor.yml index 4d3e91c..8922bd1 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -147,7 +147,7 @@ for: - start /wait python-%PYTHON_VERSION%-amd64.exe /quiet - dir C:\python312-dist - C:\python312-dist\python -m compileall -b C:\python312-dist\Lib - - 7z a -xr@exclude.txt python-windows-for-dart-%PYTHON_VERSION%.zip C:\python312-dist\* + - 7z a -xr@exclude.txt python-windows-for-dart-%PYTHON_VERSION_SHORT%.zip C:\python312-dist\* test: off From 4ee387d97700621991768f004ef5b8226d77a93b Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Fri, 27 Sep 2024 12:34:41 -0700 Subject: [PATCH 25/26] Re-build darwin --- .appveyor.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 8922bd1..6796947 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -9,8 +9,8 @@ environment: secure: 9SKIwc3VSfYJ5IChvNR74rlTF9BMbAfhCGu1/TmYJBMtC6lkY+UDDkZNK7rC9xnQFUxMrNgoo9kNcNAbKbU8XAcrSwkP2H4mX04FI7P+YbxfiWC8nVHhGNxR4LzO+GO0 matrix: - # - job_name: Build Python for iOS and macOS - # APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma + - job_name: Build Python for iOS and macOS + APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma # - job_name: Build Python for Android # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c @@ -20,8 +20,8 @@ environment: # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c # PYTHON_DIST_RELEASE: 20240909 - - job_name: Build Python for Windows - APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + # - job_name: Build Python for Windows + # APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 matrix: fast_finish: true @@ -65,7 +65,7 @@ for: deploy: provider: GitHub auth_token: $(GITHUB_TOKEN) - release: v$(PYTHON_VERSION) + release: v$(PYTHON_VERSION_SHORT) artifact: python-darwin # ====================================== From 5d1250c03d7ade0a497fccff2aaf10447eab3807 Mon Sep 17 00:00:00 2001 From: Feodor Fitsner Date: Mon, 7 Oct 2024 11:36:15 -0700 Subject: [PATCH 26/26] Run all CI jobs --- .appveyor.yml | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/.appveyor.yml b/.appveyor.yml index 6796947..4c53162 100644 --- a/.appveyor.yml +++ b/.appveyor.yml @@ -12,16 +12,16 @@ environment: - job_name: Build Python for iOS and macOS APPVEYOR_BUILD_WORKER_IMAGE: macos-sonoma - # - job_name: Build Python for Android - # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c - # NDK_VERSION: r27 + - job_name: Build Python for Android + APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c + NDK_VERSION: r27 - # - job_name: Build Python for Linux - # APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c - # PYTHON_DIST_RELEASE: 20240909 + - job_name: Build Python for Linux + APPVEYOR_BUILD_WORKER_IMAGE: ubuntu-gce-c + PYTHON_DIST_RELEASE: 20240909 - # - job_name: Build Python for Windows - # APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 + - job_name: Build Python for Windows + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2022 matrix: fast_finish: true