PEP 730: CPython Adds iOS Support

BYMark Howell 2 years ago5 MINS READ
PEP 730: CPython Adds iOS Support

Today in Edworking News we want to talk about PEP 730 – Adding iOS as a Supported Platform

Copy link Abstract

This PEP proposes adding iOS as a supported platform in CPython. The initial goal is to achieve Tier 3 support for Python 3.13. This PEP describes the technical aspects of the changes that are required to support iOS. It also describes the project management concerns related to the adoption of iOS as a Tier 3 platform.

Copy link Motivation

Over the last 15 years, mobile platforms have become increasingly important parts of the computing landscape. iOS is one of two operating systems that control the vast majority of these devices. However, there is no official support for iOS in CPython. The BeeWare Project and Kivy have both supported iOS for almost 10 years. This support has been able to generate applications that have been accepted for publication in the iOS App Store. This demonstrates the technical feasibility of iOS support.
It is important for the future of Python as a language that it is able to be used on any hardware or OS that has widespread adoption. If Python cannot be used on a platform that has widespread use, adoption of the language will be impacted as potential users will adopt other languages that do provide support for these platforms.

Python adds iOS as a supported platform (Tier 3)

Copy link Development Landscape

  • iOS provides a single API, but two distinct ABIs: `iphoneos` (physical devices) and `iphonesimulator`.
  • iOS supports "fat" binaries, containing multiple CPU architectures, but cannot span ABIs. For distribution, the "XCframework" structure is used.
  • iOS runs on a Darwin kernel, similar to macOS, but needs differentiation at an implementation level due to platform differences.
  • Apple's references to iPadOS in marketing have no development implications, as binaries for `iphoneos` or `iphonesimulator` ABIs can be deployed on iPads.
  • Other Apple platforms like tvOS, watchOS, and visionOS use different ABIs and are not covered by this PEP.

Copy link POSIX Compliance

  • iOS is broadly a POSIX platform but with significant restrictions:
    - No multiprocess support (`fork` and `spawn` exist but do not function as expected).
    - Threading is supported, but there are significant limitations to socket handling.

Copy link Dynamic Libraries

  • Apps can use dynamically loaded libraries with strict guidelines on how content is packaged for use on iOS.
  • Binary modules cannot be stored in usual directories like lib-dynload; they must be in the app’s Frameworks folder.

Copy link Console and Interactive Usage

  • A traditional CPython REPL or interactive "python.exe" is not viable because mobile devices do not provide a TTY-style console with stdin, stdout, or stderr.
  • An embedded distribution suitable for native iOS applications with IDE-style interfaces is the goal.
Edworking
All your work in one place
All-in-one platform for your team and your work. Register now for Free.
Get Started Now

Copy link Specification

Copy link Platform Identification

  • `sys.platform` will identify as "ios" on both simulator and physical devices.
  • ABI and CPU architecture details will be identified by `sys.implementation._multiarch`.
  • A new method, `platform.ios_ver()`, will provide iOS version information.

Copy link Subprocess Support

  • iOS will disable subprocesses, raising exceptions if attempts are made to start subprocesses, and `os.fork` and `os.spawn` calls will raise an `OSError`.

Copy link Dynamic Module Loading

  • Import requests for Python binary modules will be converted to Framework locations.

Copy link Compilation

  • The dynamically-linkable `libpython3.x.dylib` is the only supported binary format.
  • Compilation requires using cross-platform tooling in CPython’s configure build system.
  • An Xcode project will be provided for running the CPython test suite.

Copy link Distribution

  • Adding iOS as a Tier 3 platform requires support for compiling an iOS-compatible build from an unpatched CPython code checkout, not official end-user iOS artifacts.

Copy link CI Resources

  • Anaconda has offered to provide hardware to run iOS buildbots.
  • GitHub Actions can host iOS simulators on their macOS machines.

Copy link Packaging

  • iOS will not use a universal wheel format. Individual ABI-arch combination wheels will be provided.
Edworking
All your work in one place
All-in-one platform for your team and your work. Register now for Free.
Get Started Now

Copy link PEP 11 Update

  • PEP 11 will be updated to include iOS ABIs. Ned Deily will serve as the initial core team contact.

Copy link Backwards Compatibility

  • Adding iOS support does not introduce backwards compatibility concerns to CPython.
  • There may be some implications for projects that have historically provided CPython support (BeeWare and Kivy).

Copy link Security Implications

  • Adding iOS does not introduce any new security implications.

Copy link How to Teach This

  • Documentation and tutorials demonstrating how end-users can add iOS support to their Xcode projects will be provided.

Copy link Reference Implementation

The BeeWare Python-Apple-support repository, Briefcase, and Toga Testbed are examples of such implementations.

  • Xcode simulation and tooling integration for testing

  • Edworking is the best and smartest decision for SMEs and startups to be more productive. Edworking is a FREE superapp of productivity that combines all you need for work powered by AI in the same superapp, connecting Task Management, Docs, Chat, Videocall, and File Management. Save money today by not paying for Slack, Trello, Dropbox, Zoom, and Notion.
  • Copy link Remember these 3 key ideas for your startup:

    1. Expand to iOS: Leverage the new capability to run Python on iOS platforms, tapping into one of the largest mobile operating system user bases. Official support can dramatically increase your application's reach and adoption.
    2. Adapt to Framework Constraints: Be aware of the strict packaging and dynamic library requirements for iOS applications, which can affect the way you structure your app’s libraries. This ensures smooth functionality and compliance with Apple's guidelines.
    3. Integrate and Automate: Use tools like GitHub Actions and Anaconda’s buildbot resources to automate your build and testing processes, maximizing efficiency and reliability in your development workflow.
      For more detailed comprehension and to explore potential implementations, visit the Python PEP 730.

      This approach toward integrating iOS opens up new avenues for Python developers to delve into the mobile domain, potentially expanding the Python ecosystem and enriching both developer and user experiences.
      For more details, see the original source.
    Mark Howell

    About the Author: Mark Howell

    LinkedIn

    Mark Howell is a talented content writer for Edworking's blog, consistently producing high-quality articles on a daily basis. As a Sales Representative, he brings a unique perspective to his writing, providing valuable insights and actionable advice for readers in the education industry. With a keen eye for detail and a passion for sharing knowledge, Mark is an indispensable member of the Edworking team. His expertise in task management ensures that he is always on top of his assignments and meets strict deadlines. Furthermore, Mark's skills in project management enable him to collaborate effectively with colleagues, contributing to the team's overall success and growth. As a reliable and diligent professional, Mark Howell continues to elevate Edworking's blog and brand with his well-researched and engaging content.

    Startups

    Try Edworking Background

    A new way to work from anywhere, for everyone for Free!

    Get Started Now