Skip to content

Commit a76ec35

Browse files
miss-islingtonfreakboy3742hugovk
committed
[3.13] pythongh-140189: Add CI job to test iOS builds. (pythonGH-140190) (python#140696)
Adds a CI configuration to test iOS builds on every build. (cherry picked from commit f4e6370) Co-authored-by: Russell Keith-Magee <russell@keith-magee.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
1 parent 86c5943 commit a76ec35

File tree

4 files changed

+76
-9
lines changed

4 files changed

+76
-9
lines changed

.github/workflows/build.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,29 @@ jobs:
354354
- name: Build and test
355355
run: ./Android/android.py ci --fast-ci ${{ matrix.arch }}-linux-android
356356

357+
build-ios:
358+
name: iOS
359+
needs: build-context
360+
if: needs.build-context.outputs.run-tests == 'true'
361+
timeout-minutes: 60
362+
runs-on: macos-15
363+
steps:
364+
- uses: actions/checkout@v4
365+
with:
366+
persist-credentials: false
367+
368+
# GitHub recommends explicitly selecting the desired Xcode version:
369+
# https://github.com/actions/runner-images/issues/12541#issuecomment-3083850140
370+
# This became a necessity as a result of
371+
# https://github.com/actions/runner-images/issues/12541 and
372+
# https://github.com/actions/runner-images/issues/12751.
373+
- name: Select Xcode version
374+
run: |
375+
sudo xcode-select --switch /Applications/Xcode_16.4.app
376+
377+
- name: Build and test
378+
run: python3 Apple ci iOS --fast-ci --simulator 'iPhone 16e,OS=18.5'
379+
357380
build-wasi:
358381
name: 'WASI'
359382
needs: build-context
@@ -595,6 +618,7 @@ jobs:
595618
- build-ubuntu
596619
- build-ubuntu-ssltests
597620
- build-android
621+
- build-ios
598622
- build-wasi
599623
- test-hypothesis
600624
- build-asan
@@ -628,6 +652,7 @@ jobs:
628652
build-ubuntu,
629653
build-ubuntu-ssltests,
630654
build-android,
655+
build-ios,
631656
build-wasi,
632657
test-hypothesis,
633658
build-asan,

Apple/__main__.py

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ def test(context: argparse.Namespace, host: str | None = None) -> None:
823823
+ [
824824
"--",
825825
"test",
826-
"--slow-ci" if context.slow else "--fast-ci",
826+
f"--{context.ci_mode}-ci",
827827
"--single-process",
828828
"--no-randomize",
829829
# Timeout handling requires subprocesses; explicitly setting
@@ -836,11 +836,39 @@ def test(context: argparse.Namespace, host: str | None = None) -> None:
836836
)
837837

838838

839+
def apple_sim_host(platform_name: str) -> str:
840+
"""Determine the native simulator target for this platform."""
841+
for _, slice_parts in HOSTS[platform_name].items():
842+
for host_triple in slice_parts:
843+
parts = host_triple.split('-')
844+
if parts[0] == platform.machine() and parts[-1] == "simulator":
845+
return host_triple
846+
847+
raise KeyError(platform_name)
848+
849+
839850
def ci(context: argparse.Namespace) -> None:
840-
"""The implementation of the "ci" command."""
851+
"""The implementation of the "ci" command.
852+
853+
In "Fast" mode, this compiles the build python, and the simulator for the
854+
build machine's architecture; and runs the test suite with `--fast-ci`
855+
configuration.
856+
857+
In "Slow" mode, it compiles the build python, plus all candidate
858+
architectures (both device and simulator); then runs the test suite with
859+
`--slow-ci` configuration.
860+
"""
841861
clean(context, "all")
842-
build(context, host="all")
843-
test(context, host="all")
862+
if context.ci_mode == "slow":
863+
# In slow mode, build and test the full XCframework
864+
build(context, host="all")
865+
test(context, host="all")
866+
else:
867+
# In fast mode, just build the simulator platform.
868+
sim_host = apple_sim_host(context.platform)
869+
build(context, host="build")
870+
build(context, host=sim_host)
871+
test(context, host=sim_host)
844872

845873

846874
def parse_args() -> argparse.Namespace:
@@ -947,11 +975,13 @@ def parse_args() -> argparse.Namespace:
947975
"an ARM64 iPhone 16 Pro simulator running iOS 26.0."
948976
),
949977
)
950-
cmd.add_argument(
951-
"--slow",
952-
action="store_true",
953-
help="Run tests with --slow-ci options.",
954-
)
978+
group = cmd.add_mutually_exclusive_group()
979+
group.add_argument(
980+
"--fast-ci", action="store_const", dest="ci_mode", const="fast",
981+
help="Add test arguments for GitHub Actions")
982+
group.add_argument(
983+
"--slow-ci", action="store_const", dest="ci_mode", const="slow",
984+
help="Add test arguments for buildbots")
955985

956986
for subcommand in [configure_build, configure_host, build, ci]:
957987
subcommand.add_argument(
@@ -1012,4 +1042,10 @@ def signal_handler(*args):
10121042

10131043

10141044
if __name__ == "__main__":
1045+
# Under the buildbot, stdout is not a TTY, but we must still flush after
1046+
# every line to make sure our output appears in the correct order relative
1047+
# to the output of our subprocesses.
1048+
for stream in [sys.stdout, sys.stderr]:
1049+
stream.reconfigure(line_buffering=True)
1050+
10151051
main()

Apple/testbed/__main__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,4 +413,9 @@ def main():
413413

414414

415415
if __name__ == "__main__":
416+
# Under the buildbot, stdout is not a TTY, but we must still flush after
417+
# every line to make sure our output appears in the correct order relative
418+
# to the output of our subprocesses.
419+
for stream in [sys.stdout, sys.stderr]:
420+
stream.reconfigure(line_buffering=True)
416421
main()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
iOS builds were added to CI.

0 commit comments

Comments
 (0)