Skip to content

Commit

Permalink
Add iOS testbed, plus Makefile target to invoke it.
Browse files Browse the repository at this point in the history
  • Loading branch information
freakboy3742 committed Feb 26, 2024
1 parent de0b4f9 commit f852d39
Show file tree
Hide file tree
Showing 20 changed files with 1,061 additions and 7 deletions.
13 changes: 13 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ Lib/test/data/*
/Makefile
/Makefile.pre
iOS/Resources/Info.plist
iOS/testbed/build
iOS/testbed/Python.xcframework/ios-arm64/bin
iOS/testbed/Python.xcframework/ios-arm64/include
iOS/testbed/Python.xcframework/ios-arm64/lib
iOS/testbed/Python.xcframework/ios-arm64/Python.framework
iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator/bin
iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator/include
iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator/lib
iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator/Python.framework
iOS/testbed/iOSTestbed/iOSTestbed-Info.plist
iOS/testbed/iOSTestbed.xcodeproj/project.xcworkspace
iOS/testbed/iOSTestbed.xcodeproj/xcuserdata
iOS/testbed/iOSTestbed.xcodeproj/xcshareddata
Mac/Makefile
Mac/PythonLauncher/Info.plist
Mac/PythonLauncher/Makefile
Expand Down
25 changes: 24 additions & 1 deletion Makefile.pre.in
Original file line number Diff line number Diff line change
Expand Up @@ -1994,6 +1994,21 @@ testuniversal: all
$(RUNSHARED) /usr/libexec/oah/translate \
./$(BUILDPYTHON) -E -m test -j 0 -u all $(TESTOPTS)

# Run the test suite on the iOS simulator.
# Must be run on a macOS machine with a full Xcode install that has an iPhone SE
# (3rd edition) simulator available, after running `make install` on a configuration
# with --enable-framework="./iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator"
XCRESULT=./build/$(MULTIARCH).$(shell date +%s).xcresult
.PHONY: testiOS
testiOS:
# Run the test suite for the Xcode project, targeting the iOS simulator.
# If the suite fails, extract and print the console output, then re-raise the failure
if ! xcodebuild test -project ./iOS/testbed/iOSTestbed.xcodeproj -scheme "iOSTestbed" -destination "platform=iOS Simulator,name=iPhone SE (3rd Generation)" -resultBundlePath $(XCRESULT) ; then \
xcrun xcresulttool get --path $(XCRESULT) --id $$(xcrun xcresulttool get --path $(XCRESULT) --format json | $(PYTHON_FOR_BUILD) -c "import sys, json; result = json.load(sys.stdin); print(result['actions']['_values'][0]['actionResult']['logRef']['id']['_value'])"); \
echo ; \
exit 1; \
fi

# Like test, but using --slow-ci which enables all test resources and use
# longer timeout. Run an optional pybuildbot.identify script to include
# information about the build environment.
Expand Down Expand Up @@ -2713,7 +2728,7 @@ frameworkinstallextras:
# subdirectory. The install has put these folders in the same folder as
# Python.framework; Move the headers to their final framework-compatible home.
.PHONY: frameworkinstallmobileheaders
frameworkinstallmobileheaders:
frameworkinstallmobileheaders: frameworkinstallunversionedstructure inclinstall
if test -d $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; then \
echo "Removing old framework headers"; \
rm -rf $(DESTDIR)$(PYTHONFRAMEWORKINSTALLDIR)/Headers; \
Expand Down Expand Up @@ -2848,6 +2863,14 @@ clean-retain-profile: pycremoval
-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-arm64/bin
-rm -rf iOS/testbed/Python.xcframework/ios-arm64/lib
-rm -rf iOS/testbed/Python.xcframework/ios-arm64/include
-rm -rf iOS/testbed/Python.xcframework/ios-arm64/Python.framework
-rm -rf iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator/bin
-rm -rf iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator/lib
-rm -rf iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator/include
-rm -rf iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator/Python.framework

.PHONY: profile-removal
profile-removal:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
A testbed project was added to run the test suite on iOS.
49 changes: 49 additions & 0 deletions configure

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 47 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,52 @@ then
fi
AC_MSG_RESULT(["$MACHDEP"])

# On cross-compile builds, configure will look for a host-specific compiler by
# prepending the user-provided host triple to the required binary name.
#
# On iOS, this results in binaries like "arm64-apple-ios12.0-simulator-gcc",
# which isn't a binary that exists, and isn't very convenient, as it contains the
# iOS version. As the default cross-compiler name won't exist, configure falls
# back to gcc, which *definitely* won't work. We're providing wrapper scripts for
# these tools; the binary names of these scripts are better defaults than "gcc".
# This only requires that the user put the platform scripts folder (e.g.,
# "iOS/Resources/bin") in their path, rather than defining platform-specific
# names/paths for AR, CC, CPP, and CXX explicitly; and if the user forgets to
# either put the platform scripts folder in the path, or specify CC etc,
# configure will fail.
if test -z "$AR"; then
case "$host" in
aarch64-apple-ios*-simulator) AR=arm64-apple-ios-simulator-ar ;;
aarch64-apple-ios*) AR=arm64-apple-ios-ar ;;
x86_64-apple-ios*-simulator) AR=x86_64-apple-ios-simulator-ar ;;
*)
esac
fi
if test -z "$CC"; then
case "$host" in
aarch64-apple-ios*-simulator) CC=arm64-apple-ios-simulator-clang ;;
aarch64-apple-ios*) CC=arm64-apple-ios-clang ;;
x86_64-apple-ios*-simulator) CC=x86_64-apple-ios-simulator-clang ;;
*)
esac
fi
if test -z "$CPP"; then
case "$host" in
aarch64-apple-ios*-simulator) CPP=arm64-apple-ios-simulator-cpp ;;
aarch64-apple-ios*) CPP=arm64-apple-ios-cpp ;;
x86_64-apple-ios*-simulator) CPP=x86_64-apple-ios-simulator-cpp ;;
*)
esac
fi
if test -z "$CXX"; then
case "$host" in
aarch64-apple-ios*-simulator) CXX=arm64-apple-ios-simulator-clang ;;
aarch64-apple-ios*) CXX=arm64-apple-ios-clang ;;
x86_64-apple-ios*-simulator) CXX=x86_64-apple-ios-simulator-clang ;;
*)
esac
fi

AC_MSG_CHECKING([for --enable-universalsdk])
AC_ARG_ENABLE([universalsdk],
AS_HELP_STRING([--enable-universalsdk@<:@=SDKDIR@:>@],
Expand Down Expand Up @@ -598,6 +644,7 @@ AC_ARG_ENABLE([framework],
RESSRCDIR=iOS/Resources
AC_CONFIG_FILES([iOS/Resources/Info.plist])
AC_CONFIG_FILES([iOS/testbed/iOSTestbed/iOSTestbed-Info.plist])
;;
*)
AC_MSG_ERROR([Unknown platform for framework build])
Expand Down
8 changes: 2 additions & 6 deletions iOS/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,8 @@ provide the ``--enable-framework`` flag when configuring the build. The build
also requires the use of cross-compilation. The minimal commands for building
Python for the ARM64 iOS simulator will look something like::

$ export PATH="`pwd`/iOS/Resources/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
$ export PATH="$(pwd)/iOS/Resources/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Apple/usr/bin"
$ ./configure \
AR=arm64-apple-ios-simulator-ar \
CC=arm64-apple-ios-simulator-clang \
CPP=arm64-apple-ios-simulator-cpp \
CXX=arm64-apple-ios-simulator-clang \
--enable-framework=/path/to/install \
--host=arm64-apple-ios-simulator \
--build=arm64-apple-darwin \
Expand Down Expand Up @@ -258,7 +254,7 @@ To run the test suite, configure a Python build for an iOS simulator (i.e.,
``--host=arm64-apple-ios-simulator`` or ``--host=x86_64-apple-ios-simulator``
), setting the framework location to the testbed project::

--enable-framework="./iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator"
--enable-framework="$(pwd)/iOS/testbed/Python.xcframework/ios-arm64_x86_64-simulator"

Then run ``make all install testiOS``. This will build an iOS framework for your
chosen architecture, install the Python iOS framework into the testbed project,
Expand Down
44 changes: 44 additions & 0 deletions iOS/testbed/Python.xcframework/Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>AvailableLibraries</key>
<array>
<dict>
<key>BinaryPath</key>
<string>Python.framework/Python</string>
<key>LibraryIdentifier</key>
<string>ios-arm64</string>
<key>LibraryPath</key>
<string>Python.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
</dict>
<dict>
<key>BinaryPath</key>
<string>Python.framework/Python</string>
<key>LibraryIdentifier</key>
<string>ios-arm64_x86_64-simulator</string>
<key>LibraryPath</key>
<string>Python.framework</string>
<key>SupportedArchitectures</key>
<array>
<string>arm64</string>
<string>x86_64</string>
</array>
<key>SupportedPlatform</key>
<string>ios</string>
<key>SupportedPlatformVariant</key>
<string>simulator</string>
</dict>
</array>
<key>CFBundlePackageType</key>
<string>XFWK</string>
<key>XCFrameworkFormatVersion</key>
<string>1.0</string>
</dict>
</plist>
4 changes: 4 additions & 0 deletions iOS/testbed/Python.xcframework/ios-arm64/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This directory is intentionally empty.

It should be used as a target for `--enable-framework` when compiling an iOS on-device
build for testing purposes.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This directory is intentionally empty.

It should be used as a target for `--enable-framework` when compiling an iOS simulator
build for testing purposes (either x86_64 or ARM64).
Loading

0 comments on commit f852d39

Please sign in to comment.