Skip to content

Commit bb30722

Browse files
committed
pythongh-156109: Make non-framework iOS builds self-consistent
A non-framework iOS build has no framework for extension modules to link against, and is statically linked into the app binary, so it cannot load extension modules at runtime. Mirror what WASI already does for the same reason: * force MODULE_BUILDTYPE=static for iOS builds without a framework, and error out if MODULE_BUILDTYPE=shared was requested explicitly; * mark the test modules that must be built as shared libraries (see Modules/Setup.stdlib.in) as unavailable, so that the build no longer requires --disable-test-modules. Framework builds are unaffected. Document that this configuration does not support loadable extension modules or binary wheels. configure was edited by hand; it needs to be regenerated with the pinned autoconf container before merging.
1 parent fccc461 commit bb30722

5 files changed

Lines changed: 87 additions & 6 deletions

File tree

‎Doc/using/configure.rst‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,6 +1338,22 @@ See :source:`Platforms/Apple/iOS/README.md`.
13381338
Create a Python.framework. Unlike macOS, the *INSTALLDIR* argument
13391339
specifying the installation path is mandatory.
13401340

1341+
.. option:: --disable-framework
1342+
1343+
Build a static ``libpython`` for embedding directly in an app binary,
1344+
instead of a ``Python.framework``. This option requires
1345+
``--disable-shared``, and must be requested explicitly: an iOS build that
1346+
specifies neither ``--enable-framework`` nor ``--disable-framework`` is an
1347+
error.
1348+
1349+
A non-framework build cannot load extension modules at runtime, so every
1350+
extension module must be compiled into ``libpython``
1351+
(``MODULE_BUILDTYPE=static`` is enforced), binary wheels are not supported,
1352+
and the standard library test modules that must be built as shared
1353+
libraries are marked as unavailable.
1354+
1355+
.. versionadded:: 3.16
1356+
13411357
.. option:: --with-framework-name=FRAMEWORK
13421358

13431359
Specify the name for the framework (default: ``Python``).
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
iOS builds may now be configured with ``--disable-framework`` when combined with
22
``--disable-shared``, producing a static ``libpython`` for embedding in an app
3-
binary. A shared iOS build must still be a framework build.
3+
binary. In this configuration all extension modules are linked into
4+
``libpython``, and the test modules that must be built as shared libraries are
5+
marked as unavailable. A shared iOS build must still be a framework build.

‎Platforms/Apple/iOS/README.md‎

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,23 @@ Python build for a single framework, the following options are available.
9090
installed. If `DIR` is not specified, the framework will be installed into
9191
a subdirectory of the `iOS/Frameworks` folder.
9292

93-
This argument *must* be provided when configuring iOS builds. iOS does not
94-
support non-framework builds.
93+
Either this argument or `--disable-framework` *must* be provided when
94+
configuring iOS builds; there is no default.
95+
96+
* `--disable-framework`
97+
98+
Build a static `libpython` for embedding directly in an app binary, instead
99+
of a `Python.framework`. This option requires `--disable-shared`, and must be
100+
requested explicitly.
101+
102+
A non-framework build cannot load extension modules at runtime, as there is
103+
no framework for those modules to link against. Every extension module must
104+
therefore be compiled into `libpython`; `MODULE_BUILDTYPE=static` is enforced
105+
for this configuration, binary wheels are not supported, and the standard
106+
library test modules that must be built as shared libraries are marked as
107+
unavailable. This configuration is only useful if you are embedding Python in
108+
an app that links `libpython` at compile time, and are able to compile any
109+
third-party extension modules into that app as well.
95110

96111
* `--with-framework-name=NAME`
97112

@@ -113,9 +128,10 @@ framework to contain non-library content, so the iOS build will produce a
113128
The `lib` folder will be needed at runtime to support the Python library.
114129

115130
If you want to use Python in a real iOS project, you need to produce multiple
116-
`Python.framework` builds, one for each ABI and architecture. iOS builds of
117-
Python *must* be constructed as framework builds. To support this, you must
118-
provide the `--enable-framework` flag when configuring the build. The build
131+
`Python.framework` builds, one for each ABI and architecture. Unless you are
132+
statically linking Python into your app (see `--disable-framework` above), iOS
133+
builds of Python *must* be constructed as framework builds. To support this,
134+
you must provide the `--enable-framework` flag when configuring the build. The build
119135
also requires the use of cross-compilation. The minimal commands for building
120136
Python for the ARM64 iOS simulator will look something like:
121137
```

‎configure‎

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎configure.ac‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8308,6 +8308,21 @@ AS_CASE([$ac_sys_system],
83088308
[spwd],
83098309
[syslog],
83108310
)
8311+
dnl A non-framework build is statically linked into the app binary, so it
8312+
dnl cannot load extension modules at runtime. Test modules that must be
8313+
dnl compiled as shared libraries are not supported
8314+
dnl (see Modules/Setup.stdlib.in).
8315+
AS_IF([test -z "$PYTHONFRAMEWORK"], [
8316+
PY_STDLIB_MOD_SET_NA(
8317+
[_ctypes_test],
8318+
[_testimportmultiple],
8319+
[_testmultiphase],
8320+
[_testsinglephase],
8321+
[xxlimited],
8322+
[xxlimited_35],
8323+
[xxlimited_3_13],
8324+
)
8325+
])
83118326
],
83128327
[CYGWIN*], [PY_STDLIB_MOD_SET_NA([_scproxy])],
83138328
[QNX*], [PY_STDLIB_MOD_SET_NA([_scproxy])],
@@ -8386,6 +8401,13 @@ AS_CASE([$ac_sys_system],
83868401
dnl AC_MSG_NOTICE([m4_set_list([_PY_STDLIB_MOD_SET_NA])])
83878402

83888403
dnl Default value for Modules/Setup.stdlib build type
8404+
dnl A non-framework iOS build has no framework for extension modules to link
8405+
dnl against, so every extension module must be linked into libpython.
8406+
AS_IF([test "$ac_sys_system" = "iOS" && test -z "$PYTHONFRAMEWORK"], [
8407+
AS_VAR_IF([MODULE_BUILDTYPE], [shared],
8408+
[AC_MSG_ERROR([non-framework iOS builds require MODULE_BUILDTYPE=static])])
8409+
MODULE_BUILDTYPE=static
8410+
])
83898411
AS_CASE([$host_cpu],
83908412
[wasm32|wasm64], [MODULE_BUILDTYPE=static],
83918413
[MODULE_BUILDTYPE=${MODULE_BUILDTYPE:-shared}]

0 commit comments

Comments
 (0)