Skip to content

Commit 62bfe8d

Browse files
committed
Tweaks to fix tvOS and watchOS build and usage of libFFI.
1 parent 0f2d634 commit 62bfe8d

File tree

4 files changed

+263
-46
lines changed

4 files changed

+263
-46
lines changed

Makefile

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -290,23 +290,7 @@ $$(XZ_DIR-$1)/src/liblzma/.libs/liblzma.a: $$(XZ_DIR-$1)/Makefile
290290

291291
# No need to build libFFI on macOS
292292
ifneq ($2,macOS)
293-
294-
# libFFI has it's own internal build directories for each Apple platform
295-
ifeq ($$(ARCH-$1),x86_64)
296-
LIBFFI_BUILD_DIR-$1=build_iphonesimulator-x86_64
297-
else ifeq ($$(ARCH-$1),i386)
298-
LIBFFI_BUILD_DIR-$1=build_iphonesimulator-i386
299-
else ifeq ($$(ARCH-$1),arm64)
300-
LIBFFI_BUILD_DIR-$1=build_iphoneos-arm64
301-
else ifeq ($$(ARCH-$1),armv7)
302-
LIBFFI_BUILD_DIR-$1=build_iphoneos-armv7
303-
else ifeq ($$(ARCH-$1),armv7k)
304-
LIBFFI_BUILD_DIR-$1=build_iphoneos-armv7
305-
else
306-
# This is a canary - it should never occur, so if you see it,
307-
# you've got a problem.
308-
LIBFFI_BUILD_DIR-$1=build_other
309-
endif
293+
LIBFFI_BUILD_DIR-$1=build_$$(SDK-$1)-$$(ARCH-$1)
310294

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

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

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

505489
# Create the fat library
506490
xcrun libtool -no_warning_for_no_symbols -static \

patch/Python/Python.patch

Lines changed: 80 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2681,15 +2681,30 @@ index 4aa7e6559a..511d77024c 100644
26812681
sin(pi*x), giving accurate results for all finite x (especially x
26822682
integral or close to an integer). This is here for use in the
26832683
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
2684-
index 12f72f525f..a2355bf93f 100644
2684+
index 12f72f525f..ec487c6d0e 100644
26852685
--- a/Modules/posixmodule.c
26862686
+++ b/Modules/posixmodule.c
2687-
@@ -56,6 +56,28 @@
2687+
@@ -56,6 +56,8 @@
26882688
*/
26892689
#if defined(__APPLE__)
26902690

26912691
+#include "TargetConditionals.h"
26922692
+
2693+
#if defined(__has_builtin) && __has_builtin(__builtin_available)
2694+
# define HAVE_FSTATAT_RUNTIME __builtin_available(macOS 10.10, iOS 8.0, *)
2695+
# define HAVE_FACCESSAT_RUNTIME __builtin_available(macOS 10.10, iOS 8.0, *)
2696+
@@ -169,7 +171,6 @@
2697+
disguised Unix interface). Refer to the library manual and\n\
2698+
corresponding Unix manual entries for more information on calls.");
2699+
2700+
-
2701+
#ifdef HAVE_SYS_UIO_H
2702+
# include <sys/uio.h>
2703+
#endif
2704+
@@ -326,6 +327,26 @@
2705+
# endif /* _MSC_VER */
2706+
#endif /* ! __WATCOMC__ || __QNX__ */
2707+
26932708
+// iOS/tvOS/watchOS *define* a number of POSIX functions, but you can't use them
26942709
+// because iOS isn't a conventional multiprocess environment.
26952710
+#if TARGET_OS_IPHONE
@@ -2710,18 +2725,65 @@ index 12f72f525f..a2355bf93f 100644
27102725
+# undef HAVE_WAITPID
27112726
+#endif
27122727
+
2713-
#if defined(__has_builtin) && __has_builtin(__builtin_available)
2714-
# define HAVE_FSTATAT_RUNTIME __builtin_available(macOS 10.10, iOS 8.0, *)
2715-
# define HAVE_FACCESSAT_RUNTIME __builtin_available(macOS 10.10, iOS 8.0, *)
2716-
@@ -169,7 +191,6 @@
2717-
disguised Unix interface). Refer to the library manual and\n\
2718-
corresponding Unix manual entries for more information on calls.");
2728+
_Py_IDENTIFIER(__fspath__);
27192729

2720-
-
2721-
#ifdef HAVE_SYS_UIO_H
2722-
# include <sys/uio.h>
2723-
#endif
2724-
@@ -1509,7 +1530,9 @@
2730+
/*[clinic input]
2731+
@@ -549,27 +570,33 @@
2732+
}
2733+
}
2734+
}
2735+
+#endif
2736+
2737+
void
2738+
PyOS_BeforeFork(void)
2739+
{
2740+
+#ifdef HAVE_FORK
2741+
run_at_forkers(_PyInterpreterState_GET()->before_forkers, 1);
2742+
2743+
_PyImport_AcquireLock();
2744+
+#endif
2745+
}
2746+
2747+
void
2748+
PyOS_AfterFork_Parent(void)
2749+
{
2750+
+#ifdef HAVE_FORK
2751+
if (_PyImport_ReleaseLock() <= 0)
2752+
Py_FatalError("failed releasing import lock after fork");
2753+
2754+
run_at_forkers(_PyInterpreterState_GET()->after_forkers_parent, 0);
2755+
+#endif
2756+
}
2757+
2758+
void
2759+
PyOS_AfterFork_Child(void)
2760+
{
2761+
+#ifdef HAVE_FORK
2762+
_PyRuntimeState *runtime = &_PyRuntime;
2763+
_PyGILState_Reinit(runtime);
2764+
_PyEval_ReInitThreads(runtime);
2765+
@@ -579,8 +606,10 @@
2766+
_PyInterpreterState_DeleteExceptMain(runtime);
2767+
2768+
run_at_forkers(_PyInterpreterState_GET()->after_forkers_child, 0);
2769+
+#endif
2770+
}
2771+
2772+
+#ifdef HAVE_FORK
2773+
static int
2774+
register_at_forker(PyObject **lst, PyObject *func)
2775+
{
2776+
@@ -600,9 +629,7 @@
2777+
void
2778+
PyOS_AfterFork(void)
2779+
{
2780+
-#ifdef HAVE_FORK
2781+
PyOS_AfterFork_Child();
2782+
-#endif
2783+
}
2784+
2785+
2786+
@@ -1509,7 +1536,9 @@
27252787
*/
27262788
#include <crt_externs.h>
27272789
#elif !defined(_MSC_VER) && (!defined(__WATCOMC__) || defined(__QNX__) || defined(__VXWORKS__))
@@ -2731,23 +2793,23 @@ index 12f72f525f..a2355bf93f 100644
27312793
#endif /* !_MSC_VER */
27322794

27332795
static PyObject *
2734-
@@ -1525,6 +1548,7 @@
2796+
@@ -1525,6 +1554,7 @@
27352797
d = PyDict_New();
27362798
if (d == NULL)
27372799
return NULL;
27382800
+#if !TARGET_OS_TV && !TARGET_OS_WATCH
27392801
#ifdef MS_WINDOWS
27402802
/* _wenviron must be initialized in this way if the program is started
27412803
through main() instead of wmain(). */
2742-
@@ -1580,6 +1604,7 @@
2804+
@@ -1580,6 +1610,7 @@
27432805
Py_DECREF(k);
27442806
Py_DECREF(v);
27452807
}
27462808
+#endif
27472809
return d;
27482810
}
27492811

2750-
@@ -4739,7 +4764,12 @@
2812+
@@ -4739,7 +4770,12 @@
27512813
}
27522814

27532815
Py_BEGIN_ALLOW_THREADS
@@ -2760,15 +2822,15 @@ index 12f72f525f..a2355bf93f 100644
27602822
Py_END_ALLOW_THREADS
27612823
return result;
27622824
}
2763-
@@ -13332,6 +13362,7 @@
2825+
@@ -13332,6 +13368,7 @@
27642826
int is_symlink;
27652827
int need_stat;
27662828
#endif
27672829
+#if !TARGET_OS_TV && !TARGET_OS_WATCH
27682830
#ifdef MS_WINDOWS
27692831
unsigned long dir_bits;
27702832
#endif
2771-
@@ -13392,6 +13423,7 @@
2833+
@@ -13392,6 +13429,7 @@
27722834
#endif
27732835

27742836
return result;

patch/Python/Setup.watchOS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ _decimal _decimal/_decimal.c \
3333
_decimal/libmpdec/sixstep.c \
3434
_decimal/libmpdec/transpose.c \
3535
-I$(srcdir)/Modules/_decimal/libmpdec \
36-
-DCONFIG_64=1 -DANSI=1 -DHAVE_UINT128_T=1
36+
-DCONFIG_32=1 -DANSI=1

0 commit comments

Comments
 (0)