Skip to content

Commit

Permalink
python314-devel: add compatibility patch to fix build on macOS <10.12
Browse files Browse the repository at this point in the history
  • Loading branch information
aeiouaeiouaeiouaeiouaeiouaeiou committed Dec 25, 2024
1 parent 237e08d commit e5edddf
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 2 deletions.
12 changes: 10 additions & 2 deletions lang/python314-devel/Portfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem 1.0
PortGroup compiler_blacklist_versions 1.0

name python314-devel

Expand Down Expand Up @@ -38,8 +39,12 @@ if {${os.platform} eq "darwin" && ${os.major} <= 10} {
patch-threadid-older-systems.diff
}

# https://github.com/python/cpython/issues/127897
patchfiles-append patch-hacl-compatibility.diff
# https://github.com/python/cpython/pull/127932
# https://github.com/python/cpython/pull/128165
# using legacysupport portgroup causes an implicit
# declaration of renameat(), investigate this later
patchfiles-append patch-hacl-compatibility.diff \
patch-pylifecycle-compatibility.diff

depends_build path:bin/pkg-config:pkgconfig
depends_lib port:bzip2 \
Expand All @@ -59,6 +64,9 @@ depends_run port:python_select-${pythonVerNoDot} \
port:python3_select-${pythonVerNoDot}

compiler.c_standard 2011
# libintvector.h:230:9: error: unknown type name '__m256i' on macOS < 10.11
compiler.blacklist-append \
{clang < 800}

configure.args --enable-framework=${frameworks_dir} \
--enable-ipv6 \
Expand Down
89 changes: 89 additions & 0 deletions lang/python314-devel/files/patch-pylifecycle-compatibility.diff
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
Backport of https://github.com/python/cpython/pull/128165 with minor modifications to not use legacysupport.
--- Python/pylifecycle.c
+++ Python/pylifecycle.c
@@ -46,8 +46,25 @@

#if defined(__APPLE__)
# include <AvailabilityMacros.h>
+# define TARGET_OS_OSX 1
# include <mach-o/loader.h>
-# include <os/log.h>
+// The os_log unified logging APIs were introduced in macOS 10.12, iOS 10.0,
+// tvOS 10.0, and watchOS 3.0;
+# if defined(TARGET_OS_IPHONE) && TARGET_OS_IPHONE
+# define HAS_APPLE_SYSTEM_LOG 1
+# elif defined(TARGET_OS_OSX) && TARGET_OS_OSX
+# if defined(MAC_OS_X_VERSION_10_12) && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12
+# define HAS_APPLE_SYSTEM_LOG 1
+# else
+# define HAS_APPLE_SYSTEM_LOG 0
+# endif
+# else
+# define HAS_APPLE_SYSTEM_LOG 0
+# endif
+
+# if HAS_APPLE_SYSTEM_LOG
+# include <os/log.h>
+# endif
#endif

#ifdef HAVE_SIGNAL_H
@@ -77,7 +94,7 @@ static PyStatus init_sys_streams(PyThreadState *tstate);
#ifdef __ANDROID__
static PyStatus init_android_streams(PyThreadState *tstate);
#endif
-#if defined(__APPLE__)
+#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
static PyStatus init_apple_streams(PyThreadState *tstate);
#endif
static void wait_for_thread_shutdown(PyThreadState *tstate);
@@ -1262,7 +1279,7 @@ init_interp_main(PyThreadState *tstate)
return status;
}
#endif
-#if defined(__APPLE__)
+#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG
if (config->use_system_logger) {
status = init_apple_streams(tstate);
if (_PyStatus_EXCEPTION(status)) {
@@ -2946,7 +2963,7 @@ init_android_streams(PyThreadState *tstate)

#endif // __ANDROID__

-#if defined(__APPLE__)
+#if defined(__APPLE__) && HAS_APPLE_SYSTEM_LOG

static PyObject *
apple_log_write_impl(PyObject *self, PyObject *args)
@@ -2957,14 +2974,9 @@ apple_log_write_impl(PyObject *self, PyObject *args)
return NULL;
}

- // Call the underlying Apple logging API. The os_log unified logging APIs
- // were introduced in macOS 10.12, iOS 10.0, tvOS 10.0, and watchOS 3.0;
- // this call is a no-op on older versions.
- #if TARGET_OS_IPHONE || (TARGET_OS_OSX && MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12)
// Pass the user-provided text through explicit %s formatting
// to avoid % literals being interpreted as a formatting directive.
os_log_with_type(OS_LOG_DEFAULT, logtype, "%s", text);
- #endif
Py_RETURN_NONE;
}

@@ -2999,7 +3011,6 @@ init_apple_streams(PyThreadState *tstate)
if (result == NULL) {
goto error;
}
-
goto done;

error:
@@ -3013,7 +3024,7 @@ init_apple_streams(PyThreadState *tstate)
return status;
}

-#endif // __APPLE__
+#endif // __APPLE__ && HAS_APPLE_SYSTEM_LOG


static void

0 comments on commit e5edddf

Please sign in to comment.