mesonbuild / mesonbuild/meson-python
libdir inexplicitly overriden when installing a shared library from a subproject
Nessuno ha ancora preso questa issue.
- Lingua principale
- Python
- Stelle
- 180
- Fork
- 93
- Merge medio
- 2g 7h
- PR unite (30g)
- 18
Descrizione
I'm building a [ctypes](https://docs.python.org/3/library/ctypes.html)-based Python wrapper for a library provided as a subproject.
I would expect such a project to have a simple layout of `foo/__init__.py`, `foo/wrapper.py` and `foo/libfoo.so`, like in https://github.com/joerick/python-ctypes-package-sample or even https://github.com/peppedilillo/meson-ctypes-test.
The compiled library does the following in `subprojects/foo/meson.build`:
```meson
foo_tgt = custom_target(
'foo',
output: 'libfoo.so',
command: [...],
install: true,
install_dir: get_option('libdir'),
)
```
It's a custom_target, because it's actually another wrapper, but the same issue persists with `shared_library`.
My `meson.build` looks like this:
```meson
project('foo-python')
py = import('python').find_installation(pure: false)
py.install_sources(
'foo/__init__.py',
'foo/wrapper.py',
preserve_path: true,
)
subproject(
'foo',
default_options: {
'libdir': py.get_install_dir() / 'foo',
},
)
```
foo/wrapper.py attempts to load the shared library with a simple `ctypes.cdll.LoadLibrary(str(Path(__file__).with_name("libfoo.so")))`.
And even though I explicitly specify the `libdir`, the built wheel contains the .so file in a completely arbitrary location:
```terminal
$ python -m build -w
...
Successfully built foo-0.1.0-cp313-cp313-linux_x86_64.whl
$ unzip -l dist/foo-0.1.0-cp313-cp313-linux_x86_64.whl
Archive: dist/foo-0.1.0-cp313-cp313-linux_x86_64.whl
Length Date Time Name
--------- ---------- ----- ----
149 2025-11-01 14:50 foo-0.1.0.dist-info/METADATA
88 2025-11-01 14:50 foo-0.1.0.dist-info/WHEEL
1360680 2025-11-01 14:49 .foo.mesonpy.libs/libfoo.so
532 2025-11-01 14:17 foo/__init__.py
22526 2025-11-01 14:18 foo/wrapper.py
507 2025-11-01 14:50 foo-0.1.0.dist-info/RECORD
--------- -------
1389847 7 files
```
In this case I would expect libfoo.so to be placed in `foo/libfoo.so`.
This issue only persists when using subprojects. Without them, it's possible to simply do `custom_target(..., install: true, install_dir: py.get_install_dir() / 'foo')` (or the same with shared_library), as evidenced in https://github.com/peppedilillo/meson-ctypes-test (also related - https://github.com/mesonbuild/meson-python/discussions/573).
Seems to also be related to https://github.com/mesonbuild/meson-python/discussions/770.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Riproduci l’installazione con i file meson.build mostrati eseguendo python -m build -w, quindi ispeziona la wheel generata con unzip -l. Traccia come viene gestito install_dir di subproject custom_target o shared_library, includendo py.get_install_dir() e l’output .foo.mesonpy.libs. Il lavoro è completato quando la libreria condivisa viene installata come foo/libfoo.so, mentre il wrapper e i file del pacchetto rimangono utilizzabili.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- python
- Ambito
- build-system
- Tipo di issue
- Bug
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100