abi3 fallback for older interpreters incorrectly sets Py_LIMITED_API in pyo3 config
## Bug Description
When maturin detects abi3 support and an interpreter older than the abi3 minimum is requested (e.g., Python 3.10 when abi3 targets ≥ 3.11), it falls back to building a version-specific wheel. However, the generated `pyo3-config-*.txt` for the fallback build still appears to have `abi3=true` set, which causes `Py_LIMITED_API` to be defined during compilation.
This breaks crates that use pyo3 APIs gated behind `cfg(any(not(Py_LIMITED_API), Py_3_XX))` — for example, `pyo3::buffer` which requires either non-limited-API or Python ≥ 3.11.
**This is a regression introduced in maturin 1.13.x** (likely related to #3126 "fall back to placeholder for abi3 when found interpreters are too old"). The same project builds successfully with maturin 1.12.6.
## Reproduction
Project: https://github.com/trim21/bencode-rs/pull/240
### pyproject.toml (relevant sections)
```toml
[build-system]
requires = ["maturin==1.13.2"]
build-backend = "maturin"
[tool.maturin]
features = [
{ feature = "pyo3/abi3-py311", python-version = ">=3.11" },
]
```
### Cargo.toml (relevant sections)
```toml
[dependencies]
pyo3 = { version = "0.28.3", features = ['generate-import-lib'] }
```
### Build command
```
maturin build --release --out dist --interpreter '3.11' --interpreter '3.10'
```
### Steps to reproduce
1. Use a pyo3 project that imports `pyo3::buffer` (which is gated behind `cfg(any(not(Py_LIMITED_API), Py_3_11))`)
2. Configure conditional abi3 features in `pyproject.toml`: `{ feature = "pyo3/abi3-py311", python-version = ">=3.11" }`
3. Build with `--interpreter '3.11' --interpreter '3.10'`
### Expected behavior
- First build: abi3 wheel for Python ≥ 3.11 ✅ (works)
- Second build: version-specific wheel for Python 3.10 with `abi3=false` in pyo3 config ✅
### Actual behavior
- First build: abi3 wheel for Python ≥ 3.11 ✅ (works)
- Second build: version-specific wheel for Python 3.10, but the generated pyo3 config appears to still have `abi3=true`, causing `Py_LIMITED_API` to be defined ❌
## Error output
```
📦 Built wheel for abi3 Python ≥ 3.11 to dist/bencode_rs-0.0.9-cp311-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
⚠️ Warning: abi3 does not yet support CPython 3.10 so the build artifacts will be version-specific.
error[E0432]: unresolved import `pyo3::buffer`
--> src/encode.rs:2:11
|
2 | use pyo3::buffer::{PyBuffer, ReadOnlyCell};
| ^^^^^^^ could not find `buffer` in `pyo3`
|
note: found an item that was configured out
--> pyo3-0.28.3/src/lib.rs:413:9
|
413 | pub mod buffer;
| ^^^^^^
|
::: pyo3-0.28.3/src/buffer.rs:1:11
|
1 | #![cfg(any(not(Py_LIMITED_API), Py_3_11))]
| ------------------------------ the item is gated here
```
## Environment
- maturin version: 1.13.2 (regression from 1.12.6)
- pyo3 version: 0.28.3
- Python interpreters: 3.10, 3.11
- Platforms affected: all (Linux x86_64, Linux aarch64, macOS arm64, etc.)
## CI Run
Full CI failure logs: https://github.com/trim21/bencode-rs/actions/runs/25625690761
关闭于 2026-05-11 2 条评论