Use Postgres as meson wrap subproject
It is not possible to use Postgres as meson wrap subproject at least out of box. But I think it can be easily fixed. I made a small patch for libpq and it works. There were two problems, first is catalog header generator using @SOURCE_DIR@ as root for paths, which will use main root project as source dir, so I just changed it to meson.project_source_root(). Second was that libpq dependency include_directories had no dependent headers(for example postgres_ext.h) so I just used include_directories that were also used in libpq_so, libpq_st. So the patch looks like this for commit 955f5506863dce0a3416e3fae7c3297dbbaa946d:
diff --git a/src/include/catalog/meson.build b/src/include/catalog/meson.build
index ec1cf46..2b12e8e 100644
--- a/src/include/catalog/meson.build
+++ b/src/include/catalog/meson.build
@@ -136,7 +136,7 @@ generated_catalog_headers = custom_target('generated_catalog_headers',
command: [
perl,
files('../../backend/catalog/genbki.pl'),
- '--include-path=@SOURCE_ROOT@/src/include',
+ '--include-path=' + (meson.project_source_root() / 'src/include'),
'--set-version=' + pg_version_major.to_string(),
'--output=@OUTDIR@', '@INPUT@'
],
diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build
index b259c99..51e051f 100644
--- a/src/interfaces/libpq/meson.build
+++ b/src/interfaces/libpq/meson.build
@@ -82,7 +82,7 @@ libpq_so = shared_library('libpq',
libpq = declare_dependency(
link_with: [libpq_so],
- include_directories: [include_directories('.')]
+ include_directories: [libpq_inc, postgres_inc]
)
# Check for functions that libpq must not call. See libpq_check.pl for the
Example of wrap file that applies patch:
[wrap-git]
url = https://git.postgresql.org/git/postgresql.git
revision = 955f5506863dce0a3416e3fae7c3297dbbaa946d
depth = 1
diff_files = postgres/libpq.patch
[provide]
libpq = libpq
So to use Postgres as wrap subproject u need to change @SOURCE_DIR@ to meson.project_source_root() and check include_directories for all dependencies. Is there any plans to support it?
On 12/23/25 4:21 PM, Niyaz Hazigaleyev wrote:
So to use Postgres as wrap subproject u need to change @SOURCE_DIR@ to meson.project_source_root() and check include_directories for all dependencies. Is there any plans to support it?
Thanks for the patch!
There was an earlier patch[1] for this from Elliot Haisley which looks
more complete that Andres seemed a bit interested in but as far as I
know no progress has been made on it recently. You could help out by
testing it out and reviewing it.
Out of curiosity since I am quite new to Meson: what is your personal
use case for wrap subprojects?
References
1.
/messages/by-id/PH0PR84MB1954C7D61C4882403B8258708605A@PH0PR84MB1954.NAMPRD84.PROD.OUTLOOK.COM
Andreas
You right Eliot Haisley more complete patch because he replaced all occurrences of @SOURCE_DIR@ but I also added include_directories to dependency, so it will not fail to find headers which are included in libpq headers. So if I merge my patch with Eliot’s it should be fine. I can send complete patch after it’s done.
About meson wrap subproject. In my projects I really like to have fallback if there is no system lib available or system lib have not compatible version. Basically I use it as package manager for my C/C++ projects, I just put the link to git into wrap file, provide dependency and that’s it, meson does all the work. Ideally everything in my project should be build from scratch without any prebuilt binaries, so I can cross-compile to any platform that I want and build/packaging of project becomes much easier.
Show quoted text
3 янв. 2026 г., в 04:54, Andreas Karlsson <andreas@proxel.se> написал(а):
On 12/23/25 4:21 PM, Niyaz Hazigaleyev wrote:
So to use Postgres as wrap subproject u need to change @SOURCE_DIR@ to meson.project_source_root() and check include_directories for all dependencies. Is there any plans to support it?
Thanks for the patch!
There was an earlier patch[1] for this from Elliot Haisley which looks more complete that Andres seemed a bit interested in but as far as I know no progress has been made on it recently. You could help out by testing it out and reviewing it.
Out of curiosity since I am quite new to Meson: what is your personal use case for wrap subprojects?
References
1. /messages/by-id/PH0PR84MB1954C7D61C4882403B8258708605A@PH0PR84MB1954.NAMPRD84.PROD.OUTLOOK.COM
Andreas
On 1/4/26 8:32 PM, Niyaz Hazigaleyev wrote:
You right Eliot Haisley more complete patch because he replaced all occurrences of @SOURCE_DIR@ but I also added include_directories to dependency, so it will not fail to find headers which are included in libpq headers. So if I merge my patch with Eliot’s it should be fine. I can send complete patch after it’s done.
Did you see that Tristan also just patched his own version which seems
like it could potentially be even more complete?
/messages/by-id/DFEOAWQP27I8.3LHIXYEFCXD25@partin.io
About meson wrap subproject. In my projects I really like to have fallback if there is no system lib available or system lib have not compatible version. Basically I use it as package manager for my C/C++ projects, I just put the link to git into wrap file, provide dependency and that’s it, meson does all the work. Ideally everything in my project should be build from scratch without any prebuilt binaries, so I can cross-compile to any platform that I want and build/packaging of project becomes much easier.
Thanks!
Andreas
Import Notes
Reply to msg id not found: E83EC4BD-6336-41CA-86A1-5FD0519EFF14@gmail.com
You right, Tristan made even more. At this point I just move to the original thread. Thanks Andreas!
Show quoted text
5 янв. 2026 г., в 04:09, Andreas Karlsson <andreas@proxel.se> написал(а):
On 1/4/26 8:32 PM, Niyaz Hazigaleyev wrote:
You right Eliot Haisley more complete patch because he replaced all occurrences of @SOURCE_DIR@ but I also added include_directories to dependency, so it will not fail to find headers which are included in libpq headers. So if I merge my patch with Eliot’s it should be fine. I can send complete patch after it’s done.
Did you see that Tristan also just patched his own version which seems like it could potentially be even more complete?
/messages/by-id/DFEOAWQP27I8.3LHIXYEFCXD25@partin.io
About meson wrap subproject. In my projects I really like to have fallback if there is no system lib available or system lib have not compatible version. Basically I use it as package manager for my C/C++ projects, I just put the link to git into wrap file, provide dependency and that’s it, meson does all the work. Ideally everything in my project should be build from scratch without any prebuilt binaries, so I can cross-compile to any platform that I want and build/packaging of project becomes much easier.
Thanks!
Andreas