|
1 | | -Python Apple Support |
2 | | -==================== |
| 1 | +Darwin (iOS / macOS) Python builds |
| 2 | +================================== |
3 | 3 |
|
4 | | -Building iOS and macOS "support" builds out of https://github.com/beeware/Python-Apple-support to use with Flet. |
| 4 | +Builds embeddable iOS and macOS Python runtimes for Flet, packaged for the Dart/Flutter |
| 5 | +side and for `mobile-forge <https://github.com/flet-dev/mobile-forge>`__. |
| 6 | + |
| 7 | +Both ``build_ios.py`` and ``build_macos.py`` emit the same normalized layout, which the |
| 8 | +``package-*-for-dart.sh`` scripts (and the mobile-forge tarball) consume:: |
| 9 | + |
| 10 | + install/iOS/<target>/python-<ver>/... # per-arch installs incl. lib-dynload |
| 11 | + install/macOS/macosx/python-<ver>/Python.framework |
| 12 | + support/<short>/iOS/Python.xcframework # device + fat-simulator slices |
| 13 | + support/<short>/macOS/Python.xcframework # universal2 (macos-arm64_x86_64) |
| 14 | + |
| 15 | +where ``<target>`` is ``iphoneos.arm64``, ``iphonesimulator.arm64`` or |
| 16 | +``iphonesimulator.x86_64``. |
| 17 | + |
| 18 | +iOS — ``build_ios.py <full-version>`` |
| 19 | +------------------------------------- |
| 20 | + |
| 21 | +Every version is built with the **same** mechanism — CPython's in-tree ``Apple`` build |
| 22 | +tool (``python Apple build iOS``) — then ``cross-build/`` is reshaped into the layout above: |
| 23 | + |
| 24 | +* **3.14+** — the ``Apple/`` tooling is native; build straight from the source tarball. |
| 25 | +* **3.13 / 3.12** — the tooling (and, for 3.12, the PEP 730 iOS runtime) isn't upstream |
| 26 | + yet, so a vendored back-port patch (``ios_patches/<short>/Python.patch``, see that |
| 27 | + directory's README) is applied first to add it. No dependency on beeware's |
| 28 | + Python-Apple-support repo. |
| 29 | + |
| 30 | +The Apple tool downloads its own pre-compiled C deps (from |
| 31 | +`cpython-apple-source-deps <https://github.com/beeware/cpython-apple-source-deps>`__ — the |
| 32 | +URL CPython itself hard-codes, for every version), builds all slices, and creates the |
| 33 | +xcframework. Output is tee'd to ``build/iOS/build-ios-<ver>.log``. |
| 34 | + |
| 35 | +The reshape also rebuilds the ``install``/``support`` tree that |
| 36 | +`mobile-forge <https://github.com/flet-dev/mobile-forge>`__ consumes (the |
| 37 | +``python-ios-mobile-forge-<short>.tar.gz`` artifact): per-arch ``install/iOS/<arch>/<dep>-<ver>/`` |
| 38 | +dirs (re-extracted from the deps the Apple tool downloaded) + a ``support/<short>/iOS/VERSIONS`` |
| 39 | +listing those versions, and in each xcframework slice a stub ``bin/python<short>`` plus the |
| 40 | +``_sysconfigdata`` under ``platform-config/<arch>-<sdk>/`` — the spots mobile-forge's |
| 41 | +``crossenv`` setup looks for. (The dart packager excludes all of these from its bundle.) |
| 42 | + |
| 43 | +macOS — ``build_macos.py <full-version>`` |
| 44 | +----------------------------------------- |
| 45 | + |
| 46 | +Builds a universal2 ``Python.framework`` **from source** for all versions, then makes it |
| 47 | +relocatable (``@rpath``), codesigns it, and wraps it in an xcframework. Building from |
| 48 | +source (rather than re-bundling python.org's official ``.pkg``) means we get the exact |
| 49 | +micro version even when no macOS installer was published for it. |
| 50 | + |
| 51 | +The macOS SDK supplies headers for bz2/sqlite/zlib/libffi and CPython bundles libmpdec, |
| 52 | +but it ships **no OpenSSL** and **no lzma.h** (only ``liblzma.dylib``), so **OpenSSL** and |
| 53 | +**xz/liblzma** are built universal2 from source here (``--openssl-version`` / ``--xz-version``). |
| 54 | +To match the official/beeware layout, OpenSSL is built **shared** and bundled into the |
| 55 | +framework (``Versions/<short>/lib/lib{ssl,crypto}.3.dylib``) with ``@rpath`` install names, |
| 56 | +which ``_ssl``/``_hashlib`` reference (the embedding host — e.g. serious_python — provides |
| 57 | +the rpath, exactly as the released artifact does); xz is linked **statically** into |
| 58 | +``_lzma``. On 3.14+, libzstd is also built from source (``--zstd-version``) and linked |
| 59 | +statically into ``_zstd`` (new in 3.14). All binaries are stripped (``strip -x``) before |
| 60 | +codesigning. Pass |
| 61 | +``--app-store-compliance`` to apply ``macos_support/app-store-compliance.patch`` (off by |
| 62 | +default; only for Mac App Store). Full build output is tee'd to |
| 63 | +``build/macOS/build-macos-<ver>.log``. |
| 64 | + |
| 65 | +Packaging |
| 66 | +--------- |
| 67 | + |
| 68 | +``package-ios-for-dart.sh . <short>`` and ``package-macos-for-dart.sh . <short>`` turn the |
| 69 | +normalized layout into the Dart-consumable ``dist/python-{ios,macos}-dart-<short>.tar.gz`` |
| 70 | +archives, reusing ``xcframework_utils.sh``, ``Modules/`` and the ``*.exclude`` lists. |
| 71 | + |
| 72 | +This whole flow is driven in CI by ``.github/workflows/build-python-version.yml``. |
0 commit comments