Subject: Re: Meson build updates

From: "Tristan Partin" <[email-masked]>
Date: Thu, 29 Jun 2023 14:07:19 -0500

On Thu Jun 29, 2023 at 2:02 PM CDT, Andres Freund wrote:
> Hi,
>
> On 2023-06-13 14:56:36 -0500, Tristan Partin wrote:
> > I was thinking today. When you initially wrote the build, did you try
> > using the src/bin/meson.build file as the place where all the binaries
> > were built? As you say, most of the src/bin/xxx/meson.build files are
> > extrememly reptitive.
>
> > We had a similar-ish issue in my last project which I solved like:
> > 
> > https://github.com/hse-project/hse/blob/master/tools/meson.build#L20-L405
> > 
> > This is a pattern I used quite frequently in that project. One benefit
> > of this approach is that the binaries all end up next to each other in
> > the build tree which is eventually how they'll be laid out in the
> > install destination. The other benefit is of course reducing reptitive
> > code.
>
> I think the build directory and the source code directory not matching in
> structure would have made it considerably harder sell for people to migrate.
>
> I.e. I considered it, but due to meson's "no outputs outside of the current
> directory" rule, it didn't (and sadly still doesn't) really seem viable.

Yeah, I guess it is a matter if you like the layout being closer to the
installation or the source tree at the expense of repetition. I am
partial to the installation since it is less to type if you run a binary
from the build directory and less repetition, but all good. Maybe
something that could be reconsidered when autotools is dropped.

I still think the overrides are important, at the very least for libpq,
but I will defer to your aforementioned decision for now.

-- 
Tristan Partin
Neon (https://neon.tech)

---

From: Andres Freund <[email-masked]>
Date: Thu, 29 Jun 2023 12:13:08 -0700

Hi,

> but I will defer to your aforementioned decision for now.

libpq makes sense to me, fwiw. Just doing it for all binaries individually
didn't seem as obviously beneficial.

FWIW, it seems it could be handled somewhat centrally for binaries, the
bin_targets array should have all that's needed?

Some things won't work from the build directory, btw. E.g. initdb or postgres
itself.

Greetings,

Andres Freund

---

From: "Tristan Partin" <[email-masked]>
Date: Thu, 29 Jun 2023 14:17:30 -0500

> bin_targets array should have all that's needed?

I will send a follow-up patch with at least libpq overridden. I will
investigate the bin_targets.

> Some things won't work from the build directory, btw. E.g. initdb or postgres

I have already fallen victim to this! Lesson learned :).

-- 
Tristan Partin
Neon (https://neon.tech)

---

From: "Tristan Partin" <[email-masked]>
Date: Wed, 12 Jul 2023 11:10:21 -0500

> investigate the bin_targets.

Attached is a patch which does just that without overriding the
binaries. I investigated the bin_targets stuff, but some test
executables get added there, so it wouldn't work out that well.

-- 
Tristan Partin
Neon (https://neon.tech)
From b52a13d1575e4965e8c1794e7a62f24ecfeeb1cf Mon Sep 17 00:00:00 2001
From: Tristan Partin <[email-masked]>
Date: Wed, 17 May 2023 10:36:52 -0500
Subject: [PATCH v6] Add Meson override for libpq

Meson has the ability to do transparent overrides when projects are used
as subprojects. For instance, say I am building a Postgres extension. I
can define Postgres to be a subproject of my extension given the
following wrap file:

[wrap-git]
url = https://git.postgresql.org/git/postgresql.git
revision = master
depth = 1

[provide]
dependency_names = libpq

Then in my extension (root project), I can have the following line
snippet:

libpq = dependency('libpq')

This will tell Meson to transparently compile libpq prior to it
compiling my extension (because I depend on libpq) if libpq isn't found
on the host system.
---
 src/interfaces/libpq/meson.build | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/interfaces/libpq/meson.build b/src/interfaces/libpq/meson.build
index 80e6a15adf..6d18970e81 100644
--- a/src/interfaces/libpq/meson.build
+++ b/src/interfaces/libpq/meson.build
@@ -84,6 +84,8 @@ libpq = declare_dependency(
   include_directories: [include_directories('.')]
 )
 
+meson.override_dependency('libpq', libpq)
+
 pkgconfig.generate(
   name: 'libpq',
   description: 'PostgreSQL libpq library',
-- 
Tristan Partin
Neon (https://neon.tech)