Skip to content
This repository has been archived by the owner on Feb 24, 2023. It is now read-only.

Commit

Permalink
Misc improvements for building scripts
Browse files Browse the repository at this point in the history
* Switch to a tagged version. Preparation for stable versions (#29)
    * Switches to official Python docker images
* Fixes for cross-distro compatibility (#30)
* Update OpenSSL to 1.1.1g
  • Loading branch information
yan12125 committed May 15, 2020
1 parent 301c30d commit 49f8d3f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 29 deletions.
5 changes: 2 additions & 3 deletions Android/build_deps.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import shlex
import logging
import os
import re
import subprocess
from typing import List
import sys

from util import ARCHITECTURES, BASE, SYSROOT, env_vars, ndk_unified_toolchain, parse_args

Expand Down Expand Up @@ -80,7 +79,7 @@ class NCurses(Package):
configure_args = ['--without-ada', '--enable-widec', '--without-debug', '--without-cxx-binding', '--disable-stripping']

class OpenSSL(Package):
source = 'https://www.openssl.org/source/openssl-1.1.1f.tar.gz'
source = 'https://www.openssl.org/source/openssl-1.1.1g.tar.gz'

def configure(self):
# OpenSSL handles NDK internal paths by itself
Expand Down
2 changes: 1 addition & 1 deletion Android/configure.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import os

from util import ARCHITECTURES, env_vars, parse_args
Expand Down
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
Python 3 Android
================

This is an experimental set of build scripts that will cross-compile the latest Python 3 git master for an Android device.
This is an experimental set of build scripts that will cross-compile Python 3.9.0a6 for an Android device.

Prerequisites
-------------

Building requires:

1. Linux. This project might work on other Unix-like systems but no guarantee.
2. Android NDK r21 installed and environment variable ``$ANDROID_NDK`` points to its root directory. Older NDK may not work and NDK <= r18 is known to break.
3. git and python3.9 in $PATH. It's recommended to use the latest git-master to build python3.9. Here are some ways to install the python3.9:
* For Arch Linux users, install [python-git](https://aur.archlinux.org/packages/python-git) package from AUR
* For other users, install 3.9 from [pyenv](https://github.com/yyuu/pyenv)
1. Linux. This project might work on other systems supported by NDK but no guarantee.
2. Android NDK r21 installed and environment variable ``$ANDROID_NDK`` points to its root directory. Older NDK may not work and NDK <= r18 is known to be incompatible.
3. `python3.9` binary from Python 3.9.0a6 on the building host. It's recommended to use exactly that Python version, which can be installed via [pyenv](https://github.com/yyuu/pyenv). Don't forget to check that `python3.9` is available in $PATH.

Running requires:

Expand Down
24 changes: 19 additions & 5 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,30 @@
#!/bin/sh
#!/bin/bash

set -e
set -x

THIS_DIR="$PWD"

PYVER=3.9.0a6
PYVER_SHORT=3.9.0
SRCDIR=src/Python-$PYVER

COMMON_ARGS="--arch ${ARCH:-arm} --api ${ANDROID_API:-21}"

[ -d src/cpython ] || git clone https://github.com/python/cpython src/cpython
if [ ! -d $SRCDIR ]; then
mkdir -p src
pushd src
curl -vLO https://www.python.org/ftp/python/$PYVER_SHORT/Python-$PYVER.tar.xz
tar xf Python-$PYVER.tar.xz
popd
fi

cp -r Android src/cpython/
pushd src/cpython
cp -r Android $SRCDIR
pushd $SRCDIR
./Android/build_deps.py $COMMON_ARGS
./Android/configure.py $COMMON_ARGS --prefix=/usr
make
make install DESTDIR="$THIS_DIR/build"
popd
cp -r src/cpython/Android/sysroot/usr/share/terminfo build/usr/share/
cp -r $SRCDIR/Android/sysroot/usr/share/terminfo build/usr/share/
cp devscripts/env.sh build/
5 changes: 2 additions & 3 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
#!/bin/sh
[ -d src/cpython ] && pushd src/cpython && git clean -dfx && git checkout && popd
rm -rf build
#!/bin/bash
rm -rf src/* build
22 changes: 11 additions & 11 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FROM archlinux/base
FROM python:3.9.0a6-buster

# Need to reinitialize pacman keyring; see https://github.com/archlinux/archlinux-docker/issues/18
RUN echo 'Server = https://mirror.pkgbuild.com/$repo/os/$arch' > /etc/pacman.d/mirrorlist && \
echo $'[archlinuxcn]\nServer = https://repo.archlinuxcn.org/$arch' >> /etc/pacman.conf && \
pacman-key --init && pacman-key --populate archlinux && \
pacman -Syu --noconfirm && \
pacman -S --noconfirm archlinuxcn-keyring && \
pacman -S --noconfirm --needed android-ndk autoconf automake cmake gawk gettext git gcc make patch pkgconf python python-git which
ARG NDK_VER=r21b

RUN apt-get update -y && \
apt-get install -y autoconf automake cmake gawk gettext git gcc make patch pkg-config

ADD https://dl.google.com/android/repository/android-ndk-${NDK_VER}-linux-x86_64.zip /

RUN unzip android-ndk-${NDK_VER}-linux-x86_64.zip

WORKDIR /python3-android
# Set $ANDROID_NDK manually as /etc/profile.d/*.sh are not sourced by CMD
ENV ANDROID_NDK=/opt/android-ndk
ENV ANDROID_NDK=/android-ndk-${NDK_VER}

CMD ["bash", "/python3-android/build.sh"]
CMD ["/python3-android/build.sh"]

0 comments on commit 49f8d3f

Please # to comment.