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

feat: Cross-compile macos arm64 wheels #1348

Closed
wants to merge 34 commits into from

Conversation

armenzg
Copy link

@armenzg armenzg commented Sep 7, 2021

This uses cibuildwheel in order to cross-compile the arm64 wheels for Python 3.8, 3.9 & 3.10.

Fixes #1286

This uses [cibuildwheel](https://cibuildwheel.readthedocs.io/en/stable/) in order to cross-compile the arm64 wheels for Python 3.8, 3.9 & 3.10.

Fixes psycopg#1286
@armenzg
Copy link
Author

armenzg commented Sep 7, 2021

@dvarrazzo thanks for opening this question

This PR uses the cibuildwheel action to produce the arm64 wheels that the Apple M1 machines could use.
I know you don't want to switch to cibuildwheel before version 3, however, you might be able to release only the arm64 wheels via cibuildwheel as experimental.

I did not manage to produce the universal2 package.

This can also be tested locally with `cibuildwheel --platform macos --archs arm64
image

@armenzg
Copy link
Author

armenzg commented Sep 7, 2021

I've pushed one more commit to name correctly the upload artifact.

Meanwhile, I've tested that it installs:

❯ brew uninstall postgresql
Uninstalling /opt/homebrew/Cellar/postgresql/13.4... (3,230 files, 43.6MB)
❯ pip install ~/Downloads/packages_macos/psycopg2-2.9.1-cp38-cp38-macosx_11_0_arm64.whl --no-cache-dir
Processing /Users/armenzg/Downloads/packages_macos/psycopg2-2.9.1-cp38-cp38-macosx_11_0_arm64.whl
Installing collected packages: psycopg2
Successfully installed psycopg2-2.9.1

@armenzg
Copy link
Author

armenzg commented Sep 7, 2021

The latest artifacts will show up in here:
https://github.com/armenzg/psycopg2/actions/runs/1210897910

You should be able to see packages_macos _arm64 once the workflow completes. It should be about < 9MB with the three versions.

@@ -51,16 +50,15 @@ jobs:
--health-timeout 5s
--health-retries 5


Copy link
Member

Choose a reason for hiding this comment

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

You don't like two spaces? 🥺

Copy link
Author

@armenzg armenzg Sep 7, 2021

Choose a reason for hiding this comment

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

I forgot to mention. prettier change the formatting of the file. I will change it.

- {tag: manylinux2014, arch: i686}
- {tag: manylinux_2_24, arch: aarch64}
- {tag: manylinux_2_24, arch: ppc64le}
- { tag: manylinux2014, arch: x86_64 }
Copy link
Member

Choose a reason for hiding this comment

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

Unneeded

build-macos:
runs-on: macos-10.15
strategy:
fail-fast: false
matrix:
python-version: ['3.6', '3.7', '3.8', '3.9']
python-version: ["3.6", "3.7", "3.8", "3.9"]
Copy link
Member

Choose a reason for hiding this comment

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

Unneeded

@dvarrazzo
Copy link
Member

@armenzg thank you very much for trying this out!

I have seen that tests are disabled, I assume the reference is this, right?

@dvarrazzo
Copy link
Member

The latest artifacts will show up in here:
https://github.com/armenzg/psycopg2/actions/runs/1210897910

You should be able to see packages_macos _arm64 once the workflow completes. It should be about < 9MB with the three versions.

I'm not sure it worked: the zip size is only 418k

@dvarrazzo
Copy link
Member

Meanwhile, I've tested that it installs:

Did you try if the result imports and passes the test suite?

Honestly releasing packages that aren't tested makes me nervous...

@armenzg
Copy link
Author

armenzg commented Sep 7, 2021

Meanwhile, I've tested that it installs:

Did you try if the result imports and passes the test suite?

Honestly releasing packages that aren't tested makes me nervous...

No worries. I will look at the code tomorrow and see what you have in place for testing. Thanks for the prompt feedback.

If you have any specific code you want me to look to see how to get it tested let me know.

@dvarrazzo
Copy link
Member

If you have any specific code you want me to look to see how to get it tested let me know.

What make check does :) make check tests what was just built with make; because that's not the case for you (I assume you want to test, on your laptop, what gets built by GitHub action), you can run:

python -c "import tests; tests.unittest.main(defaultTest='tests.test_suite')"

you can tweak the env vars you find in tests/testconfig.py to point the test suite to a database to trash.

What I mean is more a general thing however: future releases will build package that will not be tested automatically by the CI, at least until M1 runners are available.


# Build the wheels
wheeldir="${prjdir}/wheels"
pip wheel -w ${wheeldir} .
pip wheel --use-feature=in-tree-build -w ${wheeldir} .
Copy link
Author

Choose a reason for hiding this comment

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

There's a warning to switch to this.

@@ -8,22 +8,22 @@
set -euo pipefail
set -x

dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
Copy link
Author

Choose a reason for hiding this comment

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

Please ignore auto-formatting changes for now. My IDE is all messed up. I will fix it up at the very end.

@@ -52,28 +48,33 @@ if [[ -z "${LIBPQ:-}" ]]; then
fi

delocate-wheel ${wheeldir}/*.whl
# https://github.com/MacPython/wiki/wiki/Spinning-wheels#question-will-pip-give-me-a-broken-wheel
delocate-addplat --rm-orig -x 10_9 -x 10_10 ${wheeldir}/*.whl
if [[ $(uname -m) != 'arm64' ]]; then
Copy link
Author

Choose a reason for hiding this comment

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

This is to help my M1 machine skip this step.

@@ -0,0 +1,23 @@
#!/bin/bash
Copy link
Author

Choose a reason for hiding this comment

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

Ignore this script for now.

@@ -45,6 +45,7 @@
# for a consistent versioning pattern.

PSYCOPG_VERSION = '2.9.1'
PSYCOPG_NAME = os.environ.get("PACKAGE_NAME", "psycopg2")
Copy link
Author

Choose a reason for hiding this comment

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

This removes the need to touch the file to generate pyscopg2-binary.

@armenzg
Copy link
Author

armenzg commented Sep 9, 2021

If I execute the build_macos.sh on my M1 machine I can get the wheel with the included library.
I'm stuck not being able to cross-compile and for the library to be included (It comes up as 140kb).
I will file an issue with cibuildwheel or delocate and see what comes from it.

I can work around this on Sentry by installing postgresql on the developer's machine and get the wheel built on their machines.

@dvarrazzo
Copy link
Member

@armenzg, if Sentry would like to help with this work maybe they could lend a machine to use as external worker and do without cross compiling?

@armenzg
Copy link
Author

armenzg commented Oct 13, 2021

@armenzg, if Sentry would like to help with this work maybe they could lend a machine to use as external worker and do without cross compiling?

Hi @dvarrazzo I worked on finding ways to fund you instead. The process is out of my hand at the moment.

@lithammer
Copy link
Contributor

lithammer commented Nov 12, 2021

I'm not very familiar with the build/test related differences between psycopg2 and psycopg3. But isn't it possible to more or less copy the workflows from psycopg3? For example, it would be nice to get musllinux wheels (psycopg/psycopg#141) for psycopg2 as well for use with Django.

@dvarrazzo
Copy link
Member

@lithammer psycopg2 doesn't use cibuildwheel. Before recently, as you know, there wasn't a standard for musl wheels. Now there is, but it's probably easier to adapt the existing build pipeline to musl than to start using cibuildwheel.

The M1 issue is different: you can cross compile but you cannot test the produced artifacts and this is not really acceptable quality IMO.

@armenzg armenzg closed this Jul 11, 2022
@armenzg armenzg deleted the ci/build-m1-wheel branch July 11, 2022 16:13
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.

psycopg2-binary support for M1 chipset
3 participants