Skip to content

Add support for Android and iOS. - #3931

Open
freakboy3742 wants to merge 4 commits into
tornadoweb:masterfrom
freakboy3742:mobile-support
Open

freakboy3742 wants to merge 4 commits into
tornadoweb:masterfrom
freakboy3742:mobile-support

Conversation

@freakboy3742

Copy link
Copy Markdown

Adds a build configuration, plus some test skips, to support running tornado on iOS and Android.

This is mostly of interest for Electron-style apps - i.e., apps that are a single-site web browser and a web server wrapped into one bundle. Toga's Positron plugin recently added support for Panel apps, which use Tornado as a web server.

The CI configuration is a fairly vanilla cibuildwheel configuration for iOS. This will generate ARM64 device, ARM64 simulator and x86-64 simulator wheels on iOS; and ARM64 and x86-64 wheels for Android. This configuration will only run the test suite with the iOS ARM64 simulator, and the Android x86-64 emulator. This approach is consistent with the approach taken with other projects:

  • it's not possible to run iOS device wheels in CI
  • x86-64 iOS simulator resources are slow
  • it's not possible to run the Android ARM64 emulator in CI.

The test skips are required because:

  1. iOS and Android don't support the use of subprocesses
  2. iOS and Android don't support the getpass module in the standard library
  3. There are path length limits on sockets that the test configuration hits.

@bdarnell

Copy link
Copy Markdown
Member

Interesting. I don't think android and ios can ever be more than "experimental" platforms to us, but this was less invasive than I expected so I'm open to it.

How long do the new CI jobs take to run?

I'm a little worried about having quirky platforms that are only tested in build.yml and not test.yml (build.yml is not run on ever PR, only when we're preparing a release build, which is an awkward time to find out that something's broken). We don't test every cpu architecture in test.yml but the different CPU architectures have never been a problem for us. If it's not too expensive I'd like to add a job for each platform (just one python version) to test.yml like we've done for windows and mac.

@freakboy3742

Copy link
Copy Markdown
Author

How long do the new CI jobs take to run?

On my local machine, takes about 3 minutes to build all three iOS wheels, and test them on 3.13, 3.14 and 3.15 - about 10s per wheels, and 50s per test run. Under CI conditions, it will likely be a little slower because the simulator isn’t warmed up - maybe add another couple of minutes for that. Android performance is about the same.

I'm a little worried about having quirky platforms that are only tested in build.yml and not test.yml (build.yml is not run on ever PR, only when we're preparing a release build, which is an awkward time to find out that something's broken). We don't test every cpu architecture in test.yml but the different CPU architectures have never been a problem for us. If it's not too expensive I'd like to add a job for each platform (just one python version) to test.yml like we've done for windows and mac.

I missed the trigger for build was only for releases. I've just added a test CI target; let me know if that’s sufficient.

@freakboy3742

Copy link
Copy Markdown
Author

How long do the new CI jobs take to run?

On my local machine, takes about 3 minutes to build all three iOS wheels, and test them on 3.13, 3.14 and 3.15 - about 10s per wheels, and 50s per test run. Under CI conditions, it will likely be a little slower because the simulator isn’t warmed up - maybe add another couple of minutes for that. Android performance is about the same.

Answering this question based on the CI update to this PR: ~8 minutes for iOS; ~5 minutes for Android.

@bdarnell

Copy link
Copy Markdown
Member

OK. That does make these the longest jobs in the test CI config (next slowest is just over 3 minutes), and nearly a quarter of the total CI minutes (53). I'm not sure I'm willing to slow CI iteration speed down that much for these platforms. (Looking at the ios build, actually running the tests takes a reasonable 70 seconds. There's one easy win in that we're building two ios wheels but only need the simulator wheel in this context. Fixing that only saves 30s. It's not clear from the logs where the other ~6 minutes go)

How important are prebuilt wheels for these election-like platforms? Are they able to build from source instead? It seems like the library itself has just worked by accident on these platforms whether we do anything to support it on our side, so maybe we can get away with fixing things on an ad-hoc basis whenever a breakage is detected.

@freakboy3742

Copy link
Copy Markdown
Author

It's not clear from the logs where the other ~6 minutes go)

It's starting the iOS simulator. GitHub Actions doesn't ship a "pre-warmed" iOS simulator, so you essentially get the "first boot" experience on every PR job. Unfortunately, I haven't found any way to speed this up or cache the machine state.

How important are prebuilt wheels for these election-like platforms? Are they able to build from source instead? It seems like the library itself has just worked by accident on these platforms whether we do anything to support it on our side, so maybe we can get away with fixing things on an ad-hoc basis whenever a breakage is detected.

So - with the caveat that I have a vested interest here (I'm the CPython maintainer for iOS and Android) - I'd say it's fairly important. You could make the same argument for any wheels - after all, can't just you just build any wheel from source? It's certainly possible - it's just really inconvenient, and it's an impediment to usage in practice, because it's really easy for a local compilation environment to be just misaligned enough that you get build failures. And if a user can't "just install the wheel", that's one more thing to get in the way of them using the package in their app - and from my perspective, one more reason why they conclude that using Python on iOS/Android is Just Too Hard.

Putting another option out there - build and release the wheels, but don't actively test them as part of every CI run. As you note, there's not a whole lot of complexity to the port - it's mostly a build configuration change - so the risk of a breakage is low (not zero mind, but certainly lower than it would be for a C-module heavy package like NumPy or Pillow). You could supplement this by testing intermittently (e.g., on a weekly cron job), or only as part of the release cycle (it would be annoying to have a failure manifest in a release pipeline, but again - if the risk is low... 🤷 )

This branch has not been deployed

No deployments
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.

2 participants