fix: two-phase bridge detection for conditional abi3 features#3144
fix: two-phase bridge detection for conditional abi3 features#3144
Conversation
e299da2 to
3dd5112
Compare
There was a problem hiding this comment.
Pull request overview
Fixes a regression in bridge detection where conditional pyo3/abi3* features (gated by python-version in pyproject.toml) were being applied unconditionally during bridge inference, leading to incorrect abi3 detection and downstream interpreter-resolution failures.
Changes:
- Extends
find_bridge()/ conditional feature inference to accept an optional resolved interpreter set so conditionalpyo3features can be filtered against actual interpreters. - Implements two-phase bridge detection in
BuildContextBuilder::build()to avoid premature abi3 inference before interpreter resolution, and moves bridge log output to print only once after final resolution. - Adds a unit test for conditional abi3 feature filtering across interpreter combinations.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ci/mod.rs | Updates find_bridge call site for the new interpreters parameter. |
| src/build_options.rs | Updates existing bridge-detection tests and adds a new unit test for conditional abi3 filtering. |
| src/build_context/builder.rs | Implements two-phase bridge detection (pre- and post-interpreter resolution) and adjusts logging behavior. |
| src/bridge/detection.rs | Adds interpreter-aware conditional feature filtering for abi3 inference and removes logging from find_bridge(). |
| src/auditwheel/sbom.rs | Simplifies deterministic sorting logic for SBOM generation. |
346610c to
74db8ad
Compare
74db8ad to
fd8abb7
Compare
fd8abb7 to
4e4d105
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes a regression in bridge/abi3 detection by splitting detection into two phases so conditional pyo3/pyo3-ffi features from pyproject.toml are only evaluated after Python interpreter resolution.
Changes:
- Update
find_bridge()to infer the bridge model from Cargo metadata only (no conditional pyproject feature influence). - Add
upgrade_bridge_abi3()to apply conditional abi3 feature inference after interpreters are resolved. - Add a regression test for conditional abi3 gating and adjust logging so bridge binding messages are printed once after final resolution.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ci/mod.rs | Updates find_bridge call site to new signature (no pyproject param). |
| src/build_options.rs | Updates find_bridge tests and adds a new conditional-abi3 regression test. |
| src/build_context/builder.rs | Implements two-phase bridge detection and moves final bridge logging here. |
| src/bridge/mod.rs | Re-exports upgrade_bridge_abi3 from the bridge module. |
| src/bridge/detection.rs | Refactors find_bridge and adds upgrade_bridge_abi3 + conditional feature filtering by resolved interpreters. |
| src/auditwheel/sbom.rs | Small determinism refactor for SBOM sorting implementation. |
4e4d105 to
6ea12ff
Compare
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Fixes incorrect unconditional application of conditional pyo3/abi3 features during bridge detection by splitting bridge detection into a metadata-only phase and a post-interpreter-resolution abi3 upgrade phase.
Changes:
- Refactors
find_bridge()to exclude conditionalpyproject.tomlfeatures and introducesupgrade_bridge_abi3()to apply them after interpreter resolution. - Updates builder/orchestrator logic to keep bridge inference consistent with feature resolution (especially when CLI
--featuresoverrides pyproject features). - Adds a regression test for conditional abi3 feature gating and makes SBOM sorting deterministic via
sort_by_key.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| src/ci/mod.rs | Updates find_bridge call site for new signature (no pyproject parameter). |
| src/build_orchestrator.rs | Adjusts interpreter grouping logic when min_version interacts with stable ABI capability. |
| src/build_options.rs | Updates bridge-detection tests and adds a new regression test for conditional abi3 gating. |
| src/build_context/builder.rs | Defers conditional abi3 inference until after interpreters are resolved and aligns with CLI feature overrides. |
| src/bridge/mod.rs | Re-exports new upgrade_bridge_abi3 API. |
| src/bridge/detection.rs | Implements two-phase detection (find_bridge + upgrade_bridge_abi3) and conditional feature evaluation by interpreter. |
| src/auditwheel/sbom.rs | Replaces comparator sort with sort_by_key for clearer deterministic ordering. |
Fix a regression (PyO3#3142) where conditional `pyo3/abi3` features gated on `python-version` in `pyproject.toml` were applied unconditionally during bridge detection, causing builds to fail for interpreters that don't match the condition. Changes: - Remove the `pyproject` parameter from `find_bridge()` since it no longer inspects conditional features. `find_bridge()` now only looks at Cargo metadata for bridge/abi3 detection. - Add `upgrade_bridge_abi3()` which evaluates conditional `pyo3`/`pyo3-ffi` features from `pyproject.toml` against a set of resolved interpreters, upgrading the bridge to abi3 if any interpreter matches. This is safe because `build_stable_abi_wheels` already splits interpreters into abi3-capable vs version-specific groups by `min_version`. - Call `find_bridge()` once in `BuildContextBuilder::build()`, resolve interpreters against the conservative (non-abi3) bridge, then call `upgrade_bridge_abi3()` to conditionally promote to abi3. - Skip conditional pyproject features for bridge inference when CLI `--features` overrides pyproject features, keeping bridge detection in sync with compile-time feature resolution. - Move the bridge binding log messages from `find_bridge()` to the builder so they only print once after the final bridge is resolved. - Add unit test covering all interpreter combinations: no interpreters, 3.10-only, 3.11-only, and mixed [3.10, 3.11].
6ea12ff to
3c6523d
Compare
Fixes #3142.
Problem
Since maturin 1.13.0, conditional
pyo3/abi3features gated onpython-versioninpyproject.tomlwere applied unconditionally during bridge detection. This caused builds to fail when the target interpreter didn't match the condition:Solution
Split bridge detection into two phases:
find_bridge()— detects the bridge model from Cargo metadata only, excluding conditional pyproject features. Thepyprojectparameter is removed since it's no longer needed here.upgrade_bridge_abi3()— after interpreter resolution, evaluates conditionalpyo3/pyo3-ffifeatures against the resolved interpreters usingmatches_anysemantics, upgrading the bridge to abi3 if any interpreter qualifies.The
matches_anyapproach is safe becausebuild_stable_abi_wheelsalready splits interpreters into abi3-capable vs version-specific groups bymin_version, producing e.g.cp310 + abi3-cp311for mixed[3.10, 3.11].Additional fixes
--featuresoverrides pyproject features, keeping bridge detection in sync with compile-time feature resolution.find_bridge()to the builder so they print once after the final bridge is resolved.Validation
cargo test --lib test_find_bridge_ -- --nocapture(6 tests including new conditional abi3 test)>=3.15with Python 3.14 producescp314wheel (no abi3);>=3.11with Python 3.14 producesabi3-cp311wheel