Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
46 changes: 46 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,48 @@

name: Build Android

on:
workflow_dispatch:
push:
branches:
- main
- '3.*'
pull_request:
branches:
- main
- '3.*'

jobs:
build-android:
name: Android (aarch64)
runs-on: macos-14
timeout-minutes: 60
steps:
# Clone python/cpython branch 3.13
- name: Clone python/cpython branch 3.13
run: |
git clone --branch 3.13 --depth 1 https://github.com/python/cpython.git cpython-3.13
ls cpython-3.13

# Build using the Android directory inside cpython-3.13
- name: Build and test
working-directory: ./cpython-3.13/Android
run: ./android.py ci aarch64-linux-android

# Compress output directories from cpython-3.13 root
- name: Zip build artifacts
working-directory: ./cpython-3.13
run: |
zip -r ../android-aarch64-artifacts.zip cross-build || echo "Some directories may not exist"

# Upload the zip as a single artifact
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: android-aarch64-artifacts
path: android-aarch64-artifacts.zip
if-no-files-found: ignore

name: Build Python 3.13 for Termux (aarch64)

on:
Expand Down Expand Up @@ -27,3 +72,4 @@ jobs:
name: python3.13-deb
path: python3.13_3.13.0.deb


115 changes: 115 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,104 @@
#!/usr/bin/env bash
set -e


# 🧹 Set environment
PYTHON_VERSION=3.13.0
PREFIX_USR=$PWD/python-3.13
OPENSSL_DIR=/usr
export cc=clang
export cxx=clang++
# 🧹 Clean previous
rm -rf $PREFIX_USR
mkdir -p $PREFIX_USR

# 📦 Download Python 3.13 if not present
if [ ! -f Python-${PYTHON_VERSION}.tar.xz ]; then
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
fi

# 🗂️ Extract and enter source
rm -rf Python-${PYTHON_VERSION}
tar xf Python-${PYTHON_VERSION}.tar.xz
cd Python-${PYTHON_VERSION}

# ⚡ Max Optimization flags
export CFLAGS="-fPIC -DANDROID -O3 -march=native -mtune=native -fomit-frame-pointer -pipe -flto"
export CXXFLAGS="$CFLAGS"
export LDFLAGS="-Wl,-rpath=/data/data/com.termux/files/usr/lib -flto"
export MAKEFLAGS="-j$(nproc)"
export ax_cv_c_float_words_bigendian=no

# 🧠 Configure with maximum optimizations
./configure \
--prefix=$PREFIX_USR \
--enable-optimizations \
--with-lto \
--enable-shared \
--disable-ipv6 \
--with-openssl=$OPENSSL_DIR \
--disable-test-modules \
ac_cv_file__dev_ptmx=yes \
ac_cv_file__dev_ptc=no \
ac_cv_have_long_long_format=yes \
ac_cv_printf_long_long=yes \
ac_cv_func_lstat_dereferences_slashed_symlink=yes \
ac_cv_func_working_mktime=yes

# 🛠️ Build Python
make

# 📦 Install into PREFIX folder
make install

# 🧹 Clean up
cd ..
echo "✅ Python 3.13 built with max optimizations! Output at: $PREFIX_USR"

# 🎯 Strip binaries (reduce size)
find $PREFIX_USR -type f \( -perm -111 -o -name "*.so" \) -exec strip --strip-unneeded {} +

#####################################
# 📦 Create .deb package 📦
#####################################

echo "📦 Creating DEB package for Termux..."

PKG_NAME="python3.13"
PKG_VERSION="$PYTHON_VERSION"
ARCH="aarch64"
DEB_DIR="$PWD/${PKG_NAME}_$PKG_VERSION"

# 1. Create DEB folder structure
rm -rf $DEB_DIR
mkdir -p $DEB_DIR/DEBIAN
mkdir -p $DEB_DIR/data/data/com.termux/files/usr

# 2. Copy compiled files
cp -a $PREFIX_USR/* $DEB_DIR/data/data/com.termux/files/usr/

# 3. Create control file
cat > $DEB_DIR/DEBIAN/control <<EOF
Package: $PKG_NAME
Version: $PKG_VERSION
Architecture: $ARCH
Maintainer: Cross-compiled by Shoaib Hassan
Description: Highly optimized Python 3.13 cross-compiled for Termux aarch64.
EOF

# 4. Create empty postinst script
cat > $DEB_DIR/DEBIAN/postinst <<EOF

# 🧹 Set environment
PYTHON_VERSION=3.13.0
PREFIX_USR=$PWD/python-3.13
OPENSSL_DIR=/usr
export cc=clang
export cxx=clang++
# 🧹 Clean previous
rm -rf $PREFIX_USR
mkdir -p $PREFIX_USR
=======
PYTHON_VERSION=3.13.0
ARCH=aarch64
PKG_NAME=python3.13
Expand Down Expand Up @@ -30,6 +128,7 @@ fi
rm -rf "$PREFIX_USR" "$DEB_DIR"
mkdir -p "$PREFIX_USR"


# Download Python source
if [ ! -f Python-${PYTHON_VERSION}.tar.xz ]; then
wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tar.xz
Expand Down Expand Up @@ -98,4 +197,20 @@ chmod 0644 "$DEB_DIR/DEBIAN/control"
# Build DEB
dpkg-deb --build "$DEB_DIR"


echo "✅ DEB package created: ${DEB_DIR}.deb"
ash
EOF

# 5. Set correct permissions
chmod 0755 $DEB_DIR/DEBIAN
chmod 0644 $DEB_DIR/DEBIAN/control
chmod 0755 $DEB_DIR/DEBIAN/postinst

# 6. Build .deb package
dpkg-deb --build $DEB_DIR

echo "✅ DEB package created: ${DEB_DIR}.deb"
=======
echo "✅ Done: DEB package created at ${DEB_DIR}.deb"

Loading