PyO3 / maturin

Build and publish crates with pyo3, cffi and uniffi bindings as well as rust binaries as python packages
https://maturin.rs
Apache License 2.0
3.71k stars 254 forks source link

Build option to dynamically set abi3 version #1894

Open alex opened 9 months ago

alex commented 9 months ago

Currently the way to set abi3 version is via applying a versioned-feature in Cargo.toml (e.g., abi3-py312).

I'm requesting a way set that at the CLI. The reason for this is to be able to build wheels targeting multiple abi3 versions from the same source.

We're currently able to do this with setuptools-rust with the following command:

if [ -n "${{ matrix.PYTHON.ABI_VERSION }}" ]; then
    PY_LIMITED_API="--config-settings=--build-option=--py-limited-api=${{ matrix.PYTHON.ABI_VERSION }} --no-build-isolation"
fi
OPENSSL_DIR="/opt/pyca/cryptography/openssl" \
    OPENSSL_STATIC=1 \
    .venv/bin/python -m pip wheel -v $PY_LIMITED_API cryptograph*.tar.gz -w dist/ && mv dist/cryptography*.whl tmpwheelhouse
konstin commented 8 months ago

What's the motivation for targeting multiple abi3 versions instead of the lowest supported?

alex commented 8 months ago

To be able to take advantage of improvements (e.g. performance) on newer versions, while maintaining compatibility.

The specific improvement that motivated us to do this was https://github.com/PyO3/pyo3/blob/main/src/impl_/pymodule.rs#L83-L119

messense commented 8 months ago

I think it's already possible by using MATURIN_PEP517_ARGS env var or --config-settings, for example

pip wheel --config-settings=build-args='--features abi3-py312'
alex commented 8 months ago

Ah, that will be respected? Let me test it. Thanks!

alex commented 8 months ago

Hmm, it fails when building an sdist with:

Caused by: You have selected the abi3 feature but not a minimum version (e.g. the abi3-py36 feature). maturin needs a minimum version feature to build abi3 wheels.

alex commented 8 months ago

I guess it fails everywhere except the places I passed that argument.

alex commented 8 months ago

To follow up on this, it's missing a key element that setuptools-rust "auto" provides: using abi3 with the current python if nothing is explicitly provided.

alex commented 7 months ago

Do you think support for something like "auto" abi3, where it used the current Python's version is possible?

messense commented 6 months ago

Do you think support for something like "auto" abi3, where it used the current Python's version is possible?

I think we can support this, we can change maturin to use the current Python's version when abi3 feature is enabled without an explicit abi3-pyXY feature, and print a message about this behavior of course.