Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use cibuildwheel #7552

Merged
merged 13 commits into from
Nov 25, 2023
Merged

Use cibuildwheel #7552

merged 13 commits into from
Nov 25, 2023

Conversation

radarhere
Copy link
Member

@radarhere radarhere commented Nov 14, 2023

Helps #7390.

It has been suggested that we move from multibuild to cibuildwheel.

Looking at cibuildwheel though, it doesn't have multibuild's library builders to build our dependencies.

So this PR employs a hybrid approach, using multibuild to build the dependencies first, and then cibuildwheel to build the wheels.

It seems to me that the primary advantage of cibuildwheel is speed, in that the dependencies are built less, and re-used by different Python environments.

.github/workflows/wheels.yml Outdated Show resolved Hide resolved
.github/workflows/wheels.yml Outdated Show resolved Hide resolved
@hugovk hugovk added the Build label Nov 14, 2023
radarhere and others added 2 commits November 15, 2023 11:48
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
@radarhere radarhere marked this pull request as ready for review November 15, 2023 08:34
@hugovk
Copy link
Member

hugovk commented Nov 15, 2023

This is looking good, thanks!

Comparing the zip generated before with this PR:

image

The sdist covered above.


We're also building PyPy 3.8 wheels in addition to PyPy 3.9-3.10, I think it's because cibuildwheel by default looks at our requires-python = ">=3.8". We should be able to skip with something like this:

CIBW_SKIP: pp38-*

The macOS Intel wheels are built for 10.9 here instead of 10.10 before. I don't think this matters?

@hugovk
Copy link
Member

hugovk commented Nov 15, 2023

Hmm, installing a wheel for this Apple Silicon Mac: pillow-10.2.0.dev0-cp311-cp311-macosx_11_0_arm64.whl

Gives an error on import:

Python 3.11.5 (v3.11.5:cce6ba91b3, Aug 24 2023, 10:50:31) [Clang 13.0.0 (clang-1300.0.29.30)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from PIL import Image
╭─────────────────────────────── Traceback (most recent call last) ────────────────────────────────╮
│ in <module>:1                                                                                    │
│                                                                                                  │
│ /Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/PIL/Image.py:82  │
│ in <module>                                                                                      │
│                                                                                                  │
│     79 │   # import Image and use the Image.core variable instead.                               │
│     80 │   # Also note that Image.core is not a publicly documented interface,                   │
│     81 │   # and should be considered private and subject to change.                             │
│ ❱   82 │   from . import _imaging as core                                                        │
│     83 │                                                                                         │
│     84 │   if __version__ != getattr(core, "PILLOW_VERSION", None):                              │
│     85 │   │   msg = (                                                                           │
╰──────────────────────────────────────────────────────────────────────────────────────────────────╯
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/PIL/_imaging.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace
'_jpeg_resync_to_restart'

Renaming this wheel and the equivalent Pillow-10.1.0-cp311-cp311-macosx_11_0_arm64.whl from https://pypi.org/project/Pillow/10.1.0/#files to add .zip, and comparing, shows we're now missing the .dylibs directory, and some of the .so files:

Details

image
image

@hugovk
Copy link
Member

hugovk commented Nov 15, 2023

A quick inspection of Intel Mac, manylinux, and musllinux wheels, they look like they have everything.

CIBW_BUILD: ${{ matrix.build }}
CIBW_CONFIG_SETTINGS: raqm=enable raqm=vendor fribidi=vendor
CIBW_MANYLINUX_PYPY_X86_64_IMAGE: ${{ matrix.manylinux }}
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux }}
Copy link
Contributor

Choose a reason for hiding this comment

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

While arm64 wheels can be built on x86_64, they cannot be tested. The ability to test the arm64 wheels will be added in a future release of cibuildwheel, once Apple Silicon CI runners are widely available. To silence this warning, set CIBW_TEST_SKIP: *-macosx_arm64.

Suggested change
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux }}
CIBW_MANYLINUX_X86_64_IMAGE: ${{ matrix.manylinux }}
CIBW_TEST_SKIP: *-macosx_arm64

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, I've added a commit for this. Testing, I found that it required quotes, as per https://cibuildwheel.readthedocs.io/en/stable/options/#test-skip

Copy link
Member

Choose a reason for hiding this comment

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

I've created a PR to fix this upstream: pypa/cibuildwheel#1665

@radarhere
Copy link
Member Author

The macOS Intel wheels are built for 10.9 here instead of 10.10 before. I don't think this matters?

Taking a look, I found that #6179 had a problem when I accidentally reverted it to 10.9 once before, so I've pushed a commit to restore 10.10.

radarhere and others added 2 commits November 16, 2023 09:32
Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
@hugovk
Copy link
Member

hugovk commented Nov 16, 2023

Thanks for the update. Now we get the same filenames before and after: also the sdist, and 10_10 files instead of 10_9. 👍

However, I'm still getting this for pillow-10.2.0.dev0-cp311-cp311-macosx_11_0_arm64.whl:

ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/PIL/_imaging.cpython-311-darwin.so, 0x0002): symbol not found in flat namespace
'_jpeg_resync_to_restart'

We still seem to be missing .dylibs:

Details image

@hugovk
Copy link
Member

hugovk commented Nov 16, 2023

On an Intel Mac, pillow-10.2.0.dev0-cp311-cp311-macosx_10_10_x86_64.whl does install, and a quick Image.new() and .show() work.

@radarhere
Copy link
Member Author

Ok, the macOS arm64 wheels should be better now.

@hugovk
Copy link
Member

hugovk commented Nov 17, 2023

Thanks! I tested the cp38 to cp312 macOS arm64 wheels and they all passed a simple install/im=Image.new("RGB", (20, 20), "red")/im.show() test.

The wheels contain the same files as before:

Details

image

I'll test the Intel ones later. I note they now contain libjpeg and libzstd dylib files that they didn't have before:

Details

image

It would be good if anyone can help test out some manylinux and musllinux wheels: go to https://github.com/python-pillow/Pillow/actions/runs/6901285566?pr=7552 and download the "dist" artifact, and pip install <filename>.whl.

@nulano
Copy link
Contributor

nulano commented Nov 17, 2023

I can see that the libzstd dylib has different permissions (-r--r--r--) than most of the other files (-rwxr-xr-x). Don't know if that is an issue, but it usually means it was copied from the system and not built during the release.

It would be good if anyone can help test out some manylinux and musllinux wheels

/pillow-10.2.0.dev0-cp38-cp38-manylinux_2_28_x86_64.whl passes tests on my Ubuntu Server system.

All of the musllinux wheels pass tests in the corresponding python:3.X-alpine Docker containers.

@hugovk
Copy link
Member

hugovk commented Nov 17, 2023

✅ Working on Intel macOS with Python 3.8-3.12 with:

#!/usr/bin/env bash

for VARIABLE in 8 9 10 11 12
do
	python3.$VARIABLE -m pip install -U pip
	python3.$VARIABLE -m pip uninstall -y pillow
	python3.$VARIABLE -m pip install pillow-10.2.0.dev0-cp3$VARIABLE-cp3$VARIABLE-macosx_10_10_x86_64.whl
	python3.$VARIABLE 1.py
done
from PIL import Image
im = Image.new("RGB", (10, 20), "red")
im.show()

@radarhere
Copy link
Member Author

I can see that the libzstd dylib has different permissions (-r--r--r--) than most of the other files (-rwxr-xr-x). Don't know if that is an issue, but it usually means it was copied from the system and not built during the release.

Ok, I've pushed a commit to remove it again, like it was before this PR.

@hugovk
Copy link
Member

hugovk commented Nov 18, 2023

✅ Looking good testing with #7552 (comment) on both Intel and Apple Silicon for all versions.

Copy link
Member

@hugovk hugovk left a comment

Choose a reason for hiding this comment

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

Thank you!

@hugovk hugovk merged commit e2ddd27 into python-pillow:main Nov 25, 2023
61 of 62 checks passed
@radarhere radarhere deleted the cibuildwheel branch November 25, 2023 08:39
DavidKorczynski pushed a commit to google/oss-fuzz that referenced this pull request Nov 27, 2023
pillow has started using
[cibuildwheel](https://github.com/pypa/cibuildwheel) -
python-pillow/Pillow#7552

This moved the script for building wheel dependencies from
`wheels/config.sh`, a more natural location for
[multibuild](https://github.com/multi-build/multibuild), to just under
GitHub Actions instead, at
[.github/workflows/wheel-dependencies.sh](https://github.com/python-pillow/Pillow/blob/main/.github/workflows/wheels-dependencies.sh)

It also now includes `wheels/multibuild/library_builders.sh` [by
itself](https://github.com/python-pillow/Pillow/blob/e2ddd27500cdd4c8156bc0d5fe0bfa050408c707/.github/workflows/wheels-dependencies.sh#L10),
and rearranged the code to run immediately, instead of needing
`pre_build` to be called separately.

cc @hugovk

Co-authored-by: Andrew Murray <radarhere@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants