Hey,

I'm trying to upstream some small fixes to pyo3/maturin for building on Cygwin
and some changes I've made to CPython affect that, so I wanted to give a heads
up / ask for feedback.

1) sysconfig.get_platform() includes Cygwin runtime version

pip has started to enforce, that on systems where the wheel tags are derived
from sysconfig.get_platform(), that installations and wheels end with
sysconfig.get_platform(). Problem is that Cygwin's sysconfig.get_platform()
contains the cygwin runtime version, so every time the version changes existing
wheels are considered incompatible and pip complains about installed ones.

You can test that by running "pip check" and see it complaining about packages,
and "pip debug --verbose | grep cp39" to see the compatible tags. I've fixed
this downstream by simply removing the version.

$ python -c "import sysconfig; print(sysconfig.get_platform())" # old
cygwin-3.6.5-x86_64

$ python -c "import sysconfig; print(sysconfig.get_platform())" # new
cygwin-x86_64

Patch: 
https://github.com/msys2/MSYS2-packages/blob/eb3d060cea49e5323db3e10d2e39a8a058cd4885/python/900-msysize.patch#L54-L65

Maturin currently hardcodes this logic for platforms, and I'm planing to use the
non-versioned variant there.

2) Limited API (abi3) support missing

pyo3/maturin can build limited API extensions (cryptography uses that by default
for example). This means extensions can link against a subset of the CPython API
and the DLL does not include a version number, so in theory an extension built
against 3.12 also runs with 3.13 etc. This DLL is missing from Cygwin and abi3
wheels end up linking against a versioned DLL.

I've implemented this here:
https://github.com/msys2/MSYS2-packages/blob/eb3d060cea49e5323db3e10d2e39a8a058cd4885/python/991-py-limited-api.patch

$ ldd cryptography/hazmat/bindings/_rust.abi3.dll
        ...
        msys-python3.dll => /usr/bin/msys-python3.dll (0x41de30000)
        ...

Note that the list of symbols depends on the Python version and needs to be
updated with the included tool:

$ python ./Tools/build/stable_abi.py --generate --cyg-python3dll
PC/cyg-python3dll.c Misc/stable_abi.toml

If the DLL is missing it's easy to work around though, remove "abi3" here to
make it link against the full API:
https://github.com/pyca/cryptography/blob/7ae52180836fc01a9eb2a7e40499adf9406fe03d/Cargo.toml#L33

Perhaps both of these changes could be considered for a future Python update in
Cygwin so that the behavior of our packages align.

regards

Reply via email to