`fixup_for_abi3_version` downgrades version causing wrong link library name when cross-compiling for Android
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
Bug Description
When cross-compiling an abi3 extension module for Android with PYO3_CROSS_LIB_DIR pointing to a Python 3.14 installation (via build-details.json), the linker fails with:
ld.lld: error: unable to find library -lpython3.7m
The target has Python 3.14, but pyo3 generates -lpython3.7m instead.
See the full CI log: https://github.com/PyO3/maturin-action/actions/runs/24198305015/job/70634639917
Root Cause
In from_pyo3_config_file_env(), after reading the config file (which has version=3.14, abi3=false), the following happens:
config.abi3 |= is_abi3()→ setsabi3 = true(from Cargo feature)config.fixup_for_abi3_version(get_abi3_version())→ unconditionally setsself.version = 3.7(fromabi3-py37minimum)apply_default_lib_name_to_config_file()→ computeslib_namefrom the now-downgraded version 3.7default_lib_name_unix()for version 3.7 returns"python3.7m"(themabiflag workaround for <= 3.7)- Since
is_linking_libpython_for_target()returnstruefor Android, this incorrect library name is emitted as-lpython3.7m
The fundamental problem is that fixup_for_abi3_version downgrades version to the abi3 minimum, but version is then also used to derive the link library name. The abi3 minimum version is relevant for the Python C API compatibility level, but the link library should match the actual target Python installation, not the abi3 minimum.
Steps to Reproduce
- Set up cross-compilation for
aarch64-linux-android - Download the Android Python 3.14 standalone build
- Set
PYO3_CROSS_LIB_DIRto the Python prefix/lib directory (containingbuild-details.json) - Build an abi3 pyo3 crate (e.g., with
abi3-py37feature)
The build will fail with unable to find library -lpython3.7m.
Environment
- pyo3 v0.28.2
- Target:
aarch64-linux-android - Python: 3.14.3 (standalone Android build from python.org)
- maturin sets
PYO3_CONFIG_FILEwithversion=3.14,abi3=false,lib_dir=<PYO3_CROSS_LIB_DIR>
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing from from_pyo3_config_file_env(), fixup_for_abi3_version(), apply_default_lib_name_to_config_file(), and default_lib_name_unix() in the Rust source. Reproduce the Android cross-compilation case with PYO3_CROSS_LIB_DIR and build-details.json, then verify the emitted link library name matches the target Python installation rather than the abi3 minimum.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- build-system, mobile-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 50/100