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
WIP: Add native pkg-config implementation #7650
base: master
Are you sure you want to change the base?
Conversation
|
This pull request introduces 1 alert when merging 90e4515 into 6f74692 - view on LGTM.com new alerts:
|
|
Conceptually, this looks like a good addition. However, I have some minor issues with the implementation:
|
It's surprisingly not that far from complete actually. It's only missing support for sys_root and define_variable, at least in my local version. It can be disabled by setting PKG_CONFIG=pkg-config in the env, but I think as a first step to get feedback it could be changed to keep using pkg-config by default, and use the internal implementation only if PKG_CONFIG=meson for example.
Never understood why we are sacrificing code readability for this, if I wanted type safety I would write C++. Anyway, I'll do, yes.
What's the advantage for simple os.path.join()? |
Then I am afraid that no one will use it and we won't get bug reports for the edge cases... However, if it is really near 100% complete and there is good test coverage, then I would say that setting
Type safety is exactly the reason we want it because we use
|
|
This pull request introduces 2 alerts when merging f6927fc into 6f74692 - view on LGTM.com new alerts:
|
Unless PKG_CONFIG is set in env or pkgconfig is set in machine file, in which case we have to use the binary provided by user because it could be a wrapper that sets some env. Add internal `meson pkg-config` command line mimicking pkg-config CLI. It is far from complete and only expose features required by PkgConfigDependency.
|
This pull request introduces 1 alert when merging bdc58b3 into 6fc0673 - view on LGTM.com new alerts:
|
|
+1 for using pathlib. We need to start using it more consistently everywhere in Meson too. The biggest advantage for me is that treating paths as strings has always been silly, and using Path objects is much better because for one it stops people from doing string manipulation that assumes platform-specific things. |
We may like to import some of pkgconf's tests (the ones that are relevant to the subset of features we implement). The pkgconf testsuite is very extensive.
|
use pkgconf : https://git.sr.ht/~kaniini/pkgconf |
|
As someone who wrote an independent implementation of pkg-config from scratch (pkgconf) I can tell you that it's not as easy as it looks initially. Meson, of course, is free to do as it wishes, but this is likely to create problems for the entire ecosystem, as Meson will likely handle edge cases differently from system pkg-config implementation. This will lead to confusion among developers and other consumers of Meson. And before you say there isn't any possibility of edge cases, I can assure you there are many cases where pkgconf and pkg-config have behaved differently in the past. People demand consistency, even when consistency involves emulating bugs and design defects in the original. Meson will be expected to do the same in it's tool. An alternative would be to use libpkgconf, of which a python binding could be created easily. This gets you the benefits of not having to run a pkg-config implementation frequently while relieving you of the burden of maintaining a new pkg-config implementation which is likely to have inconsistent behavior with system pkg-config. If this goes forward, we will have to start scrutinizing bug reports from Meson users because we have no way of knowing if they are actually using pkgconf or the built in one, and users will likely just blame us for your differences in behavior regardless. I implore you to consider the situation carefully for the ecosystem at large. |
|
I should also mention that it is likely that distributions will either patch this feature out or set |
|
Note that this is an experiment and I'm not pushing it forward at the moment, it is still a long way to be completed, mostly to get unit tests to pass. Unfortunately we cannot use pkgconf in process because meson sticky depend only on pure python. It is a design decision to not use any native code. We can however use pkgconf CLI. I personally do not think that there are that many edge cases, because meson only needs a subset of pkg-config. The hard part is in the CLI that I do not attempt to replicate. Meson already rewrite args it gets from the CLI a lot. But I can be wrong of course, it's too early to know because I did not write specific tests yet. |
|
The edge cases are unrelated to the CLI, but how the dependency solver works, or what the maximum length of a fragment is. We have reports where there are pc files with single lines that are 64KB long. That sort of thing is what I mean when I say edge case. Problem is pkg-config is unspecified. There are areas where pkgconf does not behave the same as freedesktop pkg-config, and there will be areas where the Meson implementation behaves differently as well. No two implementations are completely the same, unfortunately. |
This sounds like a lot of fun and should ideally be changed at some point. |
|
@mgorny started working on a formal specification based on pkgconf's behaviour back in 2012, but there wasn't really much interest in it then: the freedesktop implementation maintainer was not interested at all, so he abandoned the effort. that could be a starting point for a new spec though. but then you run into problems where people did things allowed by one or another implementation that is technically bad practice -- should those bad practices be allowed in a specification? |
|
Tbh if I had to write a real spec I would scrap that format completely and base or on json or any format that already have solid parsers. pkg-config has so many issues I don't understand how it made it so far |
Yep, upstream pretty much said they want to able to change it arbitrarily at any point and not have to abide by any spec. I don't see how the spec would help if the 'primary' implementation can just randomly choose to violate it.
Exactly the problem with writing specs for code written before. See how HTML ended up. |
it's not clear, did you test this with pkgconf or real pkgconfig? my understanding is that pkgconf is (usually) much faster.
these parts seems to conflict with further discussion. wouldn't this only work with meson version, so projects using them would be incompatible with system pkg-config? |
|
At this point the primary implementation is pkgconf outside of Ubuntu and some Debian systems, so a spec may be more relevant now. I see pkgconf as mostly complete these days outside of Windows-specific issues. And so a spec would be good. Then meson could code against the spec for cases where pkgconf is unavailable or the user wants to use meson's version directly. Meson is also the primary consumer of pkgconf on Windows so replacing it with a native version would reduce our Windows issues (which are mainly different parties expecting different output for their own use case on Windows). |
SYSROOT is mainly for embedded use (cross compilation). pkgconf and freedesktop pkg-config have wildly different opinions on how SYSROOT should be supported. Meson doing whatever they want here doesn't seem like a huge problem as it's already something where you have to choose an implementation that behaves as you wish. |
It was using pkgconf. That would have to be profiled further of course, but I think it's hitting a hard limit where the bottleneck is spawning new process and read all needed pc files again and again. The only way for improve that is to have it in-process. I did not try on Windows but I'm expecting the difference to be much bigger there. The important part in those numbers is that the python implementation only spend 0.053s in the parser, so there is no further improvements to be expected. There is no point in optimizing the python code or using a native libpkgconf from a pure performance point of view. It would at best save a few miliseconds.
To be fair, this could be done by using libpkgconf. I'm sure if we go that way we can always add the needed APIs as needed. I believe this is however too complicated to have CLI for it, unless some has suggestions?
Support for this can be added in pkgconf CLI of course. After discussion with @kaniini there is will probably be done with new env var PKG_CONFIG_SYSROOT_MAP I suggested. I personally don't mind requiring pkgconf over pkg-config to have those kind of use-case working.
When writing this PR I wanted to have PKG_CONFIG_SYSROOT_DIR set |
|
As mentioned on IRC...
I do not see the problem with meson containing a ctypes interface to libpkgconf in Alternatively, it might be nice for pkgconf to ship with its own bindings, either via ctypes or the C-API. It would then be possible to Users could then |
No idea how PKG_CONFIG_SYSROOT_MAP would work, but for the record, I patched pkg-config to support for multiple sysroots: |
This adds a python parser for pkg-config files and use it in PkgConfigDependency, unless a binary is set in PKG_CONFIG env or in machine files in which case we are forced to still use it because it would be a wrapper that sets some env.
Note that this also add a command line
meson pkgconfigthat mimick pkg-config CLI, I've been using it for testing purpose. I'm not aiming at having any kind of CLI compatibility at all, that would add way too much complexity, I'm targetting only the subset of the features PkgConfigDependency needs.Reasons:
PkgConfigDependency._call_pkgbinand we now spend 0.053s in our custom parser.dependency('gstreamer-1.0')we could detect that gstreamer's pc file requires glib and either abort or replace it by the subproject dependency.