Skip to content

fix: two-phase bridge detection for conditional abi3 features#3144

Merged
messense merged 1 commit intoPyO3:mainfrom
messense:fix/conditional-abi3-matches-any
Apr 18, 2026
Merged

fix: two-phase bridge detection for conditional abi3 features#3144
messense merged 1 commit intoPyO3:mainfrom
messense:fix/conditional-abi3-matches-any

Conversation

@messense
Copy link
Copy Markdown
Member

@messense messense commented Apr 18, 2026

Fixes #3142.

Problem

Since maturin 1.13.0, conditional pyo3/abi3 features gated on python-version in pyproject.toml were applied unconditionally during bridge detection. This caused builds to fail when the target interpreter didn't match the condition:

💥 maturin failed
  Caused by: None of the found Python interpreters (CPython 3.10) are compatible
  with the abi3 minimum version (>= 3.11).

Solution

Split bridge detection into two phases:

  1. find_bridge() — detects the bridge model from Cargo metadata only, excluding conditional pyproject features. The pyproject parameter is removed since it's no longer needed here.

  2. upgrade_bridge_abi3() — after interpreter resolution, evaluates conditional pyo3/pyo3-ffi features against the resolved interpreters using matches_any semantics, upgrading the bridge to abi3 if any interpreter qualifies.

The matches_any approach is safe because build_stable_abi_wheels already splits interpreters into abi3-capable vs version-specific groups by min_version, producing e.g. cp310 + abi3-cp311 for mixed [3.10, 3.11].

Additional fixes

  • Skip conditional pyproject features when CLI --features overrides pyproject features, keeping bridge detection in sync with compile-time feature resolution.
  • Move bridge binding log messages from 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)
  • Manual verification: >=3.15 with Python 3.14 produces cp314 wheel (no abi3); >=3.11 with Python 3.14 produces abi3-cp311 wheel

@messense messense requested a review from Copilot April 18, 2026 03:23
@messense messense force-pushed the fix/conditional-abi3-matches-any branch from e299da2 to 3dd5112 Compare April 18, 2026 03:25
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 conditional pyo3 features 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.

Comment thread src/bridge/detection.rs Outdated
Comment thread src/build_options.rs
Comment thread src/bridge/detection.rs Outdated
@messense messense force-pushed the fix/conditional-abi3-matches-any branch 2 times, most recently from 346610c to 74db8ad Compare April 18, 2026 03:40
@messense messense requested a review from Copilot April 18, 2026 03:41
@messense messense force-pushed the fix/conditional-abi3-matches-any branch from 74db8ad to fd8abb7 Compare April 18, 2026 03:42
@messense messense force-pushed the fix/conditional-abi3-matches-any branch from fd8abb7 to 4e4d105 Compare April 18, 2026 03:45
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.

Comment thread src/bridge/detection.rs Outdated
Comment thread src/build_options.rs
@messense messense force-pushed the fix/conditional-abi3-matches-any branch from 4e4d105 to 6ea12ff Compare April 18, 2026 04:54
@messense messense requested a review from Copilot April 18, 2026 04:55
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 conditional pyproject.toml features and introduces upgrade_bridge_abi3() to apply them after interpreter resolution.
  • Updates builder/orchestrator logic to keep bridge inference consistent with feature resolution (especially when CLI --features overrides 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.

Comment thread src/build_options.rs
Comment thread src/build_options.rs
Comment thread src/bridge/detection.rs Outdated
Comment thread src/build_orchestrator.rs
Comment thread src/bridge/detection.rs Outdated
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].
@messense messense force-pushed the fix/conditional-abi3-matches-any branch from 6ea12ff to 3c6523d Compare April 18, 2026 05:08
@messense messense merged commit 3da2fd1 into PyO3:main Apr 18, 2026
45 checks passed
@messense messense deleted the fix/conditional-abi3-matches-any branch April 18, 2026 05:46
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.

1.13: conditional features python-version predicate ignored, abi3 applied unconditionally

2 participants