Skip to content

Commit

Permalink
Tweaks to fix tvOS and watchOS build and usage of libFFI.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Feb 13, 2021
1 parent 0f2d634 commit 62bfe8d
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 46 deletions.
22 changes: 3 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -290,23 +290,7 @@ $$(XZ_DIR-$1)/src/liblzma/.libs/liblzma.a: $$(XZ_DIR-$1)/Makefile

# No need to build libFFI on macOS
ifneq ($2,macOS)

# libFFI has it's own internal build directories for each Apple platform
ifeq ($$(ARCH-$1),x86_64)
LIBFFI_BUILD_DIR-$1=build_iphonesimulator-x86_64
else ifeq ($$(ARCH-$1),i386)
LIBFFI_BUILD_DIR-$1=build_iphonesimulator-i386
else ifeq ($$(ARCH-$1),arm64)
LIBFFI_BUILD_DIR-$1=build_iphoneos-arm64
else ifeq ($$(ARCH-$1),armv7)
LIBFFI_BUILD_DIR-$1=build_iphoneos-armv7
else ifeq ($$(ARCH-$1),armv7k)
LIBFFI_BUILD_DIR-$1=build_iphoneos-armv7
else
# This is a canary - it should never occur, so if you see it,
# you've got a problem.
LIBFFI_BUILD_DIR-$1=build_other
endif
LIBFFI_BUILD_DIR-$1=build_$$(SDK-$1)-$$(ARCH-$1)

# Build LibFFI
$$(LIBFFI_DIR-$1)/libffi.$1.a: $$(LIBFFI_DIR-$1)/darwin_common
Expand Down Expand Up @@ -492,15 +476,15 @@ $$(LIBFFI_DIR-$1)/darwin_common: downloads/libffi-$(LIBFFI_VERSION).tgz
# presumably be in libffi 3.4 or whatever comes next)
cd $$(LIBFFI_DIR-$1) && patch -p1 < $(PROJECT_DIR)/patch/libffi/libffi.patch
# Configure the build
cd $$(LIBFFI_DIR-$1) && python generate-darwin-source-and-headers.py --only-ios
cd $$(LIBFFI_DIR-$1) && python generate-darwin-source-and-headers.py --only-$(shell echo $1 | tr '[:upper:]' '[:lower:]')

$$(LIBFFI_FRAMEWORK-$1): $$(LIBFFI_DIR-$1)/libffi.a
# Create framework directory structure
mkdir -p $$(LIBFFI_FRAMEWORK-$1)

# Copy the headers.
cp -f -r $$(LIBFFI_DIR-$1)/darwin_common/include $$(LIBFFI_FRAMEWORK-$1)/Headers
cp -f -r $$(LIBFFI_DIR-$1)/darwin_ios/include/* $$(LIBFFI_FRAMEWORK-$1)/Headers
cp -f -r $$(LIBFFI_DIR-$1)/darwin_$(shell echo $1 | tr '[:upper:]' '[:lower:]')/include/* $$(LIBFFI_FRAMEWORK-$1)/Headers

# Create the fat library
xcrun libtool -no_warning_for_no_symbols -static \
Expand Down
98 changes: 80 additions & 18 deletions patch/Python/Python.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2681,15 +2681,30 @@ index 4aa7e6559a..511d77024c 100644
sin(pi*x), giving accurate results for all finite x (especially x
integral or close to an integer). This is here for use in the
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 12f72f525f..a2355bf93f 100644
index 12f72f525f..ec487c6d0e 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -56,6 +56,28 @@
@@ -56,6 +56,8 @@
*/
#if defined(__APPLE__)

+#include "TargetConditionals.h"
+
#if defined(__has_builtin) && __has_builtin(__builtin_available)
# define HAVE_FSTATAT_RUNTIME __builtin_available(macOS 10.10, iOS 8.0, *)
# define HAVE_FACCESSAT_RUNTIME __builtin_available(macOS 10.10, iOS 8.0, *)
@@ -169,7 +171,6 @@
disguised Unix interface). Refer to the library manual and\n\
corresponding Unix manual entries for more information on calls.");

-
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
@@ -326,6 +327,26 @@
# endif /* _MSC_VER */
#endif /* ! __WATCOMC__ || __QNX__ */

+// iOS/tvOS/watchOS *define* a number of POSIX functions, but you can't use them
+// because iOS isn't a conventional multiprocess environment.
+#if TARGET_OS_IPHONE
Expand All @@ -2710,18 +2725,65 @@ index 12f72f525f..a2355bf93f 100644
+# undef HAVE_WAITPID
+#endif
+
#if defined(__has_builtin) && __has_builtin(__builtin_available)
# define HAVE_FSTATAT_RUNTIME __builtin_available(macOS 10.10, iOS 8.0, *)
# define HAVE_FACCESSAT_RUNTIME __builtin_available(macOS 10.10, iOS 8.0, *)
@@ -169,7 +191,6 @@
disguised Unix interface). Refer to the library manual and\n\
corresponding Unix manual entries for more information on calls.");
_Py_IDENTIFIER(__fspath__);

-
#ifdef HAVE_SYS_UIO_H
# include <sys/uio.h>
#endif
@@ -1509,7 +1530,9 @@
/*[clinic input]
@@ -549,27 +570,33 @@
}
}
}
+#endif

void
PyOS_BeforeFork(void)
{
+#ifdef HAVE_FORK
run_at_forkers(_PyInterpreterState_GET()->before_forkers, 1);

_PyImport_AcquireLock();
+#endif
}

void
PyOS_AfterFork_Parent(void)
{
+#ifdef HAVE_FORK
if (_PyImport_ReleaseLock() <= 0)
Py_FatalError("failed releasing import lock after fork");

run_at_forkers(_PyInterpreterState_GET()->after_forkers_parent, 0);
+#endif
}

void
PyOS_AfterFork_Child(void)
{
+#ifdef HAVE_FORK
_PyRuntimeState *runtime = &_PyRuntime;
_PyGILState_Reinit(runtime);
_PyEval_ReInitThreads(runtime);
@@ -579,8 +606,10 @@
_PyInterpreterState_DeleteExceptMain(runtime);

run_at_forkers(_PyInterpreterState_GET()->after_forkers_child, 0);
+#endif
}

+#ifdef HAVE_FORK
static int
register_at_forker(PyObject **lst, PyObject *func)
{
@@ -600,9 +629,7 @@
void
PyOS_AfterFork(void)
{
-#ifdef HAVE_FORK
PyOS_AfterFork_Child();
-#endif
}


@@ -1509,7 +1536,9 @@
*/
#include <crt_externs.h>
#elif !defined(_MSC_VER) && (!defined(__WATCOMC__) || defined(__QNX__) || defined(__VXWORKS__))
Expand All @@ -2731,23 +2793,23 @@ index 12f72f525f..a2355bf93f 100644
#endif /* !_MSC_VER */

static PyObject *
@@ -1525,6 +1548,7 @@
@@ -1525,6 +1554,7 @@
d = PyDict_New();
if (d == NULL)
return NULL;
+#if !TARGET_OS_TV && !TARGET_OS_WATCH
#ifdef MS_WINDOWS
/* _wenviron must be initialized in this way if the program is started
through main() instead of wmain(). */
@@ -1580,6 +1604,7 @@
@@ -1580,6 +1610,7 @@
Py_DECREF(k);
Py_DECREF(v);
}
+#endif
return d;
}

@@ -4739,7 +4764,12 @@
@@ -4739,7 +4770,12 @@
}

Py_BEGIN_ALLOW_THREADS
Expand All @@ -2760,15 +2822,15 @@ index 12f72f525f..a2355bf93f 100644
Py_END_ALLOW_THREADS
return result;
}
@@ -13332,6 +13362,7 @@
@@ -13332,6 +13368,7 @@
int is_symlink;
int need_stat;
#endif
+#if !TARGET_OS_TV && !TARGET_OS_WATCH
#ifdef MS_WINDOWS
unsigned long dir_bits;
#endif
@@ -13392,6 +13423,7 @@
@@ -13392,6 +13429,7 @@
#endif

return result;
Expand Down
2 changes: 1 addition & 1 deletion patch/Python/Setup.watchOS
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ _decimal _decimal/_decimal.c \
_decimal/libmpdec/sixstep.c \
_decimal/libmpdec/transpose.c \
-I$(srcdir)/Modules/_decimal/libmpdec \
-DCONFIG_64=1 -DANSI=1 -DHAVE_UINT128_T=1
-DCONFIG_32=1 -DANSI=1
Loading

0 comments on commit 62bfe8d

Please sign in to comment.