Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 12 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ Lib/test/data/*
/Makefile
/Makefile.pre
iOS/Resources/Info.plist
iOS/testbed/build
iOS/testbed/Python.xcframework/ios-*/bin
iOS/testbed/Python.xcframework/ios-*/include
iOS/testbed/Python.xcframework/ios-*/lib
iOS/testbed/Python.xcframework/ios-*/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
21 changes: 20 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=$(srcdir)/build/$(MULTIARCH).$(shell date +%s).xcresult
.PHONY: testiOS
testiOS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.PHONY: testiOS
testiOS:
.PHONY: test-iOS
test-iOS:

?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thinking here was to be consistent with testuniversal, cleantest, buildbottest et al. However, I'm happy to change this name if there's a general preference for test-iOS over testiOS.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All existing makefile targets are lower-case, even acronyms like multissltest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's true... although I suspect I'd twitch every time I need to spell it with capitalization that breaks the branding guide 😀

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated this to 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 $(srcdir)/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,10 @@ 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-*/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

.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
Loading