1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 15:28:11 +00:00

Ports: Add Python 3.9

The current version of our Python port (3.6.0) is over four years old by
now and has (or had, I haven't actually tried it in a while) some
limitations - time for an upgrade! The latest Python release is 3.9.1,
so I used that version. It's a from-scratch port, no patches are taken
from the previous port to ensure the smallest possible amount of code is
patched. The BuildPython.sh script is useful so I kept it, with some
tweaks. I added a short document explaining each patch to ease judging
their underlying problem and necessity in the future.

Compared to the old Python port, this one does support both the time
module as well as threading (at least _thread) just fine. Importing
modules written in C (everything in /usr/local/lib/python3.9/lib-dynload)
currently asserts in Serenity's dynamic loader, which is unfortunate but
probably solvable. Possibly related to #4642. I didn't try building
Python statically, which might be one possibility to circumvent this
issue.

I also renamed the directory to just "python3", which is analogous to
the Python 3.x package most Linux distributions provide. That implicitly
means that we likely will not support multiple versions of the Python
port at any given time, but again, neither do many other systems by
default. Recent versions are usually backwards compatible anyway though,
so having the latest shouldn't be a problem.
On the other hand bumping the version should now be be as simple as
updating the variables in version.sh, given that no new patches are
required.

These core modules to currently not build - I chose to ignore that for
now rather than adding more patches to make them work somehow, which
means they're fully unavailable. This should probably be fixed in
Serenity itself.

    _ctypes, _decimal, _socket, mmap, resource, termios

These optional modules requiring 3rd-party dependencies do currently not
build (even with depends="ncurses openssl zlib"). Especially the absence
of a readline port makes the REPL a bit painful to use. :^)

    _bz2, _curses, _curses_panel, _dbm, _gdbm, _hashlib, _lzma, _sqlite3,
    _ssl, _tkinter, _uuid, nis, ossaudiodev, readline, spwd, zlib

I did some work on LibC and LibM beforehand to add at least stubs of
missing required functions, it still encounters an ASSERT_NOT_REACHED()
/ TODO() every now and then, notably frexp() (implementations of that
can be found online easily if you want to get that working right now).
But then again that's our fault and not this port's. :^)
This commit is contained in:
Linus Groh 2021-01-18 20:26:26 +01:00 committed by Andreas Kling
parent c46056122a
commit 39af1f8519
20 changed files with 277 additions and 603 deletions

View file

@ -1,62 +1,51 @@
#!/bin/bash
#!/usr/bin/env bash
set -e
# This file will need to be run in bash, for now.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "$DIR"
ARCH=${ARCH:-"i686"}
TARGET="$ARCH-pc-serenity"
PREFIX="$DIR/Local/$ARCH"
BUILD=$(realpath "$DIR/../Build")
SYSROOT="$BUILD/Root"
PREFIX_DIR="$DIR/Local/$ARCH"
BUILD_DIR="$DIR/Build/$ARCH"
TARBALLS_DIR="$DIR/Tarballs"
source "$DIR/../Ports/python-3.6/version.sh"
source "$DIR/../Ports/python3/version.sh"
echo PYTHON_VERSION is "$PYTHON_VERSION"
echo PYTHON_URL is "$PYTHON_URL"
mkdir -p "${TARBALLS_DIR}"
echo PREFIX is "$PREFIX"
echo SYSROOT is "$SYSROOT"
mkdir -p "$DIR/Tarballs"
pushd "$DIR/Tarballs"
if [ ! -e "$PYTHON_ARCHIVE" ]; then
curl -O "$PYTHON_URL"
pushd "${TARBALLS_DIR}"
if [ ! -e "${PYTHON_ARCHIVE}" ]; then
echo "Downloading Python from ${PYTHON_ARCHIVE_URL}..."
curl -O "${PYTHON_ARCHIVE_URL}"
else
echo "Skipped downloading Python-$PYTHON_VERSION"
echo "${PYTHON_ARCHIVE} already exists, not downloading archive"
fi
md5="$(md5sum $PYTHON_ARCHIVE | cut -f1 -d' ')"
echo "python md5='$md5'"
if [ "$md5" != "$PYTHON_MD5SUM" ] ; then
echo "python md5 sum mismatching, please run script again."
rm $PYTHON_ARCHIVE
if ! md5sum --status -c <(echo "${PYTHON_ARCHIVE_MD5SUM}" "${PYTHON_ARCHIVE}"); then
echo "Python archive MD5 sum mismatch, please run script again"
rm -f "${PYTHON_ARCHIVE}"
exit 1
fi
if [ ! -d "Python-$PYTHON_VERSION" ]; then
echo "Extracting python..."
tar -xf "$PYTHON_ARCHIVE"
if [ ! -d "Python-${PYTHON_VERSION}" ]; then
echo "Extracting ${PYTHON_ARCHIVE}..."
tar -xf "${PYTHON_ARCHIVE}"
else
echo "Skipped extracting python"
echo "Python-${PYTHON_VERSION} already exists, not extracting archive"
fi
popd
mkdir -p "$PREFIX"
mkdir -p "$DIR/Build/$ARCH/python"
if [ -z "$MAKEJOBS" ]; then
MAKEJOBS=$(nproc)
fi
pushd "$DIR/Build/$ARCH"
pushd python
"$DIR"/Tarballs/Python-$PYTHON_VERSION/configure --prefix="$PREFIX" || exit 1
make -j "$MAKEJOBS" || exit 1
make install || exit 1
popd
mkdir -p "${PREFIX_DIR}"
mkdir -p "${BUILD_DIR}/python"
pushd "${BUILD_DIR}/python"
"${TARBALLS_DIR}"/Python-"${PYTHON_VERSION}"/configure --prefix="${PREFIX_DIR}"
make -j "${MAKEJOBS}"
make install
popd