Skip to content

build py_limited_api abi3 wheel and MacOS universal2 wheel#186

Merged
davidism merged 1 commit into
masterfrom
new-cibuildwheel-features
Feb 9, 2021
Merged

build py_limited_api abi3 wheel and MacOS universal2 wheel#186
davidism merged 1 commit into
masterfrom
new-cibuildwheel-features

Conversation

@davidism
Copy link
Copy Markdown
Member

@davidism davidism commented Feb 7, 2021

Use py_limited_api to build one wheel for 3.6+. Currently testing this.

Use cibuildwheel as a GitHub action. Don't need setup-python or pip install.

Build a MacOS universal2 wheel. From what I could tell from the cibuildwheel docs, this seems to be preferred over building the arm64 wheel.

closes #175

@davidism
Copy link
Copy Markdown
Member Author

davidism commented Feb 7, 2021

Hmm, cibuildwheel didn't produce a universal2 wheel.

@davidism davidism linked an issue Feb 7, 2021 that may be closed by this pull request
@henryiii
Copy link
Copy Markdown

henryiii commented Feb 8, 2021

There is no universal2 wheel for CPython 3.6. The first Apple Silicon version of Python is 3.9. There's a small chance 3.8 might be back ported, possibly? But it's 3.9 only for now.

Comment thread .github/workflows/build.yaml Outdated
- run: cibuildwheel
- uses: joerick/cibuildwheel@v1.9.0
env:
CIBW_BUILD: cp36-*
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
CIBW_BUILD: cp36-*
CIBW_BUILD: cp36-* cp39-macosx_universal2

Hopefully I got the name right, we forgot to add it to our table. 😳

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I'm curious to see if this a) produces a reasonably named wheel, and b) is correctly loaded by Pip; supporting 10.9 universal was something they forgot to consider, cp36 universal sounds like something that might be easy to miss, too. :)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You can also add CIBW_TEST_SKIP: *universal2:arm64 to keep cibuildwheel from complaining about having to skip testing the arm64 part of a universal2 wheel.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Looks like that change worked, there's now a universal2 wheel in the artifact. Need to find someone with a compatible Mac to test what pip does.

Copy link
Copy Markdown
Member Author

@davidism davidism Feb 8, 2021

Choose a reason for hiding this comment

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

Well, by "worked" I mean it built MarkupSafe-2.0.0a1-cp36-abi3-macosx_10_9_universal2.whl, which hopefully only gets picked for 3.9 by pip...

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

10_0???

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

My bad, a typo 😅

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Whew. :)

@davidism davidism marked this pull request as ready for review February 8, 2021 16:46
@davidism
Copy link
Copy Markdown
Member Author

davidism commented Feb 8, 2021

Had someone test it on their M1 Mac, and it doesn't look like pip understands the combination of abi3 and universal2 right now. Steps were:

  1. Use an M1 build of Python 3.9 from Homebrew.
  2. Download and unzip the build artifact, now have a folder called "artifacts" with wheels in it. artifact.zip
  3. pip install --pre --no-index -f artifacts markupsafe tells pip to install only from the artifacts folder, not PyPI.
$ pip install --pre --no-index -f artifacts markupsafe
Looking in links: artifacts
Collecting markupsafe
  ERROR: Could not find a version that satisfies the requirement markupsafe (from versions: none)
ERROR: No matching distribution found for markupsafe

When they used an x86 Python:

$ pip install --pre --no-index -f artifacts markupsafe
Looking in links: artifacts
Processing ./artifacts/MarkupSafe-2.0.0a1-cp36-abi3-macosx_10_9_x86_64.whl
Installing collected packages: markupsafe
Successfully installed markupsafe-2.0.0a1

@henryiii
Copy link
Copy Markdown

henryiii commented Feb 8, 2021

What version of pip? You have to have pip 21.0.1 to get universal wheels to install on M1 Macs. This would not surprise me if missing, though. I don't think homebrew ships 21.0.1 yet.

@davidism
Copy link
Copy Markdown
Member Author

davidism commented Feb 8, 2021

I just messaged them asking for python -VV and pip --version just to be sure. Will hopefully hear back soon. Also trying to find some others to try it out.

@henryiii
Copy link
Copy Markdown

henryiii commented Feb 8, 2021

Homebrew does ship pip 21.0.1, as long as they updated in the last nine days it should be 21.0.1. I'll have an M1 starting Thursday.

@davidism
Copy link
Copy Markdown
Member Author

davidism commented Feb 9, 2021

They upgraded pip and it now picked the correct wheel:

$ pip install --pre --no-index -f artifacts markupsafe
Looking in links: artifacts
Processing ./artifacts/MarkupSafe-2.0.0a1-cp36-abi3-macosx_10_9_universal2.whl
Installing collected packages: markupsafe
Successfully installed markupsafe-2.0.0a1

So it looks like we should be good to build cp36-abi3 and universal2.

@henryiii
Copy link
Copy Markdown

henryiii commented Feb 9, 2021

Fantastic! You really need pip 21.0.1+ on M1.

use limited api to build one wheel for 3.6+
use cibuildwheel action
build mac universal2 wheel
@davidism davidism force-pushed the new-cibuildwheel-features branch from 3e41771 to b982d71 Compare February 9, 2021 16:59
@davidism davidism merged commit cd7d340 into master Feb 9, 2021
@davidism davidism deleted the new-cibuildwheel-features branch February 9, 2021 17:17
@davidism
Copy link
Copy Markdown
Member Author

davidism commented Feb 9, 2021

I merged this then realized we are still having issues with Windows #175 (comment)

@henryiii
Copy link
Copy Markdown

henryiii commented Feb 9, 2021

What happened with Windo... Oh, I see you noticed that. Was curious to see how it was solved when I saw it was merged. :/

@henryiii
Copy link
Copy Markdown

henryiii commented Feb 9, 2021

As a workaround, you could make the Limited API conditional, disabled on Windows, but it really should work. Not involved enough in Windows to really help here, though. :(

@henryiii
Copy link
Copy Markdown

henryiii commented Feb 9, 2021

Can you try deleting all the distutils import and overrides? That bothers me; a) you shouldn't be touching distutils, it's being removed in 3.12, and b) setuptools should always be imported first, and c) it doesn't really seem to be doing anything very useful anyway, at least as far as I can see.

@henryiii
Copy link
Copy Markdown

henryiii commented Feb 9, 2021

Ahh, it allows the build to fail but then be ignored. Still think you could just catch the normal error, though?

@henryiii
Copy link
Copy Markdown

henryiii commented Feb 9, 2021

The important stuff does come from setuptools, so that's shouldn't be it, I wouldn't think.

@davidism
Copy link
Copy Markdown
Member Author

davidism commented Feb 9, 2021

I tried getting rid of the custom command class and just catching the exceptions directly, but something else in distutils/setuptools/pip catches them first and the exceptions don't make it back to the top-level code.

@davidism
Copy link
Copy Markdown
Member Author

davidism commented Feb 9, 2021

But to answer the implied question, the custom command isn't resulting in the bad Windows build, it still fails to import even when I remove all the custom stuff.

@davidism davidism removed this from the 2.0.0 milestone Feb 15, 2021
@davidism
Copy link
Copy Markdown
Member Author

Rolling the abi3 part back, as our use of Python's Unicode API is not compatible with Py_LIMITED_API.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider using the stable API when building wheels for CPython

2 participants