Skip to content

Use a common helper to determine applicable stable ABI builds#6192

Open
ngoldbaum wants to merge 3 commits into
PyO3:mainfrom
ngoldbaum:fix-stable-abi-3.14t
Open

Use a common helper to determine applicable stable ABI builds#6192
ngoldbaum wants to merge 3 commits into
PyO3:mainfrom
ngoldbaum:fix-stable-abi-3.14t

Conversation

@ngoldbaum

@ngoldbaum ngoldbaum commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Fixes #6176.

Replaces the inconsistent implementations of this logic with a call into a shared helper.

Unfortunately PythonAbi::from_build_env is public API so I had to deprecate it. I landed on new PythonAbi::from_stable_abi function to replace it. It accepts an explicit Option<(StableAbi, PythonVersion) argument. The explicit StableAbi in the tuple allows selecting the target stable ABI, which isn't passed into from_build_env.

I also had to change the signature of a few functions to accept a Option<StableAbiVersion> instead of an Option<PythonVersion>. The former allows disambiguating between "no stable ABI version requested" and "no stable ABI requested at all".

I made this fix in two commits, the first can be backported for 0.29.1 (#6151) and fixes the issue reported in #6176.

AI disclosure

I used an AI harness to help debug this and iterate on the solution.

Comment thread newsfragments/6192.fixed.md Outdated
Comment thread pyo3-build-config/src/impl_.rs
@ngoldbaum ngoldbaum force-pushed the fix-stable-abi-3.14t branch from acc5145 to 41d139c Compare July 7, 2026 14:55
@ngoldbaum

Copy link
Copy Markdown
Contributor Author

Updated with a force-push so the first commit can still be backported.

@davidhewitt davidhewitt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks, sorry to post a second round of review.

Comment thread pyo3-build-config/src/impl_.rs Outdated
/// `abi3-py3*`/`abi3t-py3*` cargo features, ignoring them (in favor of a
/// version-specific build) when the interpreter cannot target the
/// requested stable ABI. Must be called from a PyO3 crate build script.
pub fn from_cargo_features(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Possibly private

Suggested change
pub fn from_cargo_features(
fn from_cargo_features(

Comment thread pyo3-build-config/src/impl_.rs Outdated
Comment on lines +613 to +662
let target_abi = PythonAbi::from_build_env(implementation, version, None, gil_disabled)?;
let stable_abi =
applicable_stable_abi_at_interpreter_version(implementation, version, gil_disabled);
let target_abi =
PythonAbi::from_stable_abi(implementation, version, stable_abi, gil_disabled)?;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking again, I wonder if this function from_sysconfigdata (is public) should be purely about parsing that sysconfigdata and selecting a version-specific ABI with no pollution from pyo3 features (almost feels like a bug that it isn't).

Would mean deferring actual target abi selection and lib name to cross_compile_from_sysconfigdata, probably.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It turns out make_cross_compile_config runs apply_build_env() on everything cross_compile_from_sysconfigdata returns so we can just add a dummy version-specific target ABI in this function.

It is a behavior change though so it doesn't go in the backport commit.

@ngoldbaum ngoldbaum force-pushed the fix-stable-abi-3.14t branch from 41d139c to c10afb8 Compare July 7, 2026 20:16
@ngoldbaum ngoldbaum force-pushed the fix-stable-abi-3.14t branch from c10afb8 to bb4d4ab Compare July 7, 2026 21:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

abi3t-* feature hard-errors on a valid free-threaded config from PYO3_CONFIG_FILE, even though it doesn't request abi3

2 participants