Skip to content

Add support for Android - #10233

Open
mhsmith wants to merge 35 commits into
python-pillow:mainfrom
mhsmith:android
Open

mhsmith wants to merge 35 commits into
python-pillow:mainfrom
mhsmith:android

Conversation

@mhsmith

@mhsmith mhsmith commented Oct 17, 2026 •

Copy link
Copy Markdown

As with iOS, most of the work was in wheels-dependencies.sh. I've explained the Android-specific changes with comments in the code, but here's a summary of changes that affect other platforms:

  • wheels-dependencies.sh now runs as a before-build script rather than before-all. This has several advantages:

    • It allows the script to determine the current OS and architecture from the CIBUILDWHEEL_BUILD_IDENTIFIER environment variable. This means you can now run cibuildwheel in any of its supported modes, including building multiple architectures in one command, or using --only with no environment variables at all.
    • The script runs within a temporary virtual environment, so it can install Python packages without modifying cibuildwheel's own environment.
    • Although the script may run multiple times for different Python versions, they all share the same WORKDIR, so the later runs will see all the stamp files and finish quickly without rebuilding anything.
  • To improve consistency between platforms, and reduce clutter in the build directory, WORKDIR is now set to build/deps/os_arch, where os_arch is the second half of CIBUILDWHEEL_BUILD_IDENTIFIER, e.g. android_x86_64 or macosx_arm64.

    • On all platforms except Linux, BUILD_PREFIX is now set to $WORKDIR/prefix. Linux continues to install dependencies to /usr/local as before.
  • Introduced an IS_LINUX flag, since -z $IS_MACOS can now mean either Linux or Android.

  • For consistency, cmake is now installed from PyPI on all platforms, not just macOS. pkg-config is now also installed from PyPI rather than building it from source.

  • Factored out the test sequence (selftest, check_wheel, Tests) into a wheels_test script which is shared by all platforms. This was necessary because on Android, cibuildwheel requires test-command to be a single Python command.

@radarhere

Copy link
Copy Markdown
Member

Hi. Could you let me know - what was your thinking behind creating this as a draft? You could simply run our CI in your own fork and inspect the results there. Or do you think this is close to being finished, and are hoping for support?

@mhsmith

mhsmith commented Oct 19, 2026

Copy link
Copy Markdown
Author

You could simply run our CI in your own fork and inspect the results there.

Sorry, I didn't realize the project required CI approval for new contributors. I'll work on a different branch on my own fork, and update the PR once it's ready for review, which should be within the next few days.

@mhsmith
mhsmith marked this pull request as ready for review October 26, 2026 01:25
@mhsmith

mhsmith commented Oct 26, 2026

Copy link
Copy Markdown
Author

This PR is now ready for review. I've updated the description above.

@radarhere

Copy link
Copy Markdown
Member

Is the bzip2 patch intended to be permanent? It would be ideal if the functionality could one day be added upstream.

@mhsmith

mhsmith commented Oct 27, 2026 •

Copy link
Copy Markdown
Author

A fix was already submitted to the project a few years ago, but it doesn't look like it got any response. bzip2 is a very inactive project which hasn't made a release since 2019, so I think we'll have to keep the patch until that changes.

@mhsmith

mhsmith commented Nov 9, 2026

Copy link
Copy Markdown
Author

I see the next release is planned for the first week in January; do you think we could get this merged in time for then? Let me know if there's anything that needs more explanation.

@radarhere

Copy link
Copy Markdown
Member

Unfortunately, this is a point in time where the amount of issues, PRs and security advisories are overwhelming. So I'm not very optimistic.

If you would like to try and move this forward, then the best move might be to request a review from freakboy3742. He was the one who added Pillow iOS support in #9030, and since you're changing some of that code, his approval would be encouraging.

@mhsmith

mhsmith commented Nov 10, 2026

Copy link
Copy Markdown
Author

Thanks; I've mentioned this to @freakboy3742 and he says he'll take a look at it.

@freakboy3742 freakboy3742 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For the most part, this makes sense. I can only spot a couple of issues, which I've flagged inline:

  1. Duplication of LICENCE collection by moving the wheel script to before-build
  2. oss-fuzz compatibliity
  3. iOS wheels no longer include XCB - as noted, this isn't really an issue, but it's a notable change
  4. Overwriting PKG_CONFIG_PATH on macOS in setup.py
  5. The BZip2 patch allowing environment CC etc to propegate

One issue that I didn't flag inline - The current symlink means that it's no longer possible to run builds in parallel on the same machine. I doubt that's a dealbreaker, but it's worth noting as a change. On the upside, it does allow building multiple architectures in a single build, which the previous script didn't - CIBW_ARCHS had to be set to a single value.

Regarding the LICENSE issue:

The minimal fix would be to split wheel-dependencies.sh into the before-build wheel dependency part, and the before-all license collation part.

However - my take would be that the current approach isn't right anyway, because running a build modifies a file that is CI-controlled. Even with the existing build-all setup, running a build twice in the same folder will have the same effect as this PR.

I'd suggest that the better approach here would be to either:

  1. Make better use of the PEP 639 license-files definition and include each of the dependency license files separately. That entirely removes the need for the license collation step.
  2. Write the dependency licenses into a file other than LICENSE that isn't under version control, and re-create it on every build, then include that file in license-files. The downside to this is that there will be file listed in license-files that won't exist until a build is done.
  3. Write all the license files into build/LICENSE, and point license-files at that file. Again, this means the contents of license-files won't exist unless you do a build.

For my money, option (1) is the better alternative; but that's ultimately a decision for Pillow maintainers to make.

Comment thread pyproject.toml
build-verbosity = 1
config-settings = "raqm=enable raqm=vendor fribidi=vendor imagequant=disable"
before-all = ".github/workflows/wheels-dependencies.sh"
before-build = ".github/workflows/wheels-dependencies.sh"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

before-build runs once per build; before-all runs once per job. One of the things that the wheels dependency script does is accumulate licenses in the LICENSES file; so this change results in license text being accumulated multiple times.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I agree modifying a source-controlled file during the build isn't ideal, but I think fixing that in this PR would touch too many things, because WIndows has its own separate license concatenation script elsewhere in wheels.yml.

Instead, I've added some code to the bottom of wheels-dependencies.sh which detects when the LICENSE file has already been appended, and avoids appending it again. Any other unstaged changes to the file will show an error and stop the build.

Comment thread patches/bzip2-1.0.8.tar.gz.patch Resolved
Comment thread setup.py Resolved
@mhsmith

mhsmith commented Nov 18, 2026

Copy link
Copy Markdown
Author

@radarhere: I've seen several failures like this on manylinux_x86_64 and manylinux_aarch64:

FAILED Tests/test_webp_leaks.py::TestWebPLeaks::test_leak_load - AssertionError: memory usage limit exceeded in iteration 50
  assert 3084.0 < 3072

Logs:

Is this a known problem? I don't see how it could be caused by this PR.

@mhsmith

mhsmith commented Nov 18, 2026

Copy link
Copy Markdown
Author

The Windows x86 failure is unrelated:

@mhsmith

mhsmith commented Nov 22, 2026

Copy link
Copy Markdown
Author

@freakboy3742: Please re-review when you have a chance.

@freakboy3742 freakboy3742 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 Thanks for those updates - this all looks good to me.

@hugovk hugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks both!

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.

Wheels for Android?

4 participants