@@ -23,31 +23,42 @@ To add this support package to your own project:
23
23
1 . [ Download a release tarball for your desired Python version and Apple
24
24
platform] ( https://github.com/beeware/Python-Apple-support/releases )
25
25
26
- 2 . Add the ` python-stdlib ` and ` Python.xcframework ` to your Xcode project. Both
27
- the ` python-stdlib ` folder and the ` Python.xcframework ` should be members of
28
- any target that needs to use Python .
26
+ 2 . Add ` Python.xcframework ` to your Xcode project. You can put it anywhere in your
27
+ project that you want; the following instructions assume it has been put in a
28
+ folder named "Support" .
29
29
30
30
3 . In Xcode, select the root node of the project tree, and select the target you
31
31
want to build.
32
32
33
33
4 . Select "General" -> "Frameworks, Libraries and Embedded Content", and ensure
34
34
that ` Python.xcframework ` is on the list of frameworks. It should be marked
35
- "Do not embed ".
35
+ "Embed and sign ".
36
36
37
- 5 . Select "General" -> "Build Phases", and ensure that the ` python-stdlib ` folder
38
- is listed in the "Copy Bundle Resources" step.
37
+ 5 . Select "General" -> "Build Settings", and set the following values:
38
+ - Linking - General:
39
+ - ` @executable_path/Frameworks `
40
+ - Search paths:
41
+ - Framework Search paths: ` "$(PROJECT_DIR)/Support" `
42
+ - Header Search paths: ` "$(BUILT_PRODUCTS_DIR)/Python.framework/Headers" `
39
43
40
- 6 . If you're on iOS, Add a new "Run script" build phase named "Purge Python Binary
41
- Modules for Non-Target Platforms ". This script will purge any dynamic module for the
42
- platform you are * not * targeting. The script should have the following content:
44
+ 6 . Add a new "Run script" build phase named "Install target specific Python
45
+ Modules". This script will install the standard library for your target. The
46
+ script should have the following content:
43
47
44
48
``` bash
49
+ set -e
50
+
51
+ mkdir -p " $CODESIGNING_FOLDER_PATH /python/lib"
45
52
if [ " $EFFECTIVE_PLATFORM_NAME " = " -iphonesimulator" ]; then
46
- echo " Purging Python modules for iOS Device"
47
- find " $CODESIGNING_FOLDER_PATH /python-stdlib" -name " *.*-iphoneos.dylib" -exec rm -f " {}" \;
53
+ echo " Installing Python modules for iOS Simulator"
54
+ rsync -au --delete " $PROJECT_DIR /Support/Python.xcframework/iphonesimulator/lib/" " $CODESIGNING_FOLDER_PATH /python/lib/"
55
+ # Also install any user-provided modules
56
+ # rsync -au --delete "$PROJECT_DIR/Testbed/app_packages.iphonesimulator/" "$CODESIGNING_FOLDER_PATH/app_packages"
48
57
else
49
- echo " Purging Python modules for iOS Simulator"
50
- find " $CODESIGNING_FOLDER_PATH " -name " *.*-iphonesimulator.dylib" -exec rm -f " {}" \;
58
+ echo " Installing Python modules for iOS Device"
59
+ rsync -au --delete " $PROJECT_DIR /Support/Python.xcframework/iphoneos/lib/" " $CODESIGNING_FOLDER_PATH /python/lib"
60
+ # Also install any user-provided modules
61
+ # rsync -au --delete "$PROJECT_DIR/Testbed/app_packages.iphoneos/" "$CODESIGNING_FOLDER_PATH/app_packages"
51
62
fi
52
63
```
53
64
@@ -69,13 +80,12 @@ install_dylib () {
69
80
DYLIB=$( basename " $FULL_DYLIB " )
70
81
# The name of the .dylib file, relative to the install base
71
82
RELATIVE_DYLIB=${FULL_DYLIB# $CODESIGNING_FOLDER_PATH / $INSTALL_BASE / }
72
- # The (hopefully unique) name of the framework, constructed by replacing path
73
- # separators in the relative name with underscores.
74
- FRAMEWORK_NAME=$( echo $RELATIVE_DYLIB | cut -d " ." -f 1 | tr " /" " _" ) ;
83
+ # The full dotted name of the binary module, constructed from the file path.
84
+ FULL_MODULE_NAME=$( echo $RELATIVE_DYLIB | cut -d " ." -f 1 | tr " /" " ." ) ;
75
85
# A bundle identifier; not actually used, but required by Xcode framework packaging
76
- FRAMEWORK_BUNDLE_ID=$( echo $PRODUCT_BUNDLE_IDENTIFIER .$FRAMEWORK_NAME | tr " _" " -" )
86
+ FRAMEWORK_BUNDLE_ID=$( echo $PRODUCT_BUNDLE_IDENTIFIER .$FULL_MODULE_NAME | tr " _" " -" )
77
87
# The name of the framework folder.
78
- FRAMEWORK_FOLDER=" Frameworks/$FRAMEWORK_NAME .framework"
88
+ FRAMEWORK_FOLDER=" Frameworks/$FULL_MODULE_NAME .framework"
79
89
80
90
# If the framework folder doesn't exist, create it.
81
91
if [ ! -d " $CODESIGNING_FOLDER_PATH /$FRAMEWORK_FOLDER " ]; then
@@ -91,10 +101,16 @@ install_dylib () {
91
101
mv " $FULL_DYLIB " " $CODESIGNING_FOLDER_PATH /$FRAMEWORK_FOLDER "
92
102
}
93
103
104
+ # Make sure to update the Python version version reference here
94
105
echo " Install standard library dylibs..."
95
- find " $CODESIGNING_FOLDER_PATH /python-stdlib /lib-dynload" -name " *.dylib" | while read FULL_DYLIB; do
96
- install_dylib python-stdlib /lib-dynload " $FULL_DYLIB "
106
+ find " $CODESIGNING_FOLDER_PATH /python/lib/python3.13 /lib-dynload" -name " *.dylib" | while read FULL_DYLIB; do
107
+ install_dylib python/lib/python3.13 /lib-dynload " $FULL_DYLIB "
97
108
done
109
+ # Also install any user-provided dynamic modules; e.g.,
110
+ # echo "Install app package dylibs..."
111
+ # find "$CODESIGNING_FOLDER_PATH/app_packages" -name "*.dylib" | while read FULL_DYLIB; do
112
+ # install_dylib app_packages "$FULL_DYLIB"
113
+ # done
98
114
99
115
# Clean up dylib template
100
116
rm -f " $CODESIGNING_FOLDER_PATH /dylib-Info-template.plist"
@@ -103,6 +119,11 @@ echo "Signing frameworks as $EXPANDED_CODE_SIGN_IDENTITY_NAME ($EXPANDED_CODE_SI
103
119
find " $CODESIGNING_FOLDER_PATH /Frameworks" -name " *.framework" -exec /usr/bin/codesign --force --sign " $EXPANDED_CODE_SIGN_IDENTITY " ${OTHER_CODE_SIGN_FLAGS:- } -o runtime --timestamp=none --preserve-metadata=identifier,entitlements,flags --generate-entitlement-der " {}" \;
104
120
```
105
121
122
+ Make sure that you update these scripts to update the references to the
123
+ Python version, and include any user-provided code that you want to bundle.
124
+ If you use the `` rsync `` approach above, user-provided code should * not* be
125
+ included as part of the "Copy Bundle Resources" step.
126
+
106
127
You'll also need to add a file named ` dylib-Info-template.plist ` to your Xcode
107
128
project, and make it a member of any target that needs to use Python. The template
108
129
should have the following content:
0 commit comments