Skip to content

gh-114099 - Add iOS testbed, plus Makefile target to invoke it.#115930

Merged
ned-deily merged 12 commits intopython:mainfrom
freakboy3742:ios-testbed
Mar 7, 2024
Merged

gh-114099 - Add iOS testbed, plus Makefile target to invoke it.#115930
ned-deily merged 12 commits intopython:mainfrom
freakboy3742:ios-testbed

Conversation

@freakboy3742
Copy link
Contributor

@freakboy3742 freakboy3742 commented Feb 26, 2024

Part of the PEP 730 work to add iOS support.

This PR adds an iOS testbed project, plus the Makefile target to support running it from the command line. It is the last of the code that was originally submitted as #115063.

The bulk of the PR is an iOS Xcode project; open iOS/testbed/iOSTestbed.xcodeproj from the command line will open the project in Xcode. The project itself is a bare stub app with no UI, and an XCTest test suite that contains 1 test - "run the CPython test suite"; the XCTest passes or fails depending on the overall success or failure of the CPython test suite.

Most of the project files are as generated by the new project wizard; differences of note include:

  • iOS/testbed/iOSTestbed/main.m marks some signals as ignored that the CPython test suite exercises, but iOS doesn't like to be unhandled.
  • iOS/testbed/iOSTestbedTests/iOSTestbedTests.m is an Xcode test suite with a single test that initialises a CPython interpreter and runs the test module. Command line options need to be passed in by modifying the argv array at the start of the file, as there's no real analog for a test suite command line (at least, not that I've found)
  • Build scripts have been added to post-process the standard library into "framework" form.
  • The build setting for Enable Testability has been set to Yes; this prevents stripping of binaries in release configurations. This is required because an iOS app may not link against symbols, but it will use them.
  • The build setting for User Script Sandboxing has been set to No. This allows the post-processing scripts to modify and sign framework binaries.

There are 2 other changes:

  • An extra dependency was added to the frameworkinstallmobileheaders target; I discovered that parallel make install builds would fail because it would try to correct the header install before actually installing the headers.
  • The configure script has been modified to use the iOS wrapper binaries rather than gcc as a default compiler when CC et al aren't defined. This makes configure easier to invoke (as you just need to have the path correct), and makes the failure mode more predictable (as an attempt to compile with gcc will get quite far along before failing). Manually specifying overrides for CC et al remains available as an option.

Running the test suite

As of this PR, it is possible to build CPython as a framework, and start the test suite.

The new Makefile target is make testios. This target will run the test suite on an iPhone SE 3rd edition; this is a simulator that is reliably available, as it's a model that doesn't get updated all that often.

Running the testbed requires that an iOS framework build for a simulator target has been compiled and installed into the stub Python.xcframework folder that the testbed project contains. The minimum invocation for running the test suite is:

export PATH="$(pwd)/iOS/Resources/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin" 
./configure --host=arm64-apple-ios12.0-simulator --build=arm64-apple-darwin --with-build-python=/path/to/python3.13 --enable-framework
make clean
make -j4 all
make testios

(adjusting as necessary to point to a appropriate build-python). A cold start of the iOS simulator takes 2-3 minutes, and for most of that time, the simulator appears to be doing nothing. Don't be alarmed when the console output for the test run says Testing started and then appears to do nothing for a long time. If you're running the test suite from inside Xcode, it's a lot faster once the simulator is warm.

However, if you invoke this target, the test suite will currently fail because it can't find binary modules at runtime. Correcting this will be the subject of the next PR.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants