Skip to content

Commit 8ff313c

Browse files
clementperonclaude
authored andcommitted
[PR 29029] fix(depends): build python for the iOS simulator
CPython appends -mios-version-min - the device flag - to every iOS build. Against the simulator SDK the linker rejects the dylibs it resolves there, and the first configure check that links one fails, taking the depends build with it. The local patch faked ac_sys_system=iOS by deleting CPython's host parsing, because config.site.in pinned every package to the tree's darwin triplet. Python now configures against its own iOS triplet, so CPython derives ac_sys_system, the deployment target and the device/simulator split itself, and the 76 lines that deleted that logic are gone. What is left matches three patches under review upstream, so all three can be dropped when python is next bumped: python/cpython#156110 python/cpython#156116 python/cpython#156113 Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent f0de5af commit 8ff313c

6 files changed

Lines changed: 114 additions & 149 deletions

File tree

‎tools/depends/target/config.site.in‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
if test "@cross_compiling@" = "yes"; then
22
cross_compiling=yes
3-
host=@use_host@
4-
host_alias=@use_host@
3+
# Defaults, not overrides: a package passing its own --host must win.
4+
: ${host=@use_host@}
5+
: ${host_alias=@use_host@}
56
fi
67

78
LD="@LD@"

‎tools/depends/target/python3/16-ios-platform.patch‎

Lines changed: 0 additions & 142 deletions
This file was deleted.
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--- a/configure.ac
2+
+++ b/configure.ac
3+
@@ -570,7 +570,6 @@
4+
case $enableval in
5+
no)
6+
case $ac_sys_system in
7+
- iOS) AC_MSG_ERROR([iOS builds must use --enable-framework]) ;;
8+
*)
9+
PYTHONFRAMEWORK=
10+
PYTHONFRAMEWORKDIR=no-framework
11+
@@ -680,7 +679,7 @@
12+
esac
13+
],[
14+
case $ac_sys_system in
15+
- iOS) AC_MSG_ERROR([iOS builds must use --enable-framework]) ;;
16+
+ iOS) AC_MSG_ERROR([iOS builds must use --enable-framework, or --disable-framework with --disable-shared to build a static libpython]) ;;
17+
*)
18+
PYTHONFRAMEWORK=
19+
PYTHONFRAMEWORKDIR=no-framework
20+
@@ -1636,6 +1635,12 @@
21+
esac
22+
fi
23+
AC_MSG_RESULT([$LDLIBRARY])
24+
+
25+
+# A shared Python on iOS has to be a framework: an app can only load a signed
26+
+# framework, never a bare dylib. A static libpython has nothing to load.
27+
+if test "$ac_sys_system" = "iOS" && test "$PY_ENABLE_SHARED" = 1 && test -z "$PYTHONFRAMEWORK"; then
28+
+ AC_MSG_ERROR([iOS builds must use --enable-framework, or --disable-framework with --disable-shared to build a static libpython])
29+
+fi
30+
31+
if test "$cross_compiling" = yes; then
32+
RUNSHARED=
33+
@@ -3658,7 +3663,11 @@
34+
fi
35+
LINKFORSHARED="$LINKFORSHARED"
36+
elif test $ac_sys_system = "iOS"; then
37+
- LINKFORSHARED="-Wl,-stack_size,$stack_size $LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK)'
38+
+ LINKFORSHARED="-Wl,-stack_size,$stack_size $LINKFORSHARED"
39+
+
40+
+ if test "$enable_framework"; then
41+
+ LINKFORSHARED="$LINKFORSHARED "'$(PYTHONFRAMEWORKDIR)/$(PYTHONFRAMEWORK)'
42+
+ fi
43+
fi
44+
;;
45+
OpenUNIX*|UnixWare*) LINKFORSHARED="-Wl,-Bexport";;
46+
@@ -6413,8 +6422,9 @@
47+
LIBPYTHON="\$(BLDLIBRARY)"
48+
fi
49+
50+
-# On iOS the shared libraries must be linked with the Python framework
51+
-if test "$ac_sys_system" = "iOS"; then
52+
+# On iOS the shared libraries must be linked with the Python framework, when one
53+
+# is being built
54+
+if test "$ac_sys_system" = "iOS" && test "$enable_framework"; then
55+
MODULE_DEPS_SHARED="$MODULE_DEPS_SHARED \$(PYTHONFRAMEWORKDIR)/\$(PYTHONFRAMEWORK)"
56+
fi
57+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--- a/configure.ac
2+
+++ b/configure.ac
3+
@@ -989,8 +988,13 @@
4+
dnl Add the compiler flag for the iOS minimum supported OS version.
5+
AS_CASE([$ac_sys_system],
6+
[iOS], [
7+
- AS_VAR_APPEND([CFLAGS], [" -mios-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"])
8+
- AS_VAR_APPEND([LDFLAGS], [" -mios-version-min=${IPHONEOS_DEPLOYMENT_TARGET}"])
9+
+ dnl -mios-version-min names the device platform; using it against the
10+
+ dnl simulator SDK makes the linker reject every dylib it resolves there.
11+
+ AS_IF([test "x$_host_device" = "xsimulator"],
12+
+ [_ios_version_min_flag=-mios-simulator-version-min],
13+
+ [_ios_version_min_flag=-mios-version-min])
14+
+ AS_VAR_APPEND([CFLAGS], [" ${_ios_version_min_flag}=${IPHONEOS_DEPLOYMENT_TARGET}"])
15+
+ AS_VAR_APPEND([LDFLAGS], [" ${_ios_version_min_flag}=${IPHONEOS_DEPLOYMENT_TARGET}"])
16+
],
17+
)
18+
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--- a/Lib/_ios_support.py
2+
+++ b/Lib/_ios_support.py
3+
@@ -10,12 +10,15 @@
4+
else:
5+
# ctypes is available. Load the ObjC library, and wrap the objc_getClass,
6+
# sel_registerName methods
7+
- lib = util.find_library("objc")
8+
- if lib is None:
9+
- # Failed to load the objc library
10+
- raise ImportError("ObjC runtime library couldn't be loaded")
11+
+ # find_library() resolves a system library through the dyld shared cache,
12+
+ # which needs _dyld_shared_cache_contains_path(); that is unavailable before
13+
+ # iOS 14, so fall back to the bare name, which dyld resolves by itself.
14+
+ lib = util.find_library("objc") or "libobjc.dylib"
15+
16+
- objc = cdll.LoadLibrary(lib)
17+
+ try:
18+
+ objc = cdll.LoadLibrary(lib)
19+
+ except OSError:
20+
+ raise ImportError("ObjC runtime library couldn't be loaded")
21+
objc.objc_getClass.restype = c_void_p
22+
objc.objc_getClass.argtypes = [c_char_p]
23+
objc.sel_registerName.restype = c_void_p

‎tools/depends/target/python3/Makefile‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@ DEPS = ../../Makefile.include Makefile PYTHON3-VERSION ../../download-files.incl
88
13-wasm-em-config-clang.patch \
99
14-wasm-build-wasm-default.patch \
1010
15-wasm-static-hacl.patch \
11-
16-ios-platform.patch
11+
16-ios-static-nonframework.patch \
12+
17-ios-simulator-version-min.patch \
13+
18-ios-objc-fallback.patch
1214

1315
ifeq ($(findstring apple-darwin, $(HOST)), apple-darwin)
1416
ifeq ($(OS), darwin_embedded)
@@ -81,10 +83,14 @@ ifeq ($(OS), darwin_embedded)
8183
PY_MODULES+= py_cv_module__posixsubprocess=n/a \
8284
py_cv_module__scproxy=n/a
8385

86+
# A real iOS triplet, not the tree's darwin one: CPython derives ac_sys_system,
87+
# the deployment target and the simulator split from it.
8488
ifeq ($(findstring iphone,$(TARGET_PLATFORM)),iphone)
85-
# see 16-ios-platform.patch
86-
export IPHONEOS_DEPLOYMENT_TARGET=$(APPLE_DEPLOYMENT_TARGET)
87-
export _host_device=$(subst iphone,,$(TARGET_PLATFORM))
89+
PYTHON_HOST=$(subst -darwin,-ios$(APPLE_DEPLOYMENT_TARGET),$(HOST))
90+
ifeq ($(TARGET_PLATFORM),iphonesimulator)
91+
PYTHON_HOST:=$(PYTHON_HOST)-simulator
92+
endif
93+
EXTRA_CONFIGURE+= --host=$(PYTHON_HOST)
8894
endif
8995
endif
9096

@@ -127,7 +133,9 @@ ifeq ($(OS),wasm)
127133
cd $(PLATFORM); patch -p1 -i ../15-wasm-static-hacl.patch
128134
endif
129135
ifeq ($(findstring iphone,$(TARGET_PLATFORM)),iphone)
130-
cd $(PLATFORM); patch -p1 -i ../16-ios-platform.patch
136+
cd $(PLATFORM); patch -p1 -i ../16-ios-static-nonframework.patch
137+
cd $(PLATFORM); patch -p1 -i ../17-ios-simulator-version-min.patch
138+
cd $(PLATFORM); patch -p1 -i ../18-ios-objc-fallback.patch
131139
endif
132140
cd $(PLATFORM); $(AUTORECONF)
133141
cd $(PLATFORM); $(CONFIGURE)

0 commit comments

Comments
 (0)