Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds support for Android / iOS wheels, thanks to the excellent updates of cibuildwheel 3.0.0 and 3.1.0 (specifically, PR #2349 for Android and PR #2286 for iOS).
Updating the GitHub Actions workflow to accommodate these platforms was a bit challenging, so I'm sharing my experience here. I hope it may help other engineers in the future, when they face similar issues. My own code is available at https://github.com/hajimes/mmh3/blob/master/.github/workflows/wheels.yml.
Start with the official documentation
See the cibuildwheel platforms and options guides:
Also, consult their YAML example:
Explicitly declare
platform(usually in the build matrix)For standard platforms (
linux,windows,macos), cibuildwheel infers this automatically from runner's OS. But forandroidandios, you must declare it manually. Then, setCIBW_PLATFORM: ${{ matrix.platform || 'auto' }}to ensure proper platform selection. This instructs cibuildwheel to use theplatformvalue specified in the build matrix when available; otherwise, it falls back to the runner's OS.Configure Android/iOS-specific environment variables for testing
For example, if using
pytestand your tests are under./tests, define:Standard platforms usually use
pytest {project}as the testing command with cibuildwheel. However, Android/iOS builds cannot resolve the{project}placeholder, so explicit paths are required. Also note:CIBW_TEST_SOURCES_*must be defined, even if test file paths are stated withinCIBW_TEST_COMMAND_*.For Android-Intel builds (that is,
*-android_x86_64), use a Linux runner (e.g.,ubuntu-latest) and enable the kernel-based virtual machine (KVM) for testing.If you don't specify this, testing will fail (as of cibuildwheel 3.1.1). You can just copy and paste the code from https://github.blog/changelog/2024-04-02-github-actions-hardware-accelerated-android-virtualization-now-available/. Also, see https://github.com/pypa/cibuildwheel/blob/v3.1.1/examples/github-deploy.yml#L55-L61 for the real-world example.
For Android-ARM builds (that is,
*-android_arm64_v8a), the canonical approach is to use an Apple Silicon runner (e.g.,macos-latest) and skip testing.As of cibuildwheel 3.1.1, macOS runners on GitHub Actions do not support testing under Android emulation. Therefore, you must explicitly skip tests using
CIBW_TEST_SKIP: "*-android_arm64_v8a". Alternatively, you can build on Intel Linux (e.g.,ubuntu-latest), where tests are automatically skipped due to emulator limitations (no need to setCIBW_TEST_SKIP). This results in one fewer configuration line. However, from a code maintanability perspective, I recommend usingmacosfor future extensions and support.For iOS builds,
Use:
macos-13(Intel Mac runner) forx86_64_iphonesimulatormacos-14ormacos-latest(Apple Silicon runners) forarm64_iphoneosandarm64_iphonesimulatorarchitectures