PyO3 / PyO3/pyo3

`fixup_for_abi3_version` downgrades version causing wrong link library name when cross-compiling for Android

Open
#5,960 7 comments 0 reactions 0 assignees View on GitHub

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:

  1. config.abi3 |= is_abi3() → sets abi3 = true (from Cargo feature)
  2. config.fixup_for_abi3_version(get_abi3_version()) → unconditionally sets self.version = 3.7 (from abi3-py37 minimum)
  3. apply_default_lib_name_to_config_file() → computes lib_name from the now-downgraded version 3.7
  4. default_lib_name_unix() for version 3.7 returns "python3.7m" (the m abiflag workaround for <= 3.7)
  5. Since is_linking_libpython_for_target() returns true for 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

  1. Set up cross-compilation for aarch64-linux-android
  2. Download the Android Python 3.14 standalone build
  3. Set PYO3_CROSS_LIB_DIR to the Python prefix/lib directory (containing build-details.json)
  4. Build an abi3 pyo3 crate (e.g., with abi3-py37 feature)

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_FILE with version=3.14, abi3=false, lib_dir=<PYO3_CROSS_LIB_DIR>

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.