mesonbuild / mesonbuild/meson-python

RPATH goes missing when using both `install_rpath` and an internal shared library dependency

Aperta
#711 8 commenti 1 reazione 0 assegnatari Vedi su GitHub

@dnicolodi ci sta già lavorando.

Dal 10/8/2025.

  • #788 di @dnicolodi — aperta
bug
Lingua principale
Python
Stelle
180
Fork
93
Merge medio
2g 7h
PR unite (30g)
18

Descrizione

This is a case that probably hasn't been exercised before: a Python extension module that links against both a shared library that's part of the package _and_ a shared library built in a subproject that's folded into the wheel by `meson-python`.

I ran into this in SciPy when adding a subproject. This worked as advertised, except for [this `scipy.special._ufuncs`](
https://github.com/scipy/scipy/blob/dd08de8c9b0e2726f5688a8b76a699c1f28e6514/scipy/special/meson.build#L144-L162) extension module, which depends on [this `libsf_error` shared library](https://github.com/scipy/scipy/blob/dd08de8c9b0e2726f5688a8b76a699c1f28e6514/scipy/special/meson.build#L36-L42) as well as on the library in the subproject.
What one sees then is that the installed wheel can no longer find `libsf_error.so`, because the RPATH entry for `install_rpath: '$ORIGIN'` goes missing.

With a default SciPy build (no subproject), the `Library rpath|runpath` entries on the `_ufuncs` target in the build and install directories looks like this (has `$ORIGIN` as it should):
```bash
$ readelf -d build/scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so | rg "Library r"
0x000000000000000f (RPATH) Library rpath: [/home/rgommers/mambaforge/envs/scipy-dev-py312/lib:$ORIGIN/]

$ readelf -d build-install/lib/python3.12/site-packages/scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so | rg "Library r"
0x000000000000000f (RPATH) Library rpath: [$ORIGIN:/home/rgommers/mambaforge/envs/scipy-dev-py312/lib]
```

On the branch with the subproject, we see this instead:
```bash
$ readelf -d build-whl/scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so | rg Library
0x000000000000001d (RUNPATH) Library runpath: [/home/rgommers/code/pixi-dev-scipystack/scipy/.pixi/envs/openblas-src/lib:$ORIGIN/../../.scipy.mesonpy.libs:$ORIGIN/../../.scipy.mesonpy.libs:$ORIGIN/../../.scipy.mesonpy.libs:$ORIGIN/../../.scipy.mesonpy.libs]

$ readelf -d site-packages/scipy/special/_ufuncs.cpython-312-x86_64-linux-gnu.so | rg "Library r"
0x000000000000001d (RUNPATH) Library runpath: [/home/rgommers/code/pixi-dev-scipystack/scipy/.pixi/envs/openblas-src/lib:$ORIGIN/../../.scipy.mesonpy.libs:$ORIGIN/../../.scipy.mesonpy.libs:$ORIGIN/../../.scipy.mesonpy.libs:$ORIGIN/../../.scipy.mesonpy.libs]
```
The duplication of the `.scipy.mesonpy.libs` entries is a minor stylistic issue, we may be able to de-duplicate but it doesn't matter. What does matter is that `$ORIGIN` is no longer present.

This looks like a bug in the `fix_rpath` implementation at:
https://github.com/mesonbuild/meson-python/blob/91d64d1d08aa2702ceaf1bde3edc53d69429100e/mesonpy/_rpath.py#L28-L36

The problem seems clear: all RPATH entries are cleared, and the ones that are added back all get `libs_relative_path` appended (i.e. to the subproject-relocated location). Any existing RPATHs within the package, like `'$ORIGIN'`, will get lost.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Esamina mesonpy/_rpath.py, in particolare fix_rpath alle righe indicate, e riproduci il caso usando i target SciPy di meson.build e i comandi readelf mostrati. Il lavoro è completato quando il wheel installato conserva la voce $ORIGIN esistente e aggiunge anche i percorsi alle librerie dei sottoprogetti spostati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
build-system
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.