Repository navigation
Expand file tree
/
Copy pathPython.patch
More file actions
10198 lines (10064 loc) · 385 KB
/
Copy pathPython.patch
File metadata and controls
10198 lines (10064 loc) · 385 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 9428c4d7cb5..b8c7de11542 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -2,6 +2,10 @@
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: a27a2e47c7751b639d2b5badf0ef6ff11fee893f # frozen: v0.15.4
hooks:
+ - id: ruff-check
+ name: Run Ruff (lint) on Platforms/Apple/
+ args: [--exit-non-zero-on-fix, --config=Platforms/Apple/.ruff.toml]
+ files: ^Platforms/Apple/
- id: ruff-check
name: Run Ruff (lint) on Doc/
args: [--exit-non-zero-on-fix]
@@ -26,6 +30,10 @@
name: Run Ruff (lint) on Tools/wasm/
args: [--exit-non-zero-on-fix, --config=Tools/wasm/.ruff.toml]
files: ^Tools/wasm/
+ - id: ruff-format
+ name: Run Ruff (format) on Platforms/Apple/
+ args: [--exit-non-zero-on-fix, --config=Platforms/Apple/.ruff.toml]
+ files: ^Platforms/Apple/
- id: ruff-format
name: Run Ruff (format) on Doc/
args: [--exit-non-zero-on-fix]
diff --git a/Doc/using/ios.rst b/Doc/using/ios.rst
index 9921fd6114b..4ed18f4938c 100644
--- a/Doc/using/ios.rst
+++ b/Doc/using/ios.rst
@@ -170,7 +170,7 @@
To add Python to an iOS Xcode project:
1. Build or obtain a Python ``XCFramework``. See the instructions in
- :source:`iOS/README.rst` (in the CPython source distribution) for details on
+ :source:`Apple/iOS/README.md` (in the CPython source distribution) for details on
how to build a Python ``XCFramework``. At a minimum, you will need a build
that supports ``arm64-apple-ios``, plus one of either
``arm64-apple-ios-simulator`` or ``x86_64-apple-ios-simulator``.
@@ -180,22 +180,19 @@
of your project; however, you can use any other location that you want by
adjusting paths as needed.
-3. Drag the ``iOS/Resources/dylib-Info-template.plist`` file into your project,
- and ensure it is associated with the app target.
-
-4. Add your application code as a folder in your Xcode project. In the
+3. Add your application code as a folder in your Xcode project. In the
following instructions, we'll assume that your user code is in a folder
named ``app`` in the root of your project; you can use any other location by
adjusting paths as needed. Ensure that this folder is associated with your
app target.
-5. Select the app target by selecting the root node of your Xcode project, then
+4. Select the app target by selecting the root node of your Xcode project, then
the target name in the sidebar that appears.
-6. In the "General" settings, under "Frameworks, Libraries and Embedded
+5. In the "General" settings, under "Frameworks, Libraries and Embedded
Content", add ``Python.xcframework``, with "Embed & Sign" selected.
-7. In the "Build Settings" tab, modify the following:
+6. In the "Build Settings" tab, modify the following:
- Build Options
@@ -211,86 +208,24 @@
* Quoted Include In Framework Header: No
-8. Add a build step that copies the Python standard library into your app. In
- the "Build Phases" tab, add a new "Run Script" build step *before* the
- "Embed Frameworks" step, but *after* the "Copy Bundle Resources" step. Name
- the step "Install Target Specific Python Standard Library", disable the
- "Based on dependency analysis" checkbox, and set the script content to:
+7. Add a build step that processes the Python standard library, and your own
+ Python binary dependencies. In the "Build Phases" tab, add a new "Run
+ Script" build step *before* the "Embed Frameworks" step, but *after* the
+ "Copy Bundle Resources" step. Name the step "Process Python libraries",
+ disable the "Based on dependency analysis" checkbox, and set the script
+ content to:
.. code-block:: bash
- set -e
-
- mkdir -p "$CODESIGNING_FOLDER_PATH/python/lib"
- if [ "$EFFECTIVE_PLATFORM_NAME" = "-iphonesimulator" ]; then
- echo "Installing Python modules for iOS Simulator"
- rsync -au --delete "$PROJECT_DIR/Python.xcframework/ios-arm64_x86_64-simulator/lib/" "$CODESIGNING_FOLDER_PATH/python/lib/"
- else
- echo "Installing Python modules for iOS Device"
- rsync -au --delete "$PROJECT_DIR/Python.xcframework/ios-arm64/lib/" "$CODESIGNING_FOLDER_PATH/python/lib/"
- fi
+ set -e
+ source $PROJECT_DIR/Python.xcframework/build/build_utils.sh
+ install_python Python.xcframework app
- Note that the name of the simulator "slice" in the XCframework may be
- different, depending the CPU architectures your ``XCFramework`` supports.
+ If you have placed your XCframework somewhere other than the root of your
+ project, modify the path to the first argument.
-9. Add a second build step that processes the binary extension modules in the
- standard library into "Framework" format. Add a "Run Script" build step
- *directly after* the one you added in step 8, named "Prepare Python Binary
- Modules". It should also have "Based on dependency analysis" unchecked, with
- the following script content:
-
- .. code-block:: bash
-
- set -e
-
- install_dylib () {
- INSTALL_BASE=$1
- FULL_EXT=$2
-
- # The name of the extension file
- EXT=$(basename "$FULL_EXT")
- # The location of the extension file, relative to the bundle
- RELATIVE_EXT=${FULL_EXT#$CODESIGNING_FOLDER_PATH/}
- # The path to the extension file, relative to the install base
- PYTHON_EXT=${RELATIVE_EXT/$INSTALL_BASE/}
- # The full dotted name of the extension module, constructed from the file path.
- FULL_MODULE_NAME=$(echo $PYTHON_EXT | cut -d "." -f 1 | tr "/" ".");
- # A bundle identifier; not actually used, but required by Xcode framework packaging
- FRAMEWORK_BUNDLE_ID=$(echo $PRODUCT_BUNDLE_IDENTIFIER.$FULL_MODULE_NAME | tr "_" "-")
- # The name of the framework folder.
- FRAMEWORK_FOLDER="Frameworks/$FULL_MODULE_NAME.framework"
-
- # If the framework folder doesn't exist, create it.
- if [ ! -d "$CODESIGNING_FOLDER_PATH/$FRAMEWORK_FOLDER" ]; then
- echo "Creating framework for $RELATIVE_EXT"
- mkdir -p "$CODESIGNING_FOLDER_PATH/$FRAMEWORK_FOLDER"
- cp "$CODESIGNING_FOLDER_PATH/dylib-Info-template.plist" "$CODESIGNING_FOLDER_PATH/$FRAMEWORK_FOLDER/Info.plist"
- plutil -replace CFBundleExecutable -string "$FULL_MODULE_NAME" "$CODESIGNING_FOLDER_PATH/$FRAMEWORK_FOLDER/Info.plist"
- plutil -replace CFBundleIdentifier -string "$FRAMEWORK_BUNDLE_ID" "$CODESIGNING_FOLDER_PATH/$FRAMEWORK_FOLDER/Info.plist"
- fi
-
- echo "Installing binary for $FRAMEWORK_FOLDER/$FULL_MODULE_NAME"
- mv "$FULL_EXT" "$CODESIGNING_FOLDER_PATH/$FRAMEWORK_FOLDER/$FULL_MODULE_NAME"
- # Create a placeholder .fwork file where the .so was
- echo "$FRAMEWORK_FOLDER/$FULL_MODULE_NAME" > ${FULL_EXT%.so}.fwork
- # Create a back reference to the .so file location in the framework
- echo "${RELATIVE_EXT%.so}.fwork" > "$CODESIGNING_FOLDER_PATH/$FRAMEWORK_FOLDER/$FULL_MODULE_NAME.origin"
- }
-
- PYTHON_VER=$(ls -1 "$CODESIGNING_FOLDER_PATH/python/lib")
- echo "Install Python $PYTHON_VER standard library extension modules..."
- find "$CODESIGNING_FOLDER_PATH/python/lib/$PYTHON_VER/lib-dynload" -name "*.so" | while read FULL_EXT; do
- install_dylib python/lib/$PYTHON_VER/lib-dynload/ "$FULL_EXT"
- done
-
- # Clean up dylib template
- rm -f "$CODESIGNING_FOLDER_PATH/dylib-Info-template.plist"
-
- echo "Signing frameworks as $EXPANDED_CODE_SIGN_IDENTITY_NAME ($EXPANDED_CODE_SIGN_IDENTITY)..."
- 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 "{}" \;
-
-10. Add Objective C code to initialize and use a Python interpreter in embedded
- mode. You should ensure that:
+8. Add Objective C code to initialize and use a Python interpreter in embedded
+ mode. You should ensure that:
* UTF-8 mode (:c:member:`PyPreConfig.utf8_mode`) is *enabled*;
* Buffered stdio (:c:member:`PyConfig.buffered_stdio`) is *disabled*;
@@ -307,22 +242,19 @@
Your app's bundle location can be determined using ``[[NSBundle mainBundle]
resourcePath]``.
-Steps 8, 9 and 10 of these instructions assume that you have a single folder of
+Steps 7 and 8 of these instructions assume that you have a single folder of
pure Python application code, named ``app``. If you have third-party binary
modules in your app, some additional steps will be required:
* You need to ensure that any folders containing third-party binaries are
- either associated with the app target, or copied in as part of step 8. Step 8
- should also purge any binaries that are not appropriate for the platform a
- specific build is targeting (i.e., delete any device binaries if you're
- building an app targeting the simulator).
-
-* Any folders that contain third-party binaries must be processed into
- framework form by step 9. The invocation of ``install_dylib`` that processes
- the ``lib-dynload`` folder can be copied and adapted for this purpose.
+ either associated with the app target, or are explicitly copied as part of
+ step 7. Step 7 should also purge any binaries that are not appropriate for
+ the platform a specific build is targeting (i.e., delete any device binaries
+ if you're building an app targeting the simulator).
-* If you're using a separate folder for third-party packages, ensure that folder
- is included as part of the :envvar:`PYTHONPATH` configuration in step 10.
+* If you're using a separate folder for third-party packages, ensure that
+ folder is added to the end of the call to ``install_python`` in step 7, and
+ as part of the :envvar:`PYTHONPATH` configuration in step 8.
* If any of the folders that contain third-party packages will contain ``.pth``
files, you should add that folder as a *site directory* (using
@@ -332,25 +264,30 @@
Testing a Python package
------------------------
-The CPython source tree contains :source:`a testbed project <iOS/testbed>` that
+The CPython source tree contains :source:`a testbed project <Apple/iOS/testbed>` that
is used to run the CPython test suite on the iOS simulator. This testbed can also
be used as a testbed project for running your Python library's test suite on iOS.
-After building or obtaining an iOS XCFramework (See :source:`iOS/README.rst`
-for details), create a clone of the Python iOS testbed project by running:
+After building or obtaining an iOS XCFramework (see :source:`Apple/iOS/README.md`
+for details), create a clone of the Python iOS testbed project. If you used the
+``Apple`` build script to build the XCframework, you can run:
+
+.. code-block:: bash
+
+ $ python cross-build/iOS/testbed clone --app <path/to/module1> --app <path/to/module2> app-testbed
+
+Or, if you've sourced your own XCframework, by running:
.. code-block:: bash
- $ python iOS/testbed clone --framework <path/to/Python.xcframework> --app <path/to/module1> --app <path/to/module2> app-testbed
+ $ python Apple/testbed clone --platform iOS --framework <path/to/Python.xcframework> --app <path/to/module1> --app <path/to/module2> app-testbed
-You will need to modify the ``iOS/testbed`` reference to point to that
-directory in the CPython source tree; any folders specified with the ``--app``
-flag will be copied into the cloned testbed project. The resulting testbed will
-be created in the ``app-testbed`` folder. In this example, the ``module1`` and
-``module2`` would be importable modules at runtime. If your project has
-additional dependencies, they can be installed into the
-``app-testbed/iOSTestbed/app_packages`` folder (using ``pip install --target
-app-testbed/iOSTestbed/app_packages`` or similar).
+Any folders specified with the ``--app`` flag will be copied into the cloned
+testbed project. The resulting testbed will be created in the ``app-testbed``
+folder. In this example, the ``module1`` and ``module2`` would be importable
+modules at runtime. If your project has additional dependencies, they can be
+installed into the ``app-testbed/Testbed/app_packages`` folder (using ``pip
+install --target app-testbed/Testbed/app_packages`` or similar).
You can then use the ``app-testbed`` folder to run the test suite for your app,
For example, if ``module1.tests`` was the entry point to your test suite, you
@@ -379,7 +316,7 @@
arguments.
The test plan also disables parallel testing, and specifies the use of the
-``iOSTestbed.lldbinit`` file for providing configuration of the debugger. The
+``Testbed.lldbinit`` file for providing configuration of the debugger. The
default debugger configuration disables automatic breakpoints on the
``SIGINT``, ``SIGUSR1``, ``SIGUSR2``, and ``SIGXFSZ`` signals.
@@ -389,7 +326,12 @@
The only mechanism for distributing apps to third-party iOS devices is to
submit the app to the iOS App Store; apps submitted for distribution must pass
Apple's app review process. This process includes a set of automated validation
-rules that inspect the submitted application bundle for problematic code.
+rules that inspect the submitted application bundle for problematic code. There
+are some steps that must be taken to ensure that your app will be able to pass
+these validation steps.
+
+Incompatible code in the standard library
+-----------------------------------------
The Python standard library contains some code that is known to violate these
automated rules. While these violations appear to be false positives, Apple's
@@ -400,3 +342,18 @@
:source:`a patch file <Mac/Resources/app-store-compliance.patch>` that will remove
all code that is known to cause issues with the App Store review process. This
patch is applied automatically when building for iOS.
+
+Privacy manifests
+-----------------
+
+In April 2025, Apple introduced a requirement for `certain third-party
+libraries to provide a Privacy Manifest
+<https://developer.apple.com/support/third-party-SDK-requirements>`__.
+As a result, if you have a binary module that uses one of the affected
+libraries, you must provide an ``.xcprivacy`` file for that library.
+OpenSSL is one library affected by this requirement, but there are others.
+
+If you produce a binary module named ``mymodule.so``, and use you the Xcode
+build script described in step 7 above, you can place a ``mymodule.xcprivacy``
+file next to ``mymodule.so``, and the privacy manifest will be installed into
+the required location when the binary module is converted into a framework.
diff --git a/Include/internal/mimalloc/mimalloc/prim.h b/Include/internal/mimalloc/mimalloc/prim.h
index 322ab29e6b4..bb54814238d 100644
--- a/Include/internal/mimalloc/mimalloc/prim.h
+++ b/Include/internal/mimalloc/mimalloc/prim.h
@@ -174,12 +174,15 @@
__asm__ volatile ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tcb));
res = tcb[slot];
#elif defined(__aarch64__)
- void** tcb; MI_UNUSED(ofs);
+ // Use a 64-bit temporary: on arm64_32 (ILP32), pointers are 32 bits
+ // but system registers are 64 bits.
+ uint64_t tp; MI_UNUSED(ofs);
#if defined(__APPLE__) // M1, issue #343
- __asm__ volatile ("mrs %0, tpidrro_el0\nbic %0, %0, #7" : "=r" (tcb));
+ __asm__ volatile ("mrs %0, tpidrro_el0\nbic %0, %0, #7" : "=r" (tp));
#else
- __asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tcb));
+ __asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tp));
#endif
+ void** tcb = (void**)(uintptr_t)tp;
res = tcb[slot];
#endif
return res;
@@ -201,12 +204,15 @@
__asm__ volatile ("mrc p15, 0, %0, c13, c0, 3\nbic %0, %0, #3" : "=r" (tcb));
tcb[slot] = value;
#elif defined(__aarch64__)
- void** tcb; MI_UNUSED(ofs);
+ // Use a 64-bit temporary: on arm64_32 (ILP32), pointers are 32 bits
+ // but system registers are 64 bits.
+ uint64_t tp; MI_UNUSED(ofs);
#if defined(__APPLE__) // M1, issue #343
- __asm__ volatile ("mrs %0, tpidrro_el0\nbic %0, %0, #7" : "=r" (tcb));
+ __asm__ volatile ("mrs %0, tpidrro_el0\nbic %0, %0, #7" : "=r" (tp));
#else
- __asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tcb));
+ __asm__ volatile ("mrs %0, tpidr_el0" : "=r" (tp));
#endif
+ void** tcb = (void**)(uintptr_t)tp;
tcb[slot] = value;
#endif
}
diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
index 62d375f9dca..fd0a2dc1616 100644
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -673,10 +673,10 @@
# end polls as readable whenever unread data sits in the FIFO, and no
# event is delivered when the read end is closed, so it can only
# ever report a false disconnection (gh-145030). The same XNU
- # behaviour applies on iOS/tvOS/watchOS (sys.platform is not
+ # behaviour applies on iOS/tvOS/visionOS/watchOS (sys.platform is not
# "darwin" there).
is_named_fifo_without_close_event = (
- sys.platform in {"darwin", "ios", "tvos", "watchos", "sunos5"}
+ sys.platform in {"darwin", "ios", "tvos", "visionos", "watchos", "sunos5"}
and is_fifo and pipe_stat.st_nlink > 0)
if is_socket or (is_fifo
and not sys.platform.startswith("aix")
diff --git a/Lib/ctypes/__init__.py b/Lib/ctypes/__init__.py
index c430f9faa47..e733003e965 100644
--- a/Lib/ctypes/__init__.py
+++ b/Lib/ctypes/__init__.py
@@ -380,9 +380,9 @@
else:
def _load_library(self, name, mode, handle, winmode):
- # If the filename that has been provided is an iOS/tvOS/watchOS
- # .fwork file, dereference the location to the true origin of the
- # binary.
+ # If the filename that has been provided is an iOS, tvOS, visionOS
+ # or watchOS .fwork file, dereference the location to the true
+ # origin of the binary.
if name and name.endswith(".fwork"):
with open(name) as f:
name = _os.path.join(
diff --git a/Lib/ctypes/util.py b/Lib/ctypes/util.py
index 43f10dedce8..7cbc6039fa2 100644
--- a/Lib/ctypes/util.py
+++ b/Lib/ctypes/util.py
@@ -67,7 +67,7 @@
return fname
return None
-elif os.name == "posix" and sys.platform in {"darwin", "ios", "tvos", "watchos"}:
+elif os.name == "posix" and sys.platform in {"darwin", "ios", "tvos", "visionos", "watchos"}:
from ctypes.macholib.dyld import dyld_find as _dyld_find
def find_library(name):
possible = ['lib%s.dylib' % name,
diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py
index fcfe312747c..e02a897ea08 100644
--- a/Lib/importlib/_bootstrap_external.py
+++ b/Lib/importlib/_bootstrap_external.py
@@ -52,7 +52,7 @@
# Bootstrap-related code ######################################################
_CASE_INSENSITIVE_PLATFORMS_STR_KEY = 'win',
-_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY = 'cygwin', 'darwin', 'ios', 'tvos', 'watchos'
+_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY = 'cygwin', 'darwin', 'ios', 'tvos', 'visionos', 'watchos'
_CASE_INSENSITIVE_PLATFORMS = (_CASE_INSENSITIVE_PLATFORMS_BYTES_KEY
+ _CASE_INSENSITIVE_PLATFORMS_STR_KEY)
@@ -1806,7 +1806,7 @@
"""
extension_loaders = []
if hasattr(_imp, 'create_dynamic'):
- if sys.platform in {"ios", "tvos", "watchos"}:
+ if sys.platform in {"ios", "tvos", "visionos", "watchos"}:
extension_loaders = [(AppleFrameworkLoader, [
suffix.replace(".so", ".fwork")
for suffix in _imp.extension_suffixes()
diff --git a/Lib/platform.py b/Lib/platform.py
index 8895177e326..9e1e0628671 100755
--- a/Lib/platform.py
+++ b/Lib/platform.py
@@ -522,6 +522,78 @@
return IOSVersionInfo(system, release, model, is_simulator)
+# A namedtuple for tvOS version information.
+TVOSVersionInfo = collections.namedtuple(
+ "TVOSVersionInfo",
+ ["system", "release", "model", "is_simulator"]
+)
+
+
+def tvos_ver(system="", release="", model="", is_simulator=False):
+ """Get tvOS version information, and return it as a namedtuple:
+ (system, release, model, is_simulator).
+
+ If values can't be determined, they are set to values provided as
+ parameters.
+ """
+ if sys.platform == "tvos":
+ # TODO: Can the iOS implementation be used here?
+ import _ios_support
+ result = _ios_support.get_platform_ios()
+ if result is not None:
+ return TVOSVersionInfo(*result)
+
+ return TVOSVersionInfo(system, release, model, is_simulator)
+
+
+# A namedtuple for watchOS version information.
+WatchOSVersionInfo = collections.namedtuple(
+ "WatchOSVersionInfo",
+ ["system", "release", "model", "is_simulator"]
+)
+
+
+def watchos_ver(system="", release="", model="", is_simulator=False):
+ """Get watchOS version information, and return it as a namedtuple:
+ (system, release, model, is_simulator).
+
+ If values can't be determined, they are set to values provided as
+ parameters.
+ """
+ if sys.platform == "watchos":
+ # TODO: Can the iOS implementation be used here?
+ import _ios_support
+ result = _ios_support.get_platform_ios()
+ if result is not None:
+ return WatchOSVersionInfo(*result)
+
+ return WatchOSVersionInfo(system, release, model, is_simulator)
+
+
+# A namedtuple for visionOS version information.
+VisionOSVersionInfo = collections.namedtuple(
+ "VisionOSVersionInfo",
+ ["system", "release", "model", "is_simulator"]
+)
+
+
+def visionos_ver(system="", release="", model="", is_simulator=False):
+ """Get visionOS version information, and return it as a namedtuple:
+ (system, release, model, is_simulator).
+
+ If values can't be determined, they are set to values provided as
+ parameters.
+ """
+ if sys.platform == "visionos":
+ # TODO: Can the iOS implementation be used here?
+ import _ios_support
+ result = _ios_support.get_platform_ios()
+ if result is not None:
+ return VisionOSVersionInfo(*result)
+
+ return VisionOSVersionInfo(system, release, model, is_simulator)
+
+
def _java_getprop(name, default):
"""This private helper is deprecated in 3.13 and will be removed in 3.15"""
from java.lang import System
@@ -721,7 +793,7 @@
default in case the command should fail.
"""
- if sys.platform in {'dos', 'win32', 'win16', 'ios', 'tvos', 'watchos'}:
+ if sys.platform in {'dos', 'win32', 'win16', 'ios', 'tvos', 'visionos', 'watchos'}:
# XXX Others too ?
return default
@@ -885,14 +957,30 @@
csid, cpu_number = vms_lib.getsyi('SYI$_CPU', 0)
return 'Alpha' if cpu_number >= 128 else 'VAX'
- # On the iOS simulator, os.uname returns the architecture as uname.machine.
- # On device it returns the model name for some reason; but there's only one
- # CPU architecture for iOS devices, so we know the right answer.
+ # On the iOS/tvOS/visionOS/watchOS simulator, os.uname returns the
+ # architecture as uname.machine. On device it returns the model name for
+ # some reason; but there's only one CPU architecture for devices, so we know
+ # the right answer.
def get_ios():
if sys.implementation._multiarch.endswith("simulator"):
return os.uname().machine
return 'arm64'
+ def get_tvos():
+ if sys.implementation._multiarch.endswith("simulator"):
+ return os.uname().machine
+ return 'arm64'
+
+ def get_visionos():
+ if sys.implementation._multiarch.endswith("simulator"):
+ return os.uname().machine
+ return 'arm64'
+
+ def get_watchos():
+ if sys.implementation._multiarch.endswith("simulator"):
+ return os.uname().machine
+ return 'arm64_32'
+
def from_subprocess():
"""
Fall back to `uname -p`
@@ -1052,9 +1140,15 @@
system = 'Android'
release = android_ver().release
- # Normalize responses on iOS
+ # Normalize responses on Apple mobile platforms
if sys.platform == 'ios':
system, release, _, _ = ios_ver()
+ if sys.platform == 'tvos':
+ system, release, _, _ = tvos_ver()
+ if sys.platform == 'visionos':
+ system, release, _, _ = visionos_ver()
+ if sys.platform == 'watchos':
+ system, release, _, _ = watchos_ver()
vals = system, node, release, version, machine
# Replace 'unknown' values with the more portable ''
@@ -1344,6 +1438,12 @@
# macOS and iOS both report as a "Darwin" kernel
if sys.platform == "ios":
system, release, _, _ = ios_ver()
+ elif sys.platform == "tvos":
+ system, release, _, _ = tvos_ver()
+ elif sys.platform == "visionos":
+ system, release, _, _ = visionos_ver()
+ elif sys.platform == "watchos":
+ system, release, _, _ = watchos_ver()
else:
macos_release = mac_ver()[0]
if macos_release:
diff --git a/Lib/site.py b/Lib/site.py
index 041dca113a5..3dedc828524 100644
--- a/Lib/site.py
+++ b/Lib/site.py
@@ -292,8 +292,8 @@
if env_base:
return env_base
- # Emscripten, iOS, tvOS, VxWorks, WASI, and watchOS have no home directories
- if sys.platform in {"emscripten", "ios", "tvos", "vxworks", "wasi", "watchos"}:
+ # Emscripten, iOS, tvOS, visionOS, VxWorks, WASI, and watchOS have no home directories
+ if sys.platform in {"emscripten", "ios", "tvos", "vxworks", "visionos", "wasi", "watchos"}:
return None
def joinuser(*args):
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index e845f48a407..b64a0553973 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -75,7 +75,7 @@
_mswindows = True
# some platforms do not support subprocesses
-_can_fork_exec = sys.platform not in {"emscripten", "wasi", "ios", "tvos", "watchos"}
+_can_fork_exec = sys.platform not in {"emscripten", "wasi", "ios", "tvos", "visionos", "watchos"}
if _mswindows:
import _winapi
diff --git a/Lib/sysconfig/__init__.py b/Lib/sysconfig/__init__.py
index 43edebce347..c6136b661ac 100644
--- a/Lib/sysconfig/__init__.py
+++ b/Lib/sysconfig/__init__.py
@@ -23,6 +23,9 @@
_ALWAYS_STR = {
'IPHONEOS_DEPLOYMENT_TARGET',
'MACOSX_DEPLOYMENT_TARGET',
+ 'TVOS_DEPLOYMENT_TARGET',
+ 'WATCHOS_DEPLOYMENT_TARGET',
+ 'XROS_DEPLOYMENT_TARGET',
}
_INSTALL_SCHEMES = {
@@ -117,7 +120,7 @@
return env_base
# Emscripten, iOS, tvOS, VxWorks, WASI, and watchOS have no home directories
- if sys.platform in {"emscripten", "ios", "tvos", "vxworks", "wasi", "watchos"}:
+ if sys.platform in {"emscripten", "ios", "tvos", "visionos", "vxworks", "wasi", "watchos"}:
return None
def joinuser(*args):
@@ -688,6 +691,18 @@
release = get_config_vars().get("IPHONEOS_DEPLOYMENT_TARGET", "13.0")
osname = sys.platform
machine = sys.implementation._multiarch
+ elif sys.platform == "tvos":
+ release = get_config_vars().get("TVOS_DEPLOYMENT_TARGET", "12.0")
+ osname = sys.platform
+ machine = sys.implementation._multiarch
+ elif sys.platform == "watchos":
+ release = get_config_vars().get("WATCHOS_DEPLOYMENT_TARGET", "9.0")
+ osname = sys.platform
+ machine = sys.implementation._multiarch
+ elif sys.platform == "visionos":
+ release = get_config_vars().get("XROS_DEPLOYMENT_TARGET", "2.0")
+ osname = sys.platform
+ machine = sys.implementation._multiarch
else:
import _osx_support
osname, release, machine = _osx_support.get_platform_osx(
diff --git a/Lib/test/datetimetester.py b/Lib/test/datetimetester.py
index ca60e204cff..ab7aeba9e7d 100644
--- a/Lib/test/datetimetester.py
+++ b/Lib/test/datetimetester.py
@@ -6897,9 +6897,9 @@
self.assertEqual(dt_orig, dt_rt)
def test_type_check_in_subinterp(self):
- # iOS requires the use of the custom framework loader,
+ # Apple mobile platforms require the use of the custom framework loader,
# not the ExtensionFileLoader.
- if sys.platform == "ios":
+ if support.is_apple_mobile:
extension_loader = "AppleFrameworkLoader"
else:
extension_loader = "ExtensionFileLoader"
diff --git a/Lib/test/pythoninfo.py b/Lib/test/pythoninfo.py
index e6b6271763d..5f378af91e1 100644
--- a/Lib/test/pythoninfo.py
+++ b/Lib/test/pythoninfo.py
@@ -9,7 +9,7 @@
MS_WINDOWS = (sys.platform == "win32")
-APPLE = (sys.platform in ("darwin", "ios", "tvos", "watchos"))
+APPLE = (sys.platform in ("darwin", "ios", "tvos", "watchos", "visionos"))
COMMAND_TIMEOUT = 60.0
diff --git a/Lib/test/support/__init__.py b/Lib/test/support/__init__.py
index 4a20b55448c..22e62785747 100644
--- a/Lib/test/support/__init__.py
+++ b/Lib/test/support/__init__.py
@@ -67,6 +67,7 @@
"make_clean_env",
"BrokenIter",
"requires_root_user", "requires_non_root_user",
+ "on_github_actions"
]
@@ -595,7 +596,7 @@
is_android = sys.platform == "android"
-if sys.platform not in {"win32", "vxworks", "ios", "tvos", "watchos"}:
+if sys.platform not in {"win32", "vxworks", "ios", "tvos", "visionos", "watchos"}:
unix_shell = '/system/bin/sh' if is_android else '/bin/sh'
else:
unix_shell = None
@@ -605,7 +606,7 @@
is_emscripten = sys.platform == "emscripten"
is_wasi = sys.platform == "wasi"
-is_apple_mobile = sys.platform in {"ios", "tvos", "watchos"}
+is_apple_mobile = sys.platform in {"ios", "tvos", "visionos", "watchos"}
is_apple = is_apple_mobile or sys.platform == "darwin"
has_fork_support = hasattr(os, "fork") and not (
@@ -1349,6 +1350,8 @@
_opcode.ENABLE_SPECIALIZATION, "requires specialization")(test)
+on_github_actions = "GITHUB_ACTIONS" in os.environ
+
#=======================================================================
# Check for the presence of docstrings.
diff --git a/Lib/test/test__interpreters.py b/Lib/test/test__interpreters.py
index 6fb2bc24fa3..88cb6691cd8 100644
--- a/Lib/test/test__interpreters.py
+++ b/Lib/test/test__interpreters.py
@@ -695,6 +695,7 @@
f'assert(obj == {obj!r})',
)
+ @support.requires_subprocess()
def test_os_exec(self):
expected = 'spam spam spam spam spam'
subinterp = _interpreters.create()
diff --git a/Lib/test/test_platform.py b/Lib/test/test_platform.py
index ed277276b51..c846a9bc5d7 100644
--- a/Lib/test/test_platform.py
+++ b/Lib/test/test_platform.py
@@ -236,13 +236,21 @@
if sys.platform == "android":
self.assertEqual(res.system, "Android")
self.assertEqual(res.release, platform.android_ver().release)
- elif sys.platform == "ios":
+ elif support.is_apple_mobile:
# Platform module needs ctypes for full operation. If ctypes
# isn't available, there's no ObjC module, and dummy values are
# returned.
if _ctypes:
- self.assertIn(res.system, {"iOS", "iPadOS"})
- self.assertEqual(res.release, platform.ios_ver().release)
+ if sys.platform == "ios":
+ # iPads also identify as iOS
+ self.assertIn(res.system, {"iOS", "iPadOS"})
+ else:
+ # All other platforms - sys.platform is the lower case
+ # form of system (e.g., visionOS->visionos)
+ self.assertEqual(res.system.lower(), sys.platform)
+ # Use the platform-specific version method
+ platform_ver = getattr(platform, f"{sys.platform}_ver")
+ self.assertEqual(res.release, platform_ver().release)
else:
self.assertEqual(res.system, "")
self.assertEqual(res.release, "")
diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py
index 0f62f9eb200..2ca356606b2 100644
--- a/Lib/test/test_socketserver.py
+++ b/Lib/test/test_socketserver.py
@@ -218,12 +218,16 @@
self.dgram_examine)
@requires_unix_sockets
+ @unittest.skipIf(test.support.is_apple_mobile and test.support.on_github_actions,
+ "gh-140702: Test fails regularly on iOS simulator on GitHub Actions")
def test_UnixDatagramServer(self):
self.run_server(socketserver.UnixDatagramServer,
socketserver.DatagramRequestHandler,
self.dgram_examine)
@requires_unix_sockets
+ @unittest.skipIf(test.support.is_apple_mobile and test.support.on_github_actions,
+ "gh-140702: Test fails regularly on iOS simulator on GitHub Actions")
def test_ThreadingUnixDatagramServer(self):
self.run_server(socketserver.ThreadingUnixDatagramServer,
socketserver.DatagramRequestHandler,
diff --git a/Lib/test/test_webbrowser.py b/Lib/test/test_webbrowser.py
index 135f116d46b..c756e8e0ba7 100644
--- a/Lib/test/test_webbrowser.py
+++ b/Lib/test/test_webbrowser.py
@@ -252,7 +252,8 @@
arguments=[f'openURL({URL},new-tab)'])
-@unittest.skipUnless(sys.platform == "ios", "Test only applicable to iOS")
+@unittest.skipUnless(sys.platform in {"ios", "visionOS"},
+ "Test only applicable to iOS and visionOS")
class IOSBrowserTest(unittest.TestCase):
def _obj_ref(self, *args):
# Construct a string representation of the arguments that can be used
diff --git a/Lib/webbrowser.py b/Lib/webbrowser.py
index be033d707a9..8e47e6576fe 100755
--- a/Lib/webbrowser.py
+++ b/Lib/webbrowser.py
@@ -500,7 +500,8 @@
# OS X can use below Unix support (but we prefer using the OS X
# specific stuff)
- if sys.platform == "ios":
+ if sys.platform in {"ios", "visionos"}:
+ # iOS and visionOS provide a browser; tvOS and watchOS don't.
register("iosbrowser", None, IOSBrowser(), preferred=True)
if sys.platform == "serenityos":
@@ -629,9 +630,10 @@
return not rc
#
-# Platform support for iOS
+# Platform support for Apple Mobile platforms that provide a browser
+# (i.e., iOS and visionOS)
#
-if sys.platform == "ios":
+if sys.platform in {"ios", "visionos"}:
from _ios_support import objc
if objc:
# If objc exists, we know ctypes is also importable.
diff --git a/Mac/BuildScript/resources/install_certificates.command b/Mac/BuildScript/resources/install_certificates.command
index 700eb462b68..aa44961da7f 100755
--- a/Mac/BuildScript/resources/install_certificates.command
+++ b/Mac/BuildScript/resources/install_certificates.command
@@ -1,4 +1,8 @@
#!/bin/sh
+# Installing into the global environment is the point; ensure that the user
+# hasn't configured pip to always require a virtual environment.
+unset PIP_REQUIRE_VENV
+unset PIP_REQUIRE_VIRTUALENV
/Library/Frameworks/Python.framework/Versions/@PYVER@/bin/python@PYVER@ << "EOF"
diff --git a/Makefile.pre.in b/Makefile.pre.in
index 414b466cf60..ccae3a9c81b 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -202,6 +202,12 @@
# the build, and is only listed here so it will be included in sysconfigdata.
IPHONEOS_DEPLOYMENT_TARGET=@IPHONEOS_DEPLOYMENT_TARGET@
+# visionOS Deployment target is *actually* used during the build, by the
+# compiler shims; export.
+XROS_DEPLOYMENT_TARGET=@XROS_DEPLOYMENT_TARGET@
+@EXPORT_XROS_DEPLOYMENT_TARGET@export XROS_DEPLOYMENT_TARGET
+
+
# Option to install to strip binaries
STRIPFLAG=-s
@@ -2098,7 +2104,7 @@
fi
# Clone the testbed project into the XCFOLDER
- $(PYTHON_FOR_BUILD) $(srcdir)/iOS/testbed clone --framework $(PYTHONFRAMEWORKPREFIX) "$(XCFOLDER)"
+ $(PYTHON_FOR_BUILD) $(srcdir)/Platforms/Apple/testbed clone --framework $(PYTHONFRAMEWORKPREFIX) "$(XCFOLDER)"
# Run the testbed project
$(PYTHON_FOR_BUILD) "$(XCFOLDER)" run --verbose -- test -uall --single-process --rerun -W
@@ -2802,6 +2808,9 @@
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)
sed 's/%VERSION%/'"`$(RUNSHARED) $(PYTHON_FOR_BUILD) -c 'import platform; print(platform.python_version())'`"'/g' < $(RESSRCDIR)/Info.plist > $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Info.plist
$(INSTALL_SHARED) $(LDLIBRARY) $(DESTDIR)$(PYTHONFRAMEWORKPREFIX)/$(LDLIBRARY)
+ $(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(LIBDIR)
+ $(LN) -fs "../$(LDLIBRARY)" "$(DESTDIR)$(prefix)/lib/libpython$(LDVERSION).dylib"
+ $(LN) -fs "../$(LDLIBRARY)" "$(DESTDIR)$(prefix)/lib/libpython$(VERSION).dylib"
$(INSTALL) -d -m $(DIRMODE) $(DESTDIR)$(BINDIR)
for file in $(srcdir)/$(RESSRCDIR)/bin/* ; do \
$(INSTALL) -m $(EXEMODE) $$file $(DESTDIR)$(BINDIR); \
@@ -2986,10 +2995,10 @@
-find build -type f -a ! -name '*.gc??' -exec rm -f {} ';'
-rm -f Include/pydtrace_probes.h
-rm -f profile-gen-stamp
- -rm -rf iOS/testbed/Python.xcframework/ios-*/bin
- -rm -rf iOS/testbed/Python.xcframework/ios-*/lib
- -rm -rf iOS/testbed/Python.xcframework/ios-*/include
- -rm -rf iOS/testbed/Python.xcframework/ios-*/Python.framework
+ -rm -rf Platforms/Apple/iOS/testbed/Python.xcframework/ios-*/bin
+ -rm -rf Platforms/Apple/iOS/testbed/Python.xcframework/ios-*/lib
+ -rm -rf Platforms/Apple/iOS/testbed/Python.xcframework/ios-*/include
+ -rm -rf Platforms/Apple/iOS/testbed/Python.xcframework/ios-*/Python.framework
.PHONY: profile-removal
profile-removal:
@@ -3023,7 +3032,7 @@
config.cache config.log pyconfig.h Modules/config.c
-rm -rf build platform
-rm -rf $(PYTHONFRAMEWORKDIR)
- -rm -rf iOS/Frameworks
+ -rm -rf Platforms/Apple/iOS/Frameworks
-rm -rf iOSTestbed.*
-rm -f python-config.py python-config
-rm -rf cross-build
diff --git a/Misc/platform_triplet.c b/Misc/platform_triplet.c
index f5cd73bdea8..6c1863c943b 100644
--- a/Misc/platform_triplet.c
+++ b/Misc/platform_triplet.c
@@ -257,6 +257,32 @@
# else
PLATFORM_TRIPLET=arm64-iphoneos
# endif
+# elif defined(TARGET_OS_TV) && TARGET_OS_TV
+# if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
+# if __x86_64__
+PLATFORM_TRIPLET=x86_64-appletvsimulator
+# else
+PLATFORM_TRIPLET=arm64-appletvsimulator
+# endif
+# else
+PLATFORM_TRIPLET=arm64-appletvos
+# endif
+# elif defined(TARGET_OS_WATCH) && TARGET_OS_WATCH
+# if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
+# if __x86_64__
+PLATFORM_TRIPLET=x86_64-watchsimulator
+# else
+PLATFORM_TRIPLET=arm64-watchsimulator
+# endif
+# else
+PLATFORM_TRIPLET=arm64_32-watchos
+# endif
+# elif defined(TARGET_OS_VISION) && TARGET_OS_VISION
+# if defined(TARGET_OS_SIMULATOR) && TARGET_OS_SIMULATOR
+PLATFORM_TRIPLET=arm64-xrsimulator
+# else
+PLATFORM_TRIPLET=arm64-xros
+# endif
// Older macOS SDKs do not define TARGET_OS_OSX
# elif !defined(TARGET_OS_OSX) || TARGET_OS_OSX
PLATFORM_TRIPLET=darwin
diff --git a/Platforms/Apple/.ruff.toml b/Platforms/Apple/.ruff.toml
new file mode 100644
index 00000000000..f5d74fdb6af
--- /dev/null
+++ b/Platforms/Apple/.ruff.toml
@@ -0,0 +1,22 @@
+extend = "../../.ruff.toml" # Inherit the project-wide settings
+
+[format]
+preview = true
+docstring-code-format = true
+
+[lint]
+select = [
+ "C4", # flake8-comprehensions
+ "E", # pycodestyle
+ "F", # pyflakes
+ "I", # isort
+ "ISC", # flake8-implicit-str-concat
+ "LOG", # flake8-logging
+ "PGH", # pygrep-hooks
+ "PT", # flake8-pytest-style
+ "PYI", # flake8-pyi
+ "RUF100", # Ban unused `# noqa` comments
+ "UP", # pyupgrade
+ "W", # pycodestyle
+ "YTT", # flake8-2020
+]
diff --git a/Platforms/Apple/Apple/tvOS/README.rst b/Platforms/Apple/Apple/tvOS/README.rst
new file mode 100644
index 00000000000..1f793252caf
--- /dev/null
+++ b/Platforms/Apple/Apple/tvOS/README.rst
@@ -0,0 +1,108 @@
+=====================
+Python on tvOS README
+=====================
+
+:Authors:
+ Russell Keith-Magee (2023-11)
+
+This document provides a quick overview of some tvOS specific features in the
+Python distribution.
+
+Compilers for building on tvOS
+==============================
+
+Building for tvOS requires the use of Apple's Xcode tooling. It is strongly
+recommended that you use the most recent stable release of Xcode, on the
+most recently released macOS.
+
+tvOS specific arguments to configure
+===================================
+
+* ``--enable-framework[=DIR]``
+
+ This argument specifies the location where the Python.framework will
+ be installed.
+
+* ``--with-framework-name=NAME``
+
+ Specify the name for the python framework, defaults to ``Python``.
+
+
+Building and using Python on tvOS
+=================================
+
+ABIs and Architectures
+----------------------
+
+tvOS apps can be deployed on physical devices, and on the tvOS simulator.
+Although the API used on these devices is identical, the ABI is different - you
+need to link against different libraries for an tvOS device build
+(``appletvos``) or an tvOS simulator build (``appletvsimulator``). Apple uses
+the XCframework format to allow specifying a single dependency that supports
+multiple ABIs. An XCframework is a wrapper around multiple ABI-specific
+frameworks.
+
+tvOS can also support different CPU architectures within each ABI. At present,
+there is only a single support ed architecture on physical devices - ARM64.
+However, the *simulator* supports 2 architectures - ARM64 (for running on Apple
+Silicon machines), and x86_64 (for running on older Intel-based machines.)
+
+To support multiple CPU architectures on a single platform, Apple uses a "fat
+binary" format - a single physical file that contains support for multiple
+architectures.
+
+How do I build Python for tvOS?
+-------------------------------
+
+The Python build system will build a ``Python.framework`` that supports a
+*single* ABI with a *single* architecture. If you want to use Python in an tvOS
+project, you need to:
+
+1. Produce multiple ``Python.framework`` builds, one for each ABI and architecture;
+2. Merge the binaries for each architecture on a given ABI into a single "fat" binary;
+3. Merge the "fat" frameworks for each ABI into a single XCframework.
+
+tvOS builds of Python *must* be constructed as framework builds. To support this,
+you must provide the ``--enable-framework`` flag when configuring the build.