From 05affda20c59b2a06cf6c8c6cc08f04f7065a1dc Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 22 Jul 2025 13:54:18 +0300 Subject: [PATCH] ports: Add python3 port --- ports/python3/build.sh | 25 ++++++++ .../0001-fix-configure-for-banan_os.patch | 60 +++++++++++++++++++ .../patches/0002-rewrite-info-querying.patch | 19 ++++++ .../0003-fix-timeval-declaration.patch | 13 ++++ .../patches/0004-fix-resource-module.patch | 19 ++++++ .../patches/0005-fix-group-module.patch | 17 ++++++ .../patches/0006-fix-select-module.patch | 14 +++++ .../patches/0008-fix-socket-module.patch | 22 +++++++ 8 files changed, 189 insertions(+) create mode 100755 ports/python3/build.sh create mode 100644 ports/python3/patches/0001-fix-configure-for-banan_os.patch create mode 100644 ports/python3/patches/0002-rewrite-info-querying.patch create mode 100644 ports/python3/patches/0003-fix-timeval-declaration.patch create mode 100644 ports/python3/patches/0004-fix-resource-module.patch create mode 100644 ports/python3/patches/0005-fix-group-module.patch create mode 100644 ports/python3/patches/0006-fix-select-module.patch create mode 100644 ports/python3/patches/0008-fix-socket-module.patch diff --git a/ports/python3/build.sh b/ports/python3/build.sh new file mode 100755 index 00000000..4f957174 --- /dev/null +++ b/ports/python3/build.sh @@ -0,0 +1,25 @@ +#!/bin/bash ../install.sh + +NAME='python' +VERSION='3.13.3' +DOWNLOAD_URL="https://www.python.org/ftp/python/$VERSION/Python-$VERSION.tar.xz#40f868bcbdeb8149a3149580bb9bfd407b3321cd48f0be631af955ac92c0e041" +TAR_CONTENT="Python-$VERSION" +DEPENDENCIES=('ncurses' 'zlib' 'openssl') +CONFIG_SUB=('config.sub') +CONFIGURE_OPTIONS=( + "--build=$(uname -m)-pc-linux-gnu" + "--with-build-python=python3.13" + '--without-ensurepip' + '--disable-ipv6' + '--disable-test-modules' + '--enable-shared' + 'ac_cv_file__dev_ptmx=no' + 'ac_cv_file__dev_ptc=no' +) + +pre_configure() { + if ! command -v python3.13 &>/dev/null ; then + echo "You need to have python3.13 installed on your host machine" >&2 + exit 1 + fi +} diff --git a/ports/python3/patches/0001-fix-configure-for-banan_os.patch b/ports/python3/patches/0001-fix-configure-for-banan_os.patch new file mode 100644 index 00000000..c8199864 --- /dev/null +++ b/ports/python3/patches/0001-fix-configure-for-banan_os.patch @@ -0,0 +1,60 @@ +diff -ruN Python-3.13.3/configure Python-3.13.3-banan_os/configure +--- Python-3.13.3/configure 2025-04-08 16:54:08.000000000 +0300 ++++ Python-3.13.3-banan_os/configure 2025-04-19 04:25:20.860260051 +0300 +@@ -4052,6 +4052,9 @@ + *-*-linux*) + ac_sys_system=Linux + ;; ++ *-*-banan_os*) ++ ac_sys_system=banan_os ++ ;; + *-*-cygwin*) + ac_sys_system=Cygwin + ;; +@@ -4500,6 +4503,9 @@ + _host_ident=$host_cpu + esac + ;; ++ *-*-banan_os*) ++ _host_ident=$host_cpu ++ ;; + *-*-cygwin*) + _host_ident= + ;; +@@ -7603,6 +7609,11 @@ + PY3LIBRARY=libpython3.so + fi + ;; ++ banan_os*) ++ LDLIBRARY='libpython$(LDVERSION).so' ++ BLDLIBRARY='-L. -lpython$(LDVERSION)' ++ RUNSHARED=LD_LIBRARY_PATH=`pwd`${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}} ++ ;; + hp*|HP*) + case `uname -m` in + ia64) +@@ -12983,7 +12994,7 @@ + Emscripten*|WASI*) + LDSHARED='$(CC) -shared' + LDCXXSHARED='$(CXX) -shared';; +- Linux*|GNU*|QNX*|VxWorks*|Haiku*) ++ Linux*|GNU*|QNX*|VxWorks*|Haiku*|banan_os*) + LDSHARED='$(CC) -shared' + LDCXXSHARED='$(CXX) -shared';; + FreeBSD*) +@@ -13069,6 +13080,7 @@ + else CCSHARED="+z"; + fi;; + Linux*|GNU*) CCSHARED="-fPIC";; ++ banan_os*) CCSHARED="-fPIC";; + Emscripten*|WASI*) + if test "x$enable_wasm_dynamic_linking" = xyes + then : +@@ -23609,6 +23621,7 @@ + + case $ac_sys_system in + Darwin) ;; ++banan_os) ;; + *) LIBM=-lm + esac + { printf "%s\n" "$as_me:${as_lineno-$LINENO}: checking for --with-libm=STRING" >&5 diff --git a/ports/python3/patches/0002-rewrite-info-querying.patch b/ports/python3/patches/0002-rewrite-info-querying.patch new file mode 100644 index 00000000..3f30e715 --- /dev/null +++ b/ports/python3/patches/0002-rewrite-info-querying.patch @@ -0,0 +1,19 @@ +diff -ruN Python-3.13.3/Objects/mimalloc/prim/unix/prim.c Python-3.13.3-banan_os/Objects/mimalloc/prim/unix/prim.c +--- Python-3.13.3/Objects/mimalloc/prim/unix/prim.c 2025-04-08 16:54:08.000000000 +0300 ++++ Python-3.13.3-banan_os/Objects/mimalloc/prim/unix/prim.c 2025-04-19 02:14:12.417811656 +0300 +@@ -608,10 +608,13 @@ + getrusage(RUSAGE_SELF, &rusage); + pinfo->utime = timeval_secs(&rusage.ru_utime); + pinfo->stime = timeval_secs(&rusage.ru_stime); +-#if !defined(__HAIKU__) ++#if !defined(__HAIKU__) && !defined(__banan_os__) + pinfo->page_faults = rusage.ru_majflt; + #endif +-#if defined(__HAIKU__) ++#if defined(__banan_os__) ++ pinfo->page_faults = 0; ++ pinfo->peak_rss = 0; ++#elif defined(__HAIKU__) + // Haiku does not have (yet?) a way to + // get these stats per process + thread_info tid; diff --git a/ports/python3/patches/0003-fix-timeval-declaration.patch b/ports/python3/patches/0003-fix-timeval-declaration.patch new file mode 100644 index 00000000..4d4d9981 --- /dev/null +++ b/ports/python3/patches/0003-fix-timeval-declaration.patch @@ -0,0 +1,13 @@ +diff -ruN Python-3.13.3/Include/internal/pycore_time.h Python-3.13.3-banan_os/Include/internal/pycore_time.h +--- Python-3.13.3/Include/internal/pycore_time.h 2025-04-08 16:54:08.000000000 +0300 ++++ Python-3.13.3-banan_os/Include/internal/pycore_time.h 2025-04-19 02:27:02.327447295 +0300 +@@ -58,9 +58,7 @@ + #endif + + +-#ifdef __clang__ + struct timeval; +-#endif + + #define _SIZEOF_PYTIME_T 8 + diff --git a/ports/python3/patches/0004-fix-resource-module.patch b/ports/python3/patches/0004-fix-resource-module.patch new file mode 100644 index 00000000..d9341ec6 --- /dev/null +++ b/ports/python3/patches/0004-fix-resource-module.patch @@ -0,0 +1,19 @@ +diff -ruN Python-3.13.3/Modules/resource.c Python-3.13.3-banan_os/Modules/resource.c +--- Python-3.13.3/Modules/resource.c 2025-04-08 16:54:08.000000000 +0300 ++++ Python-3.13.3-banan_os/Modules/resource.c 2025-04-19 02:36:06.945810525 +0300 +@@ -126,6 +126,7 @@ + PyFloat_FromDouble(doubletime(ru.ru_utime))); + PyStructSequence_SetItem(result, 1, + PyFloat_FromDouble(doubletime(ru.ru_stime))); ++#if !defined(__banan_os__) + PyStructSequence_SetItem(result, 2, PyLong_FromLong(ru.ru_maxrss)); + PyStructSequence_SetItem(result, 3, PyLong_FromLong(ru.ru_ixrss)); + PyStructSequence_SetItem(result, 4, PyLong_FromLong(ru.ru_idrss)); +@@ -140,6 +141,7 @@ + PyStructSequence_SetItem(result, 13, PyLong_FromLong(ru.ru_nsignals)); + PyStructSequence_SetItem(result, 14, PyLong_FromLong(ru.ru_nvcsw)); + PyStructSequence_SetItem(result, 15, PyLong_FromLong(ru.ru_nivcsw)); ++#endif + + if (PyErr_Occurred()) { + Py_DECREF(result); diff --git a/ports/python3/patches/0005-fix-group-module.patch b/ports/python3/patches/0005-fix-group-module.patch new file mode 100644 index 00000000..fd071350 --- /dev/null +++ b/ports/python3/patches/0005-fix-group-module.patch @@ -0,0 +1,17 @@ +diff -ruN Python-3.13.3/Modules/grpmodule.c Python-3.13.3-banan_os/Modules/grpmodule.c +--- Python-3.13.3/Modules/grpmodule.c 2025-04-08 16:54:08.000000000 +0300 ++++ Python-3.13.3-banan_os/Modules/grpmodule.c 2025-04-19 02:40:57.658713753 +0300 +@@ -91,9 +91,12 @@ + + #define SET(i,val) PyStructSequence_SetItem(v, i, val) + SET(setIndex++, PyUnicode_DecodeFSDefault(p->gr_name)); ++#if !defined(__banan_os__) + if (p->gr_passwd) + SET(setIndex++, PyUnicode_DecodeFSDefault(p->gr_passwd)); +- else { ++ else ++#endif ++ { + SET(setIndex++, Py_None); + Py_INCREF(Py_None); + } diff --git a/ports/python3/patches/0006-fix-select-module.patch b/ports/python3/patches/0006-fix-select-module.patch new file mode 100644 index 00000000..1c2786a9 --- /dev/null +++ b/ports/python3/patches/0006-fix-select-module.patch @@ -0,0 +1,14 @@ +diff -ruN Python-3.13.3/Modules/selectmodule.c Python-3.13.3-banan_os/Modules/selectmodule.c +--- Python-3.13.3/Modules/selectmodule.c 2025-04-08 16:54:08.000000000 +0300 ++++ Python-3.13.3-banan_os/Modules/selectmodule.c 2025-04-19 02:55:44.944860340 +0300 +@@ -54,6 +54,10 @@ + #include + #endif + ++#if defined(__banan_os__) ++#include ++#endif ++ + #ifdef __sgi + /* This is missing from unistd.h */ + extern void bzero(void *, int); diff --git a/ports/python3/patches/0008-fix-socket-module.patch b/ports/python3/patches/0008-fix-socket-module.patch new file mode 100644 index 00000000..1804247e --- /dev/null +++ b/ports/python3/patches/0008-fix-socket-module.patch @@ -0,0 +1,22 @@ +diff -ruN Python-3.13.3/Modules/socketmodule.c Python-3.13.3-banan_os/Modules/socketmodule.c +--- Python-3.13.3/Modules/socketmodule.c 2025-04-08 16:54:08.000000000 +0300 ++++ Python-3.13.3-banan_os/Modules/socketmodule.c 2025-04-19 03:09:49.117436782 +0300 +@@ -1676,10 +1676,17 @@ + default: + /* If we don't know the address family, don't raise an + exception -- return it as an (int, bytes) tuple. */ ++#if defined(__banan_os__) + return Py_BuildValue("iy#", + addr->sa_family, + addr->sa_data, +- sizeof(addr->sa_data)); ++ sizeof(((struct sockaddr_storage){}).ss_storage)); ++#else ++ return Py_BuildValue("iy#", ++ addr->sa_family, ++ addr->sa_data, ++ sizeof(addr->sa_data)); ++#endif + + } + }