python3: bump to version 3.13.9

Explicitly disable readline and tkinter modules for host-build.
Host-build will not build if these fail.
  - readline isn't a hard requirement for host-python; some minor lack of
    functionality would be felt, but nothing terrible
  - tkinter is also disabled on the target; but for the host-python we
    don't need it either

Dropped patch: 010-no-ncursesw.patch
  - Since we're disabling readline in the host build

Drop setuptools from python3 - the only reason we kept it there, was
because it was required by pip; pip is still there and seems to install and
work fine without setuptools. There's also a separate setuptools package in
openwrt anyway:
  https://github.com/openwrt/packages/tree/master/lang/python/python-setuptools
Also, Python no longer installs it:
  https://github.com/python/cpython/issues/95299

Drop python3-cgi - 08d5923896
Drop distutils - 0faa0ba240
Drop lib2to3 - ae00b810d1

Drop patch: 0001-Adjust-library-header-paths-for-cross-compilation.patch
  - A lot of stuff has changed regarding cross-compilation; at this point
    it's unclear what we need moving forward.

Drop patch: 006-do-not-add-multiarch-local-paths.patch
  - setup.py went away, so no idea if this is needed anymore

Re-applied: 003-do-not-run-compileall.patch

Drop: 008-distutils-use-python-sysroot.patch
  - Buildroot seems to have also dropped this; this patch is from them

Added: 09-don-t-run-profile-task-during-cross-build.patch
  - For cross_compilation, running the profile-task will not work, it also
    mentions this in a comment, but nobody dared to patch it yet (at least
    in this release (3.13.9)

Re-applied: 026-openssl-feature-flags.patch
  - This could have been dropped completely, but upstream decided to keep
    scrypt on by default; for host-build this fails, because OpenWrt keeps
    libressl

Drop patch: 100-gh-95855-Refactor-platform-triplet-detection-code-GH-107221.patch
  - This was a backport; it probably should have been removed sooner

Signed-off-by: Alexandru Ardelean <alex@shruggie.ro>

wip
This commit is contained in:
Alexandru Ardelean
2024-11-24 10:59:27 +02:00
committed by Hannu Nyman
parent e3a1f5b0b9
commit 97a92f2e7a
17 changed files with 61 additions and 818 deletions

View File

@@ -5,15 +5,12 @@
# See /LICENSE for more information.
#
# Note: keep in sync with setuptools & pip
# Note: keep in sync with pip
PYTHON3_VERSION_MAJOR:=3
PYTHON3_VERSION_MINOR:=11
PYTHON3_VERSION_MICRO:=14
PYTHON3_VERSION_MINOR:=13
PYTHON3_VERSION_MICRO:=9
PYTHON3_VERSION:=$(PYTHON3_VERSION_MAJOR).$(PYTHON3_VERSION_MINOR)
PYTHON3_SETUPTOOLS_PKG_RELEASE:=1
PYTHON3_PIP_PKG_RELEASE:=1
PYTHON3_SETUPTOOLS_VERSION:=79.0.1
PYTHON3_PIP_VERSION:=24.0
PYTHON3_PIP_VERSION:=25.2

View File

@@ -16,9 +16,9 @@ PKG_VERSION:=$(PYTHON3_VERSION).$(PYTHON3_VERSION_MICRO)
PKG_SOURCE:=Python-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=https://www.python.org/ftp/python/$(PKG_VERSION)
PKG_HASH:=8d3ed8ec5c88c1c95f5e558612a725450d2452813ddad5e58fdb1a53b1209b78
PKG_HASH:=ed5ef34cda36cfa2f3a340f07cac7e7814f91c7f3c411f6d3562323a866c5c66
PKG_MAINTAINER:=Jeffery To <jeffery.to@gmail.com>
PKG_MAINTAINER:=Jeffery To <jeffery.to@gmail.com>, Alexandru Ardelean <ardeleanalex@gmail.com>
PKG_LICENSE:=Python-2.0.1 0BSD
PKG_LICENSE_FILES:=LICENSE Doc/copyright.rst Doc/license.rst Modules/_ctypes/darwin/LICENSE Modules/_ctypes/libffi_osx/LICENSE Modules/expat/COPYING
PKG_CPE_ID:=cpe:/a:python:python
@@ -41,7 +41,7 @@ PKG_BUILD_DIR:=$(BUILD_DIR)/Python-$(PKG_VERSION)
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/Python-$(PKG_VERSION)
PKG_BUILD_DEPENDS:=bluez python3/host python-build/host python-installer/host python-wheel/host
HOST_BUILD_DEPENDS:=bzip2/host libffi/host readline/host
HOST_BUILD_DEPENDS:=bzip2/host libffi/host
include $(INCLUDE_DIR)/host-build.mk
include $(INCLUDE_DIR)/package.mk
@@ -244,7 +244,8 @@ PYTHON3_BASE_LIB_FILES:= \
/usr/lib/python$(PYTHON3_VERSION)/os.py \
/usr/lib/python$(PYTHON3_VERSION)/posixpath.py \
/usr/lib/python$(PYTHON3_VERSION)/site.py \
/usr/lib/python$(PYTHON3_VERSION)/sysconfig.py \
/usr/lib/python$(PYTHON3_VERSION)/sysconfig/__init__.py \
/usr/lib/python$(PYTHON3_VERSION)/sysconfig/__main__.py \
/usr/lib/python$(PYTHON3_VERSION)/stat.py
PYTHON3_LIB_FILES_DEL+=$(PYTHON3_BASE_LIB_FILES)
@@ -258,7 +259,6 @@ endef
define Py3Package/python3-light/filespec
+|/usr/lib/python$(PYTHON3_VERSION)
-|/usr/lib/python$(PYTHON3_VERSION)/distutils/cygwinccompiler.py
-|/usr/lib/python$(PYTHON3_VERSION)/idlelib
-|/usr/lib/python$(PYTHON3_VERSION)/tkinter
-|/usr/lib/python$(PYTHON3_VERSION)/turtledemo
@@ -295,6 +295,7 @@ endif
# Bypass configure test
HOST_CONFIGURE_VARS += \
py_cv_module__tkinter=n/a \
ac_cv_working_openssl_hashlib=yes
ifeq ($(HOST_OS),Darwin)
@@ -305,6 +306,7 @@ HOST_MAKE_VARS += \
endif
HOST_CONFIGURE_ARGS += \
--with-readline=no \
--enable-optimizations \
--disable-test-modules \
--with-ensurepip=upgrade \
@@ -320,19 +322,10 @@ HOST_CFLAGS += \
define Host/Configure
$(SED) 's/^ENABLE_USER_SITE = None$$$$/ENABLE_USER_SITE = False/' $(HOST_BUILD_DIR)/Lib/site.py
$(call Host/Configure/Default)
ls $(HOST_BUILD_DIR)/Lib/ensurepip/_bundled/setuptools-$(PYTHON3_SETUPTOOLS_VERSION)-py3-none-any.whl
ls $(HOST_BUILD_DIR)/Lib/ensurepip/_bundled/pip-$(PYTHON3_PIP_VERSION)-py3-none-any.whl
endef
define Host/Install
$(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
rm -rf \
$(HOST_PYTHON3_PKG_DIR)/pkg_resources \
$(HOST_PYTHON3_PKG_DIR)/setuptools \
$(HOST_PYTHON3_PKG_DIR)/setuptools-* \
$(HOST_PYTHON3_PKG_DIR)/.setuptools-patched* \
$(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_*
)
$(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
rm -rf \
$(HOST_PYTHON3_PKG_DIR)/pip \
@@ -341,10 +334,6 @@ define Host/Install
$(HOST_PYTHON3_PKG_DIR)/.pip_installed_*
)
$(call Host/Install/Default)
$(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)),,
$(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-host-setuptools,)
touch $(HOST_PYTHON3_PKG_DIR)/.setuptools_installed_$(PYTHON3_SETUPTOOLS_VERSION)-$(PYTHON3_SETUPTOOLS_PKG_RELEASE)
)
$(if $(wildcard $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)),,
$(call HostPatchDir,$(HOST_PYTHON3_PKG_DIR),./patches-host-pip,)
touch $(HOST_PYTHON3_PKG_DIR)/.pip_installed_$(PYTHON3_PIP_VERSION)-$(PYTHON3_PIP_PKG_RELEASE)

View File

@@ -1,38 +0,0 @@
#
# Copyright (C) 2006-2017 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
define Package/python3-cgi
$(call Package/python3/Default)
TITLE+= cgi module
DEPENDS:=+python3-light +python3-email
endef
define Package/python3-cgitb
$(call Package/python3/Default)
TITLE+= cgitb module
DEPENDS:=+python3-light +python3-cgi +python3-pydoc
endef
define Package/python3-cgi/description
$(call Package/python3/Default/description)
This package contains the cgi module.
endef
define Package/python3-cgitb/description
$(call Package/python3/Default/description)
This package contains the cgitb module.
endef
$(eval $(call Py3BasePackage,python3-cgi, \
/usr/lib/python$(PYTHON3_VERSION)/cgi.py \
))
$(eval $(call Py3BasePackage,python3-cgitb, \
/usr/lib/python$(PYTHON3_VERSION)/cgitb.py \
))

View File

@@ -1,22 +0,0 @@
#
# Copyright (C) 2006-2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
define Package/python3-distutils
$(call Package/python3/Default)
TITLE+= distutils module
DEPENDS:=+python3-light +python3-email
endef
define Package/python3-distutils/description
$(call Package/python3/Default/description)
This package contains the distutils module.
endef
$(eval $(call Py3BasePackage,python3-distutils, \
/usr/lib/python$(PYTHON3_VERSION)/distutils \
))

View File

@@ -1,24 +0,0 @@
#
# Copyright (C) 2006-2016 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
define Package/python3-lib2to3
$(call Package/python3/Default)
TITLE+= lib2to3 module
DEPENDS:=+python3
endef
define Package/python3-lib2to3/description
$(call Package/python3/Default/description)
This package contains the lib2to3 module.
endef
$(eval $(call Py3BasePackage,python3-lib2to3, \
/usr/lib/python$(PYTHON3_VERSION)/lib2to3 \
, \
DO_NOT_ADD_TO_PACKAGE_DEPENDS \
))

View File

@@ -1,18 +1,18 @@
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -2144,6 +2144,7 @@ libinstall: all $(srcdir)/Modules/xxmodu
$(INSTALL_DATA) $(srcdir)/Modules/xxmodule.c \
$(DESTDIR)$(LIBDEST)/distutils/tests ; \
@@ -2569,6 +2569,7 @@ libinstall: all $(srcdir)/Modules/xxmodu
echo "Applying app store compliance patch"; \
patch --force --reject-file "$(abs_builddir)/app-store-compliance.rej" --strip 2 --directory "$(DESTDIR)$(LIBDEST)" --input "$(abs_srcdir)/$(APP_STORE_COMPLIANCE_PATCH)" || true ; \
fi
+ifeq (1,)
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
@ # Build PYC files for the 3 optimization levels (0, 1, 2)
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
-j0 -d $(LIBDEST) -f \
@@ -2171,6 +2172,7 @@ libinstall: all $(srcdir)/Modules/xxmodu
$(PYTHON_FOR_BUILD) -Wi -OO $(DESTDIR)$(LIBDEST)/compileall.py \
-j0 -d $(LIBDEST)/site-packages -f \
@@ -2579,6 +2580,7 @@ libinstall: all $(srcdir)/Modules/xxmodu
$(PYTHON_FOR_BUILD) -Wi $(DESTDIR)$(LIBDEST)/compileall.py \
-o 0 -o 1 -o 2 $(COMPILEALL_OPTS) -d $(LIBDEST)/site-packages -f \
-x badsyntax $(DESTDIR)$(LIBDEST)/site-packages
+endif
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
$(PYTHON_FOR_BUILD) -m lib2to3.pgen2.driver $(DESTDIR)$(LIBDEST)/lib2to3/Grammar.txt
-PYTHONPATH=$(DESTDIR)$(LIBDEST) $(RUNSHARED) \
# bpo-21536: Misc/python-config.sh is generated in the build directory
# from $(srcdir)Misc/python-config.sh.in.

View File

@@ -1,6 +1,6 @@
--- a/Python/initconfig.c
+++ b/Python/initconfig.c
@@ -178,7 +178,7 @@ int Py_NoSiteFlag = 0; /* Suppress 'impo
@@ -326,7 +326,7 @@ int Py_NoSiteFlag = 0; /* Suppress 'impo
int Py_BytesWarningFlag = 0; /* Warn on str(bytes) and str(buffer) */
int Py_FrozenFlag = 0; /* Needed by getpath.c */
int Py_IgnoreEnvironmentFlag = 0; /* e.g. PYTHONPATH, PYTHONHOME */

View File

@@ -1,19 +0,0 @@
--- a/setup.py
+++ b/setup.py
@@ -844,16 +844,9 @@ class PyBuildExt(build_ext):
add_dir_to_list(dir_list, directory)
def configure_compiler(self):
- # Ensure that /usr/local is always used, but the local build
- # directories (i.e. '.' and 'Include') must be first. See issue
- # 10520.
- if not CROSS_COMPILING:
- add_dir_to_list(self.compiler.library_dirs, '/usr/local/lib')
- add_dir_to_list(self.compiler.include_dirs, '/usr/local/include')
# only change this for cross builds for 3.3, issues on Mageia
if CROSS_COMPILING:
self.add_cross_compiling_paths()
- self.add_multiarch_paths()
self.add_ldflags_cppflags()
def init_inc_lib_dirs(self):

View File

@@ -1,60 +0,0 @@
From e359a7a3c4f9e70360a068bef19c95938fdacede Mon Sep 17 00:00:00 2001
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Date: Wed, 23 Dec 2015 11:33:14 +0100
Subject: [PATCH] Adjust library/header paths for cross-compilation
When cross-compiling third-party extensions, the get_python_inc() or
get_python_lib() can be called, to return the path to headers or
libraries. However, they use the sys.prefix of the host Python, which
returns incorrect paths when cross-compiling (paths pointing to host
headers and libraries).
In order to fix this, we introduce the _python_sysroot, _python_prefix
and _python_exec_prefix variables, that allow to override these
values, and get correct header/library paths when cross-compiling
third-party Python modules.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
---
Lib/distutils/command/build_ext.py | 5 ++++-
Lib/sysconfig.py | 15 +++++++++++----
2 files changed, 15 insertions(+), 5 deletions(-)
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -234,7 +234,10 @@ class build_ext(Command):
if (sysconfig.get_config_var('Py_ENABLE_SHARED')):
if not sysconfig.python_build:
# building third party extensions
- self.library_dirs.append(sysconfig.get_config_var('LIBDIR'))
+ libdir = sysconfig.get_config_var('LIBDIR')
+ if "_python_sysroot" in os.environ:
+ libdir = os.environ.get("_python_sysroot") + libdir
+ self.library_dirs.append(libdir)
else:
# building python standard extensions
self.library_dirs.append('.')
--- a/Lib/sysconfig.py
+++ b/Lib/sysconfig.py
@@ -168,10 +168,17 @@ _SCHEME_KEYS = ('stdlib', 'platstdlib',
_PY_VERSION = sys.version.split()[0]
_PY_VERSION_SHORT = f'{sys.version_info[0]}.{sys.version_info[1]}'
_PY_VERSION_SHORT_NO_DOT = f'{sys.version_info[0]}{sys.version_info[1]}'
-_PREFIX = os.path.normpath(sys.prefix)
-_BASE_PREFIX = os.path.normpath(sys.base_prefix)
-_EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
-_BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
+if "_python_sysroot" in os.environ:
+ _sysroot=os.environ.get('_python_sysroot')
+ _PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_prefix'))
+ _EXEC_PREFIX = os.path.normpath(_sysroot + os.environ.get('_python_exec_prefix'))
+ _BASE_PREFIX = _PREFIX
+ _BASE_EXEC_PREFIX = _EXEC_PREFIX
+else:
+ _PREFIX = os.path.normpath(sys.prefix)
+ _EXEC_PREFIX = os.path.normpath(sys.exec_prefix)
+ _BASE_PREFIX = os.path.normpath(sys.base_prefix)
+ _BASE_EXEC_PREFIX = os.path.normpath(sys.base_exec_prefix)
_CONFIG_VARS = None
_USER_BASE = None

View File

@@ -0,0 +1,29 @@
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -746,6 +746,7 @@ profile-gen-stamp: profile-clean-stamp
# Run task with profile generation build to create profile information.
profile-run-stamp:
+ifneq ($(PROFILE_TASK),)
@echo "Running code to generate profile data (this can take a while):"
# First, we need to create a clean build with profile generation
# enabled.
@@ -759,6 +760,7 @@ profile-run-stamp:
# This is an expensive target to build and it does not have proper
# makefile dependency information. So, we create a "stamp" file
# to record its completion and avoid re-running it.
+endif
touch $@
# Compile Python binary with profile guided optimization.
--- a/configure.ac
+++ b/configure.ac
@@ -1905,7 +1905,7 @@ fi
AC_ARG_VAR([PROFILE_TASK], [Python args for PGO generation task])
AC_MSG_CHECKING([PROFILE_TASK])
-if test -z "$PROFILE_TASK"
+if test -z "$PROFILE_TASK" -a "x$cross_compiling" = xno
then
PROFILE_TASK='-m test --pgo --timeout=$(TESTTIMEOUT)'
fi

View File

@@ -1,52 +0,0 @@
--- a/configure.ac
+++ b/configure.ac
@@ -5840,20 +5840,13 @@ if test "$with_readline" != no; then
# library. NOTE: Keep the precedence of listed libraries synchronised
# with setup.py.
AC_MSG_CHECKING([how to link readline libs])
- for py_libtermcap in "" tinfo ncursesw ncurses curses termcap; do
- if test -z "$py_libtermcap"; then
- READLINE_LIBS="-l$LIBREADLINE"
- else
- READLINE_LIBS="-l$LIBREADLINE -l$py_libtermcap"
- fi
- LIBS="$READLINE_LIBS $LIBS_no_readline"
- AC_LINK_IFELSE(
- [AC_LANG_CALL([],[readline])],
- [py_cv_lib_readline=yes])
- if test $py_cv_lib_readline = yes; then
- break
- fi
- done
+ PKG_CHECK_MODULES_STATIC(
+ [READLINE], [readline], [
+ py_cv_lib_readline=yes
+ AC_DEFINE(HAVE_LIBREADLINE, 1,
+ [Define to build the readline module.])
+ ], py_cv_lib_readline=no
+ )
# Uncomment this line if you want to use READLINE_LIBS in Makefile or scripts
#AC_SUBST([READLINE_LIBS])
@@ -5861,8 +5854,6 @@ if test "$with_readline" != no; then
AC_MSG_RESULT([none])
else
AC_MSG_RESULT([$READLINE_LIBS])
- AC_DEFINE(HAVE_LIBREADLINE, 1,
- [Define to build the readline module.])
fi
fi
@@ -6100,12 +6091,6 @@ then
[Define if you have struct stat.st_mtimensec])
fi
-# first curses header check
-ac_save_cppflags="$CPPFLAGS"
-if test "$cross_compiling" = no; then
- CPPFLAGS="$CPPFLAGS -I/usr/include/ncursesw"
-fi
-
AC_CHECK_HEADERS(curses.h ncurses.h)
# On Solaris, term.h requires curses.h

View File

@@ -1,35 +0,0 @@
--- a/configure.ac
+++ b/configure.ac
@@ -3438,10 +3438,6 @@ AS_VAR_IF([have_uuid], [missing], [
AC_DEFINE([HAVE_UUID_GENERATE_TIME_SAFE], [1])
])
])
- AS_VAR_IF([have_uuid], [yes], [
- LIBUUID_CFLAGS=${LIBUUID_CFLAGS-""}
- LIBUUID_LIBS=${LIBUUID_LIBS-"-luuid"}
- ])
])
]
)
@@ -3452,8 +3448,8 @@ AS_VAR_IF([have_uuid], [missing], [
AC_CHECK_HEADERS([uuid/uuid.h], [
AC_CHECK_FUNC([uuid_generate_time], [
have_uuid=yes
- LIBUUID_CFLAGS=${LIBUUID_CFLAGS-""}
- LIBUUID_LIBS=${LIBUUID_LIBS-""}
+ LIBUUID_CFLAGS=${LIBUUID_CFLAGS:""}
+ LIBUUID_LIBS=${LIBUUID_LIBS:""}
])
])
])
--- a/setup.py
+++ b/setup.py
@@ -1118,8 +1118,6 @@ class PyBuildExt(build_ext):
panel_library = 'panel'
if curses_library == 'ncursesw':
curses_defines.append(('HAVE_NCURSESW', '1'))
- if not CROSS_COMPILING:
- curses_includes.append('/usr/include/ncursesw')
# Bug 1464056: If _curses.so links with ncursesw,
# _curses_panel.so must link with panelw.
panel_library = 'panelw'

View File

@@ -5,7 +5,7 @@ https://git.alpinelinux.org/aports/tree/main/python2/musl-find_library.patch
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -92,6 +92,8 @@ elif sys.platform.startswith("aix"):
@@ -101,6 +101,8 @@ elif sys.platform == "android":
elif os.name == "posix":
# Andreas Degert's find functions, using gcc, /sbin/ldconfig, objdump
import re, tempfile
@@ -14,7 +14,7 @@ https://git.alpinelinux.org/aports/tree/main/python2/musl-find_library.patch
def _is_elf(filename):
"Return True if the given file is an ELF file"
@@ -268,6 +270,57 @@ elif os.name == "posix":
@@ -277,6 +279,57 @@ elif os.name == "posix":
def find_library(name, is64 = False):
return _get_soname(_findLib_crle(name, is64) or _findLib_gcc(name))

View File

@@ -1,6 +1,6 @@
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -2189,7 +2189,7 @@ python-config: $(srcdir)/Misc/python-con
@@ -2595,7 +2595,7 @@ python-config: $(srcdir)/Misc/python-con
@ # On Darwin, always use the python version of the script, the shell
@ # version doesn't use the compiler customizations that are provided
@ # in python (_osx_support.py).

View File

@@ -1,53 +1,16 @@
--- a/Modules/_hashopenssl.c
+++ b/Modules/_hashopenssl.c
@@ -45,10 +45,18 @@
@@ -45,7 +45,9 @@
#define MUNCH_SIZE INT_MAX
+#ifdef NID_id_scrypt
#define PY_OPENSSL_HAS_SCRYPT 1
+#endif
+#ifdef NID_sha3_256
#if defined(NID_sha3_224) && defined(NID_sha3_256) && defined(NID_sha3_384) && defined(NID_sha3_512)
#define PY_OPENSSL_HAS_SHA3 1
+#endif
+#ifdef NID_shake256
#define PY_OPENSSL_HAS_SHAKE 1
+#endif
+#ifdef NID_blake2s256
#define PY_OPENSSL_HAS_BLAKE2 1
+#endif
#if OPENSSL_VERSION_NUMBER >= 0x30000000L
#define PY_EVP_MD EVP_MD
@@ -120,19 +128,27 @@ static const py_hashentry_t py_hashes[]
PY_HASH_ENTRY(Py_hash_sha384, "SHA384", SN_sha384, NID_sha384),
PY_HASH_ENTRY(Py_hash_sha512, "SHA512", SN_sha512, NID_sha512),
/* truncated sha2 */
+#ifdef NID_sha512_256
PY_HASH_ENTRY(Py_hash_sha512_224, "SHA512_224", SN_sha512_224, NID_sha512_224),
PY_HASH_ENTRY(Py_hash_sha512_256, "SHA512_256", SN_sha512_256, NID_sha512_256),
+#endif
/* sha3 */
+#ifdef PY_OPENSSL_HAS_SHA3
PY_HASH_ENTRY(Py_hash_sha3_224, NULL, SN_sha3_224, NID_sha3_224),
PY_HASH_ENTRY(Py_hash_sha3_256, NULL, SN_sha3_256, NID_sha3_256),
PY_HASH_ENTRY(Py_hash_sha3_384, NULL, SN_sha3_384, NID_sha3_384),
PY_HASH_ENTRY(Py_hash_sha3_512, NULL, SN_sha3_512, NID_sha3_512),
+#endif
/* sha3 shake */
+#ifdef PY_OPENSSL_HAS_SHAKE
PY_HASH_ENTRY(Py_hash_shake_128, NULL, SN_shake128, NID_shake128),
PY_HASH_ENTRY(Py_hash_shake_256, NULL, SN_shake256, NID_shake256),
+#endif
/* blake2 digest */
+#ifdef PY_OPENSSL_HAS_BLAKE2
PY_HASH_ENTRY(Py_hash_blake2s, "blake2s256", SN_blake2s256, NID_blake2s256),
PY_HASH_ENTRY(Py_hash_blake2b, "blake2b512", SN_blake2b512, NID_blake2b512),
+#endif
PY_HASH_ENTRY(NULL, NULL, NULL, 0),
};
@@ -874,11 +890,15 @@ py_evp_fromname(PyObject *module, const
#endif
@@ -971,11 +973,15 @@ _hashlib_HASH(PyObject *module, const ch
goto exit;
}

View File

@@ -1,15 +1,6 @@
--- a/Modules/_ssl.c
+++ b/Modules/_ssl.c
@@ -4551,7 +4551,7 @@ set_sni_callback(PySSLContext *self, PyO
return 0;
}
-#if OPENSSL_VERSION_NUMBER < 0x30300000L
+#if OPENSSL_VERSION_NUMBER < 0x30300000L && !defined(LIBRESSL_VERSION_NUMBER)
static X509_OBJECT *x509_object_dup(const X509_OBJECT *obj)
{
int ok;
@@ -4624,7 +4624,11 @@ _ssl__SSLContext_cert_store_stats_impl(P
@@ -4827,7 +4827,11 @@ _ssl__SSLContext_cert_store_stats_impl(P
int x509 = 0, crl = 0, ca = 0, i;
store = SSL_CTX_get_cert_store(self->ctx);
@@ -21,7 +12,7 @@
if (objs == NULL) {
PyErr_SetString(PyExc_MemoryError, "failed to query cert store");
return NULL;
@@ -4679,7 +4683,11 @@ _ssl__SSLContext_get_ca_certs_impl(PySSL
@@ -4883,7 +4887,11 @@ _ssl__SSLContext_get_ca_certs_impl(PySSL
}
store = SSL_CTX_get_cert_store(self->ctx);

View File

@@ -1,476 +0,0 @@
From c163d7f0b67a568e9b64eeb9c1cbbaa127818596 Mon Sep 17 00:00:00 2001
From: Jeffery To <jeffery.to@gmail.com>
Date: Thu, 24 Aug 2023 20:22:50 +0800
Subject: [PATCH] gh-95855: Refactor platform triplet detection code, add
detection for MIPS soft float and musl libc (#107221)
- Move platform triplet detection code into Misc/platform_triplet.c
- Refactor MIPS detection, use defined(__mips64) to detect MIPS64
- Compute libc values in separate section
- Add detection for MIPS soft float
- Add detection for musl
musl supports SPE with its soft-float ABI:
https://git.musl-libc.org/cgit/musl/commit/?id=7be59733d71ada3a32a98622507399253f1d5e48
Original patch by Christian Heimes.
Co-authored-by: Christian Heimes <christian@python.org>
Co-authored-by: Erlend E. Aasland <erlend@python.org>
[omit news, changes to configure; adapt for Python 3.11]
Signed-off-by: Jeffery To <jeffery.to@gmail.com>
---
...3-07-25-02-30-00.gh-issue-95855.wA7rAf.rst | 2 +
Misc/platform_triplet.c | 255 ++++++++++++++++++
configure | 192 +------------
configure.ac | 192 +------------
4 files changed, 265 insertions(+), 376 deletions(-)
create mode 100644 Misc/NEWS.d/next/Build/2023-07-25-02-30-00.gh-issue-95855.wA7rAf.rst
create mode 100644 Misc/platform_triplet.c
--- /dev/null
+++ b/Misc/platform_triplet.c
@@ -0,0 +1,255 @@
+/* Detect platform triplet from builtin defines
+ * cc -E Misc/platform_triplet.c | grep '^PLATFORM_TRIPLET=' | tr -d ' '
+ */
+#undef bfin
+#undef cris
+#undef fr30
+#undef linux
+#undef hppa
+#undef hpux
+#undef i386
+#undef mips
+#undef powerpc
+#undef sparc
+#undef unix
+#if defined(__ANDROID__)
+ # Android is not a multiarch system.
+#elif defined(__linux__)
+/*
+ * BEGIN of Linux block
+ */
+// Detect libc (based on config.guess)
+# include <features.h>
+# if defined(__UCLIBC__)
+# error uclibc not supported
+# elif defined(__dietlibc__)
+# error dietlibc not supported
+# elif defined(__GLIBC__)
+# define LIBC gnu
+# define LIBC_X32 gnux32
+# if defined(__ARM_PCS_VFP)
+# define LIBC_ARM gnueabihf
+# else
+# define LIBC_ARM gnueabi
+# endif
+# if defined(__loongarch__)
+# if defined(__loongarch_soft_float)
+# define LIBC_LA gnusf
+# elif defined(__loongarch_single_float)
+# define LIBC_LA gnuf32
+# elif defined(__loongarch_double_float)
+# define LIBC_LA gnu
+# else
+# error unknown loongarch floating-point base abi
+# endif
+# endif
+# if defined(_MIPS_SIM)
+# if defined(__mips_hard_float)
+# if _MIPS_SIM == _ABIO32
+# define LIBC_MIPS gnu
+# elif _MIPS_SIM == _ABIN32
+# define LIBC_MIPS gnuabin32
+# elif _MIPS_SIM == _ABI64
+# define LIBC_MIPS gnuabi64
+# else
+# error unknown mips sim value
+# endif
+# else
+# if _MIPS_SIM == _ABIO32
+# define LIBC_MIPS gnusf
+# elif _MIPS_SIM == _ABIN32
+# define LIBC_MIPS gnuabin32sf
+# elif _MIPS_SIM == _ABI64
+# define LIBC_MIPS gnuabi64sf
+# else
+# error unknown mips sim value
+# endif
+# endif
+# endif
+# if defined(__SPE__)
+# define LIBC_PPC gnuspe
+# else
+# define LIBC_PPC gnu
+# endif
+# else
+// Heuristic to detect musl libc
+# include <stdarg.h>
+# ifdef __DEFINED_va_list
+# define LIBC musl
+# define LIBC_X32 muslx32
+# if defined(__ARM_PCS_VFP)
+# define LIBC_ARM musleabihf
+# else
+# define LIBC_ARM musleabi
+# endif
+# if defined(__loongarch__)
+# if defined(__loongarch_soft_float)
+# define LIBC_LA muslsf
+# elif defined(__loongarch_single_float)
+# define LIBC_LA muslf32
+# elif defined(__loongarch_double_float)
+# define LIBC_LA musl
+# else
+# error unknown loongarch floating-point base abi
+# endif
+# endif
+# if defined(_MIPS_SIM)
+# if defined(__mips_hard_float)
+# if _MIPS_SIM == _ABIO32
+# define LIBC_MIPS musl
+# elif _MIPS_SIM == _ABIN32
+# define LIBC_MIPS musln32
+# elif _MIPS_SIM == _ABI64
+# define LIBC_MIPS musl
+# else
+# error unknown mips sim value
+# endif
+# else
+# if _MIPS_SIM == _ABIO32
+# define LIBC_MIPS muslsf
+# elif _MIPS_SIM == _ABIN32
+# define LIBC_MIPS musln32sf
+# elif _MIPS_SIM == _ABI64
+# define LIBC_MIPS muslsf
+# else
+# error unknown mips sim value
+# endif
+# endif
+# endif
+# if defined(_SOFT_FLOAT) || defined(__NO_FPRS__)
+# define LIBC_PPC muslsf
+# else
+# define LIBC_PPC musl
+# endif
+# else
+# error unknown libc
+# endif
+# endif
+
+# if defined(__x86_64__) && defined(__LP64__)
+PLATFORM_TRIPLET=x86_64-linux-LIBC
+# elif defined(__x86_64__) && defined(__ILP32__)
+PLATFORM_TRIPLET=x86_64-linux-LIBC_X32
+# elif defined(__i386__)
+PLATFORM_TRIPLET=i386-linux-LIBC
+# elif defined(__aarch64__) && defined(__AARCH64EL__)
+# if defined(__ILP32__)
+PLATFORM_TRIPLET=aarch64_ilp32-linux-LIBC
+# else
+PLATFORM_TRIPLET=aarch64-linux-LIBC
+# endif
+# elif defined(__aarch64__) && defined(__AARCH64EB__)
+# if defined(__ILP32__)
+PLATFORM_TRIPLET=aarch64_be_ilp32-linux-LIBC
+# else
+PLATFORM_TRIPLET=aarch64_be-linux-LIBC
+# endif
+# elif defined(__alpha__)
+PLATFORM_TRIPLET=alpha-linux-LIBC
+# elif defined(__ARM_EABI__)
+# if defined(__ARMEL__)
+PLATFORM_TRIPLET=arm-linux-LIBC_ARM
+# else
+PLATFORM_TRIPLET=armeb-linux-LIBC_ARM
+# endif
+# elif defined(__hppa__)
+PLATFORM_TRIPLET=hppa-linux-LIBC
+# elif defined(__ia64__)
+PLATFORM_TRIPLET=ia64-linux-LIBC
+# elif defined(__loongarch__) && defined(__loongarch_lp64)
+PLATFORM_TRIPLET=loongarch64-linux-LIBC_LA
+# elif defined(__m68k__) && !defined(__mcoldfire__)
+PLATFORM_TRIPLET=m68k-linux-LIBC
+# elif defined(__mips__)
+# if defined(__mips_isa_rev) && (__mips_isa_rev >=6)
+# if defined(_MIPSEL) && defined(__mips64)
+PLATFORM_TRIPLET=mipsisa64r6el-linux-LIBC_MIPS
+# elif defined(_MIPSEL)
+PLATFORM_TRIPLET=mipsisa32r6el-linux-LIBC_MIPS
+# elif defined(__mips64)
+PLATFORM_TRIPLET=mipsisa64r6-linux-LIBC_MIPS
+# else
+PLATFORM_TRIPLET=mipsisa32r6-linux-LIBC_MIPS
+# endif
+# else
+# if defined(_MIPSEL) && defined(__mips64)
+PLATFORM_TRIPLET=mips64el-linux-LIBC_MIPS
+# elif defined(_MIPSEL)
+PLATFORM_TRIPLET=mipsel-linux-LIBC_MIPS
+# elif defined(__mips64)
+PLATFORM_TRIPLET=mips64-linux-LIBC_MIPS
+# else
+PLATFORM_TRIPLET=mips-linux-LIBC_MIPS
+# endif
+# endif
+# elif defined(__or1k__)
+PLATFORM_TRIPLET=or1k-linux-LIBC
+# elif defined(__powerpc64__)
+# if defined(__LITTLE_ENDIAN__)
+PLATFORM_TRIPLET=powerpc64le-linux-LIBC
+# else
+PLATFORM_TRIPLET=powerpc64-linux-LIBC
+# endif
+# elif defined(__powerpc__)
+PLATFORM_TRIPLET=powerpc-linux-LIBC_PPC
+# elif defined(__s390x__)
+PLATFORM_TRIPLET=s390x-linux-LIBC
+# elif defined(__s390__)
+PLATFORM_TRIPLET=s390-linux-LIBC
+# elif defined(__sh__) && defined(__LITTLE_ENDIAN__)
+PLATFORM_TRIPLET=sh4-linux-LIBC
+# elif defined(__sparc__) && defined(__arch64__)
+PLATFORM_TRIPLET=sparc64-linux-LIBC
+# elif defined(__sparc__)
+PLATFORM_TRIPLET=sparc-linux-LIBC
+# elif defined(__riscv)
+# if __riscv_xlen == 32
+PLATFORM_TRIPLET=riscv32-linux-LIBC
+# elif __riscv_xlen == 64
+PLATFORM_TRIPLET=riscv64-linux-LIBC
+# else
+# error unknown platform triplet
+# endif
+# else
+# error unknown platform triplet
+# endif
+/*
+ * END of Linux block
+ */
+#elif defined(__FreeBSD_kernel__)
+# if defined(__LP64__)
+PLATFORM_TRIPLET=x86_64-kfreebsd-gnu
+# elif defined(__i386__)
+PLATFORM_TRIPLET=i386-kfreebsd-gnu
+# else
+# error unknown platform triplet
+# endif
+#elif defined(__gnu_hurd__)
+PLATFORM_TRIPLET=i386-gnu
+#elif defined(__APPLE__)
+PLATFORM_TRIPLET=darwin
+#elif defined(__VXWORKS__)
+PLATFORM_TRIPLET=vxworks
+#elif defined(__wasm32__)
+# if defined(__EMSCRIPTEN__)
+PLATFORM_TRIPLET=wasm32-emscripten
+# elif defined(__wasi__)
+# if defined(_REENTRANT)
+PLATFORM_TRIPLET=wasm32-wasi-threads
+# else
+PLATFORM_TRIPLET=wasm32-wasi
+# endif
+# else
+# error unknown wasm32 platform
+# endif
+#elif defined(__wasm64__)
+# if defined(__EMSCRIPTEN__)
+PLATFORM_TRIPLET=wasm64-emscripten
+# elif defined(__wasi__)
+PLATFORM_TRIPLET=wasm64-wasi
+# else
+# error unknown wasm64 platform
+# endif
+#else
+# error unknown platform triplet
+#endif
--- a/configure.ac
+++ b/configure.ac
@@ -925,180 +925,14 @@ fi
AC_MSG_CHECKING([for the platform triplet based on compiler characteristics])
-cat > conftest.c <<EOF
-#undef bfin
-#undef cris
-#undef fr30
-#undef linux
-#undef hppa
-#undef hpux
-#undef i386
-#undef mips
-#undef powerpc
-#undef sparc
-#undef unix
-#if defined(__ANDROID__)
- # Android is not a multiarch system.
-#elif defined(__linux__)
-# if defined(__x86_64__) && defined(__LP64__)
- x86_64-linux-gnu
-# elif defined(__x86_64__) && defined(__ILP32__)
- x86_64-linux-gnux32
-# elif defined(__i386__)
- i386-linux-gnu
-# elif defined(__aarch64__) && defined(__AARCH64EL__)
-# if defined(__ILP32__)
- aarch64_ilp32-linux-gnu
-# else
- aarch64-linux-gnu
-# endif
-# elif defined(__aarch64__) && defined(__AARCH64EB__)
-# if defined(__ILP32__)
- aarch64_be_ilp32-linux-gnu
-# else
- aarch64_be-linux-gnu
-# endif
-# elif defined(__alpha__)
- alpha-linux-gnu
-# elif defined(__ARM_EABI__) && defined(__ARM_PCS_VFP)
-# if defined(__ARMEL__)
- arm-linux-gnueabihf
-# else
- armeb-linux-gnueabihf
-# endif
-# elif defined(__ARM_EABI__) && !defined(__ARM_PCS_VFP)
-# if defined(__ARMEL__)
- arm-linux-gnueabi
-# else
- armeb-linux-gnueabi
-# endif
-# elif defined(__hppa__)
- hppa-linux-gnu
-# elif defined(__ia64__)
- ia64-linux-gnu
-# elif defined(__m68k__) && !defined(__mcoldfire__)
- m68k-linux-gnu
-# elif defined(__mips_hard_float) && defined(__mips_isa_rev) && (__mips_isa_rev >=6) && defined(_MIPSEL)
-# if _MIPS_SIM == _ABIO32
- mipsisa32r6el-linux-gnu
-# elif _MIPS_SIM == _ABIN32
- mipsisa64r6el-linux-gnuabin32
-# elif _MIPS_SIM == _ABI64
- mipsisa64r6el-linux-gnuabi64
-# else
-# error unknown platform triplet
-# endif
-# elif defined(__mips_hard_float) && defined(__mips_isa_rev) && (__mips_isa_rev >=6)
-# if _MIPS_SIM == _ABIO32
- mipsisa32r6-linux-gnu
-# elif _MIPS_SIM == _ABIN32
- mipsisa64r6-linux-gnuabin32
-# elif _MIPS_SIM == _ABI64
- mipsisa64r6-linux-gnuabi64
-# else
-# error unknown platform triplet
-# endif
-# elif defined(__mips_hard_float) && defined(_MIPSEL)
-# if _MIPS_SIM == _ABIO32
- mipsel-linux-gnu
-# elif _MIPS_SIM == _ABIN32
- mips64el-linux-gnuabin32
-# elif _MIPS_SIM == _ABI64
- mips64el-linux-gnuabi64
-# else
-# error unknown platform triplet
-# endif
-# elif defined(__mips_hard_float)
-# if _MIPS_SIM == _ABIO32
- mips-linux-gnu
-# elif _MIPS_SIM == _ABIN32
- mips64-linux-gnuabin32
-# elif _MIPS_SIM == _ABI64
- mips64-linux-gnuabi64
-# else
-# error unknown platform triplet
-# endif
-# elif defined(__or1k__)
- or1k-linux-gnu
-# elif defined(__powerpc__) && defined(__SPE__)
- powerpc-linux-gnuspe
-# elif defined(__powerpc64__)
-# if defined(__LITTLE_ENDIAN__)
- powerpc64le-linux-gnu
-# else
- powerpc64-linux-gnu
-# endif
-# elif defined(__powerpc__)
- powerpc-linux-gnu
-# elif defined(__s390x__)
- s390x-linux-gnu
-# elif defined(__s390__)
- s390-linux-gnu
-# elif defined(__sh__) && defined(__LITTLE_ENDIAN__)
- sh4-linux-gnu
-# elif defined(__sparc__) && defined(__arch64__)
- sparc64-linux-gnu
-# elif defined(__sparc__)
- sparc-linux-gnu
-# elif defined(__riscv)
-# if __riscv_xlen == 32
- riscv32-linux-gnu
-# elif __riscv_xlen == 64
- riscv64-linux-gnu
-# else
-# error unknown platform triplet
-# endif
-# else
-# error unknown platform triplet
-# endif
-#elif defined(__FreeBSD_kernel__)
-# if defined(__LP64__)
- x86_64-kfreebsd-gnu
-# elif defined(__i386__)
- i386-kfreebsd-gnu
-# else
-# error unknown platform triplet
-# endif
-#elif defined(__gnu_hurd__)
- i386-gnu
-#elif defined(__APPLE__)
- darwin
-#elif defined(__VXWORKS__)
- vxworks
-#elif defined(__wasm32__)
-# if defined(__EMSCRIPTEN__)
- wasm32-emscripten
-# elif defined(__wasi__)
- wasm32-wasi
-# else
-# error unknown wasm32 platform
-# endif
-#elif defined(__wasm64__)
-# if defined(__EMSCRIPTEN__)
- wasm64-emscripten
-# elif defined(__wasi__)
- wasm64-wasi
-# else
-# error unknown wasm64 platform
-# endif
-#else
-# error unknown platform triplet
-#endif
-
-EOF
-
-if $CPP $CPPFLAGS conftest.c >conftest.out 2>/dev/null; then
- PLATFORM_TRIPLET=`grep -v '^#' conftest.out | grep -v '^ *$' | tr -d ' '`
- case "$build_os" in
- linux-musl*)
- PLATFORM_TRIPLET=`echo "$PLATFORM_TRIPLET" | sed 's/linux-gnu/linux-musl/'`
- ;;
- esac
+if $CPP $CPPFLAGS $srcdir/Misc/platform_triplet.c >conftest.out 2>/dev/null; then
+ PLATFORM_TRIPLET=`grep '^PLATFORM_TRIPLET=' conftest.out | tr -d ' '`
+ PLATFORM_TRIPLET="${PLATFORM_TRIPLET@%:@PLATFORM_TRIPLET=}"
AC_MSG_RESULT([$PLATFORM_TRIPLET])
else
AC_MSG_RESULT([none])
fi
-rm -f conftest.c conftest.out
+rm -f conftest.out
AC_MSG_CHECKING([for multiarch])
AS_CASE([$ac_sys_system],