Skip to content

fix: set explicit lib_name in pyo3 config for Android abi3 cross-compilation#3130

Merged
messense merged 1 commit into
PyO3:mainfrom
messense:fix/android-abi3-lib-name
Apr 14, 2026
Merged

fix: set explicit lib_name in pyo3 config for Android abi3 cross-compilation#3130
messense merged 1 commit into
PyO3:mainfrom
messense:fix/android-abi3-lib-name

Conversation

@messense

Copy link
Copy Markdown
Member

On Android, pyo3 forces linking libpython. When abi3 is enabled, pyo3's fixup_for_abi3_version downgrades the version to the abi3 minimum (e.g. 3.7) and derives a wrong lib_name like 'python3.7m'. Set lib_name explicitly in the pyo3 config file so pyo3 uses the actual target Python version instead of computing one from the downgraded abi3 minimum.

See PyO3/pyo3#5960

@messense messense force-pushed the fix/android-abi3-lib-name branch 2 times, most recently from 39c94ce to 185b16c Compare April 11, 2026 07:48
@messense messense requested a review from Copilot April 12, 2026 14:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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.

This PR fixes Android abi3 cross-compilation with PyO3 by explicitly setting lib_name in the generated PyO3 config so linking uses the target Python’s real versioned libpython instead of a lib name derived from the abi3-minimum version.

Changes:

  • Update pyo3_config_file to accept a Target and emit lib_name=... for Android targets.
  • Wire the updated API through the build environment configuration.
  • Add an Android-focused unit test for the emitted lib_name.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/python_interpreter/config.rs Adds Android-specific lib_name emission to the PyO3 config output and introduces an Android unit test.
src/compile.rs Updates the call site to pass Target into pyo3_config_file.

Comment thread src/python_interpreter/config.rs
@messense messense force-pushed the fix/android-abi3-lib-name branch from 185b16c to 165519d Compare April 14, 2026 11:28
@messense messense requested a review from Copilot April 14, 2026 11:29
On Android, pyo3 forces linking libpython. When abi3 is enabled, pyo3's
fixup_for_abi3_version downgrades the version to the abi3 minimum (e.g.
3.7) and derives a wrong lib_name like 'python3.7m'. Set lib_name
explicitly in the pyo3 config file: 'python3' for abi3 builds (stable
ABI) and 'python{major}.{minor}' for non-abi3 builds.

See PyO3/pyo3#5960

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 PyO3 cross-compilation on Android for abi3 builds by preventing PyO3 from deriving an incorrect lib_name from the downgraded abi3 minimum version, and instead writing an explicit lib_name into the generated PyO3 config file.

Changes:

  • Extend InterpreterConfig::pyo3_config_file to accept target and abi3, and (on Android) emit an explicit lib_name suitable for abi3 vs non-abi3.
  • Pass abi3 state from the build configuration into the generated PyO3 config file during cross compilation.
  • Add an Android-specific test validating the generated PyO3 config output (including lib_name).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/python_interpreter/config.rs Generates PyO3 config with Android-specific lib_name selection and adds tests for Android output.
src/compile.rs Passes target and abi3 mode into pyo3_config_file when writing PYO3_CONFIG_FILE during cross compilation.

Comment thread src/python_interpreter/config.rs
Comment thread src/python_interpreter/config.rs
Comment thread src/python_interpreter/config.rs
@messense messense merged commit e7278ed into PyO3:main Apr 14, 2026
45 checks passed
@messense messense deleted the fix/android-abi3-lib-name branch April 14, 2026 12:53
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.

2 participants