-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
add build option pkg_config_static
to make dependency() default to static
#6629
Conversation
I'm not sure to understand why this is needed, if you do dependency('glib-2.0', static : true) it should work, no? |
This patch is needed to cross-compile glib2 in buildroot, the build failure is not related to a meson package using glib2 so there is no "dependency('glib-2.0')". The issue is related to the building of glib2 itself. Without this patch, glib2 would have to be updated to add static: true or false to every dependency calls for example, glib2 retrieves the libmount dependency through: I also sent this patch to the buildroot's mailing list: https://patchwork.ozlabs.org/patch/1238548 so you can see how I use this new variable depending on the static or dynamic build configuration. We can also wait for their feedback. |
Hmm, I wondering if we would need something more fine grained than this.You don't necessary want to static link everything, but only a few. This is somewhat related to #4276 Just to be sure to understand your use-case, you have |
In any case, I don't think this is limited to pkg-config, the real feature needed here is to turn all (or some) |
You're right, my use case is that I only have libmount.a (and libblkid.a) and I want to build glib2 (including glib-2.0.pc). You're also right that this patch is somewhat basic as it only manages the buildroot use case. In buildroot, we only give three choices to the user for building his embedded linux system:
|
The commit message and pull request titles are confusing and don't message the reader "why do I want this?" -- as a result, reviewers are less likely to accept the PR because they don't know what it's supposed to do. Please update both to not share information about the file you're modifying (which is rarely if ever important information in a git commit message); instead, use a commit message like e.g.
|
Dumb question: if meson is already resolving detected libraries and passing them to the compiler command line as /path/to/libfoo.a, so it detects that only the .a is available, why doesn't it automatically re-run the pkg-config lookup command with --static? It's a bit broken to assume that the results of Given meson has so far avoided having a way to do something like |
pkg_config_static
to make dependency() default to static
That was my first thought too, but there is a reason explained in this comment: https://github.com/mesonbuild/meson/blob/master/mesonbuild/dependencies/base.py#L806. |
oh wait, maybe it falls into that case only if neither .so nor .a are found? If we are looking for a shared library and we found a static, I guess we could re-run with --static indeed, otherwise it's unlikely to work any way. |
Hmm, yes, but it has to be done recursively. Consider the following:
We call Since pkg-config's dependency resolution is opaque to us, we have no idea which There are two ways around this:
OR, we could just call the parent pcfile with |
@nirbheek Hmm, that quickly become much more complicated. tbh I would assume that if one .so is missing but it has its .a, then they are all missing. Worst case it over-link but still works, no? I mean, you'll re-run with --static, get more -lfoo and for those that have .so files will just be extra useless link flags. |
(got dragged here fom #6697)
There is no need for us to manually recurse in the libraries list provided by pkg-config, as that is already the full list. From the manpage:
Combined with
Well, I think overlinking is a red-hering. The |
Yeah, we should be using pkg-config as the authority on this one. |
Sadly that would be too easy. It returns a list of |
That is exactly the role of the linker (not the buildsystem like meson et al, or the compiler). The flags returned by pkg-config will also contain the necessary And of course, if one calls pkg-config with |
@yann-morin-1998 it's not that easy, you could want to static link some libs but not all. |
There are two cases here (forgive me if I use wrong terms, I am far from fluent in meson):
In the first case, when resolving the each library, we know (because that'w requested in meson.build) that it should be resolved statically or not. So when we call pkg-config for those library that are statically requested, we want to grab all its static dependencies and linker flags, and that's exactly what In the second case, we don't care what the user wrote in their meson.build: the buildsystem (or the human) above knows better and explicitly asks for a full static build. In this case, all calls to pkg-config should be made with -static, and that will work as expected. Sorry if I sounded dense, that's definitely not the goal. I know static linking is in essence a can of worms already, but some systems can only work with static libs (e.g. some noMMU embedded ARM stuff for example, or some trimmed-down, minimalist, single-app container images...). |
That's the case where meson has to resolve itself static libraries. When user explicitly request a static dependency, pkg-config just says "-lfoo" and the linker will pick the shared library when you have both installed. To fix that, meson replace -lfoo with the path to libfoo.a instead. Note that other dependencies could be shared, so we can't tell the linker to just static link everything.
That's a new use-case that has never been supported by Meson. This would require a new option, not limited to pkg-config, that would do:
|
If we're going to do this we really should have a builtin-option for this instead of a random field in the properties section of the cross/native file. |
Our pkg-config wrapper is not used since commit 4e0bc29, this raise static build failures with libglib2 because --static is not passed anymore to pkg-config so add a patch to get back the old behaviour. The patch was proposed upstream mesonbuild/meson#6629, and the feedback was not very positive. However, we need a solution that works for Buildroot now, and this proposal is simple enough. Fixes: http://autobuild.buildroot.org/results/0d36952def63cb69628697fa6408aeb6ce10cb5b Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Our pkg-config wrapper is not used since commit 4e0bc29, this raise static build failures with libglib2 because --static is not passed anymore to pkg-config so add a patch to get back the old behaviour. The patch was proposed upstream mesonbuild/meson#6629, and the feedback was not very positive. However, we need a solution that works for Buildroot now, and this proposal is simple enough. Fixes: http://autobuild.buildroot.org/results/0d36952def63cb69628697fa6408aeb6ce10cb5b Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com> (cherry picked from commit cf75d7d) Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
…static Allow the user to always call pkg-config with --static when choosing to build a project as fully static, to prevent missing library errors when only static dependencies are available. Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> [Romain: Fix if condition, pkg_config_static is a string not a boolean] Signed-off-by: Romain Naour <romain.naour@gmail.com>
IMO the right solution is to allow pkg-config return the correct set of flags automatically. |
Fix the following build failure raised since bump to version 0.3.39 in commit d9796f2 and https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/ddfbd684e78e2b8b9ad40bedb4612ea0197d231a: /home/giuliobenetti/autobuild/run/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/sh4-buildroot-linux-uclibc/9.3.0/../../../../sh4-buildroot-linux-uclibc/bin/ld: src/pipewire/libpipewire-0.3.so.0.339.0.p/pipewire.c.o: in function `i18n_ntext': pipewire.c:(.text+0x3ec): undefined reference to `libintl_dngettext' Indeed, since that time, pipewire uses the new meson intl dependency API which has been added in version 0.59.0 with mesonbuild/meson@2c6ccfe This new intl dependency API is broken (which is not so surprising based on my experience of meson). Don't even try to fix it as meson is not very prone to merge our pull requests: mesonbuild/meson#6108 mesonbuild/meson#6629 Fixes: - http://autobuild.buildroot.org/results/435d59d40209cc1028cee8e2a71a69cd3769ab56 Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Fix the following build failure raised since bump to version 0.3.39 in commit d9796f2 and https://gitlab.freedesktop.org/pipewire/pipewire/-/commit/ddfbd684e78e2b8b9ad40bedb4612ea0197d231a: /home/giuliobenetti/autobuild/run/instance-0/output-1/host/opt/ext-toolchain/bin/../lib/gcc/sh4-buildroot-linux-uclibc/9.3.0/../../../../sh4-buildroot-linux-uclibc/bin/ld: src/pipewire/libpipewire-0.3.so.0.339.0.p/pipewire.c.o: in function `i18n_ntext': pipewire.c:(.text+0x3ec): undefined reference to `libintl_dngettext' Indeed, since that time, pipewire uses the new meson intl dependency API which has been added in version 0.59.0 with mesonbuild/meson@2c6ccfe This new intl dependency API is broken (which is not so surprising based on my experience of meson). Don't even try to fix it as meson is not very prone to merge our pull requests: mesonbuild/meson#6108 mesonbuild/meson#6629 Fixes: - http://autobuild.buildroot.org/results/435d59d40209cc1028cee8e2a71a69cd3769ab56 Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Our pkg-config wrapper is not used since commit 4e0bc29, this raise static build failures with libglib2 because --static is not passed anymore to pkg-config so add a patch to get back the old behaviour. The patch was proposed upstream mesonbuild/meson#6629, and the feedback was not very positive. However, we need a solution that works for Buildroot now, and this proposal is simple enough. Fixes: http://autobuild.buildroot.org/results/0d36952def63cb69628697fa6408aeb6ce10cb5b Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Our pkg-config wrapper is not used since commit 4e0bc29, this raise static build failures with libglib2 because --static is not passed anymore to pkg-config so add a patch to get back the old behaviour. The patch was proposed upstream mesonbuild/meson#6629, and the feedback was not very positive. However, we need a solution that works for Buildroot now, and this proposal is simple enough. Fixes: http://autobuild.buildroot.org/results/0d36952def63cb69628697fa6408aeb6ce10cb5b Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Our pkg-config wrapper is not used since commit 4e0bc29, this raise static build failures with libglib2 because --static is not passed anymore to pkg-config so add a patch to get back the old behaviour. The patch was proposed upstream mesonbuild/meson#6629, and the feedback was not very positive. However, we need a solution that works for Buildroot now, and this proposal is simple enough. Fixes: http://autobuild.buildroot.org/results/0d36952def63cb69628697fa6408aeb6ce10cb5b Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Our pkg-config wrapper is not used since commit 4e0bc29, this raise static build failures with libglib2 because --static is not passed anymore to pkg-config so add a patch to get back the old behaviour. The patch was proposed upstream mesonbuild/meson#6629, and the feedback was not very positive. However, we need a solution that works for Buildroot now, and this proposal is simple enough. Fixes: http://autobuild.buildroot.org/results/0d36952def63cb69628697fa6408aeb6ce10cb5b Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Our pkg-config wrapper is not used since commit 4e0bc29, this raise static build failures with libglib2 because --static is not passed anymore to pkg-config so add a patch to get back the old behaviour. The patch was proposed upstream mesonbuild/meson#6629, and the feedback was not very positive. However, we need a solution that works for Buildroot now, and this proposal is simple enough. Fixes: http://autobuild.buildroot.org/results/0d36952def63cb69628697fa6408aeb6ce10cb5b Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
Allow the user to always call pkg-config with --static when choosing to build a project as fully static, to prevent missing library errors when only static dependencies are available.
Signed-off-by: Fabrice Fontaine fontaine.fabrice@gmail.com