-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't compile Meson extensions against managed Python due to pkg-config #11028
Comments
cc @eli-schwartz since you've been active on meson-related issues; do you have context on the motivation for this behavior? I'm fine with patching the pkg-config files on install, as we do for the macOS dylib (#10629). Are you interested in contributing a fix? |
Happy to give it a shot. Time to put those Advent of Code Rust skills to use! |
Meson needs to know the "official interface flags" for linking to libpython, primarily:
Doing this accurately is a bit of a hodgepodge. The base code for implementing this is at https://github.com/mesonbuild/meson/blob/master/mesonbuild/dependencies/python.py Notice there are two methods: pkg-config, and sysconfig. The sysconfig method uses This will hopefully get a lot better when https://peps.python.org/pep-0739/ is approved and deployed, which guarantees that any platform can describe via JSON what pkg-config already consistently describes (but requires pkg-config to be installed, which is not necessarily the case on Windows).
python_info.py is used for discovery of various things pkg-config doesn't describe, like "whether you are in a venv" or "what are the standard paths for site-packages etc", "am I PyPY or CPython", "am I free-threaded", "what is the limited API suffix", etc. We also save the exhaustive details of every sysconfig variable, just in case we need it later on (and indeed it's needed for the guesswork in |
If the target from |
Currently it assumes the flags are trusted and passes them to the compiler -- it's the compiler that decides they aren't trusted. There are some nuances around for example |
Aside: thanks for pinging me on this. ❤️ I'm interested in helping people with meson issues and this overlaps with my interest in the python ecosystem / building code, so I'm absolutely comfortable with being pinged any time you have a question for me or simply think I'd be interested. But I only irregularly remember to check issue trackers, so it's best to summon me explicitly to ensure I notice. |
Would it help anything to make the .pc file use relative paths from
This appears to be what Meson's own If so then we can just make this change in python-build-standalone and avoid having to patch on install. |
Oh cool, that definitely seems like a better solution if it's viable. |
relocatable pkg-config files are a really bad tradeoff for a project that expects to be installed to a non-relocatable place, i.e. /usr and simply have done with. You never ever use the functionality, so any cost is too much. Furthermore, it results in paths such as So of course, openssl cannot simply use them and have done with, which was what that ticket was about. For python-build-standalone, the same tradeoffs can be made that meson makes when you explicitly enable relocation. You know, on a per project or per binary distribution basis, that it is very likely to be relocated, thus by default the flags are simply broken, but relocatable pkgconfig files transition it from being "broken all the time" to "working most of the time". That makes it very much worthwhile. Additionally, uv may not be concerned about people installing python using uv in order to cross compile with a sysroot. Probably, most people using sysroots have careful setups which include building cpython from source. Also, pkgconf is pretty popular these days and people generally don't use the original pkg-config (it isn't 2020 anymore!) So all in all I think you should use relocatable pkg-config files, yes. |
This ensures that e.g. `PKG_CONFIG_PATH=wherever/python/lib/pkgconfig pkg-config --cflags` gets you existent paths in wherever/ instead of nonexistent paths in /install.
This ensures that e.g. `PKG_CONFIG_PATH=/wherever/python/lib/pkgconfig pkg-config --cflags` gets you existent paths in /wherever/python instead of nonexistent paths in /install.
This ensures that e.g. `PKG_CONFIG_PATH=/wherever/python/lib/pkgconfig pkg-config --cflags` gets you existent paths in /wherever/python instead of nonexistent paths in /install.
Wait, I just saw we already patch the pkg-config files after extracting in #10189, which should be in the version of uv you're using - why isn't that helping here? (I was looking at a plain python-build-standalone tarball.) Does doing a |
... yes it does. Sorry for not catching that! There may still be value in making the pkg-config file relocatable upstream; it would make the |
Yes, absolutely - I kind of want to get to the point where uv is no longer patching anything from python-build-standalone. |
This ensures that e.g. `PKG_CONFIG_PATH=/wherever/python/lib/pkgconfig pkg-config --cflags` gets you existent paths in /wherever/python instead of nonexistent paths in /install.
If there's still interest in patching, https://github.com/bluss/sysconfigpatcher does already patch .pc files correctly from my past usage experience and it can serve as inspiration (or for testing). |
(@geofft -- Just confirming that, yes, we do already patch |
@samypr100 https://github.com/astral-sh/uv/blob/0.5.25/crates/uv-python/src/sysconfig/mod.rs does actually reference that project in the comments at the top, so I think that's approximately what we're currently doing. Thanks for the pointer, though, in the sense that it would be nice to make sure that, eventually, neither sysconfigpatcher nor the uv port is necessary :) |
My bad @charliermarsh, I completely missed .pc file patching was implemented a bit later after the initial round of patching PR's😆 (I thought it was still a TODO thing) |
…507) This ensures that e.g. `PKG_CONFIG_PATH=/wherever/python/lib/pkgconfig pkg-config --cflags` gets you existent paths in /wherever/python instead of nonexistent paths in /install.
Summary
When compiling a Python extension using Meson's
py_installation.extension_module()
, Meson looks for the Python development headers using pkg-config. Because the prefix in python-build-standalone'spc
file is/install
, the build fails.The sysconfig paths in PBS are fine, but for better or worse Meson tries pkg-config before sysconfig. There doesn't seem to be a universal way (e.g. one that works for subprojects) to use sysconfig before pkg-config in Meson, but even if there was, it seems like it would be preferable to fix the
pc
file.Is that possible? Could uv fix the
pc
file after extraction? I guess this wouldn't help non-uv PBS users, however.I realize this is documented, so apologies for raising a known issue! But it took a little sleuthing to figure out how Meson was even picking up this
/install
path, so I thought I'd at least share that here.For completeness, here's the
.pc
file:python-3.13.pc
Here's where Meson tries pkg-config before sysconfig: https://github.com/mesonbuild/meson/blob/0b9baf573bf2b1619d7822f67965a35391172625/mesonbuild/dependencies/python.py#L391
Here's the output of Meson's
python_info.py
script that uses sysconfig for discovery (looks fine):python_info.py output
And here's a typical compiler command that Meson emits, with
-I/install/...
:Compiler command
There's a constellation of sort-of similar uv issues around sysconfig variables (e.g. those linked from #8429), but I think in this case the issue is specifically with the pkg-config file. I couldn't find an existing issue about that.
Steps to reproduce
Here is a reproducer on a small project. I'm happy to work on making it more minimal if that would be helpful.
Platform
Rocky 8 Linux
Version
0.5.24
Python version
Python 3.13
The text was updated successfully, but these errors were encountered: