fix: set explicit lib_name in pyo3 config for Android abi3 cross-compilation#3130
Conversation
39c94ce to
185b16c
Compare
There was a problem hiding this comment.
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_fileto accept aTargetand emitlib_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. |
185b16c to
165519d
Compare
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
165519d to
1254b69
Compare
There was a problem hiding this comment.
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_fileto accepttargetandabi3, and (on Android) emit an explicitlib_namesuitable 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. |
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