The first two patches in the series are re-proposals that had previously been approved[0] by Andres, but fell through the cracks.

The only patch that _could_ be controversial is probably the last one, but from my understanding it would match up with the autotools build.

One thing that I did notice while testing this patch is that Muon doesn't build postgres without coercing the build a bit. I had to disable nls and plpython. The nls issue could be fixed with a bump to Meson 0.59, which introduces import(required:). nls isn't supported in Muon unfortunately at the moment. The plpython issue is that it doesn't understand pymod.find_installation(required:), which is a bug in Muon.

Muon development has slowed quite a bit this year. Postgres is probably the largest project which tries its best to support Muon. It seems like if we want to keep supporting Muon, we should get a buildfarm machine to use it instead of Meson to catch regressions. OR we should contemplate removing support for it.

Alternatively someone (me?) could step up and provide some patches to Muon to make the postgres experience better. But I wonder if any Postgres user even uses Muon to build it.

--
Tristan Partin
Neon (https://neon.tech)
From 462ea170b1410d7916a25ffa6d27dc45284db7e3 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tris...@neon.tech>
Date: Wed, 17 May 2023 10:36:52 -0500
Subject: [PATCH v1 2/7] 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)

From 5455426c9944ff8c8694db46929eaa37e03d907f Mon Sep 17 00:00:00 2001
From: Tristan Partin <tris...@neon.tech>
Date: Fri, 1 Sep 2023 11:07:40 -0500
Subject: [PATCH v1 7/7] Disable building contrib targets by default

This matches the autotools build.
---
 contrib/meson.build          | 4 +++-
 contrib/oid2name/meson.build | 2 +-
 contrib/vacuumlo/meson.build | 2 +-
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/contrib/meson.build b/contrib/meson.build
index 618b1c50c8..06c579def5 100644
--- a/contrib/meson.build
+++ b/contrib/meson.build
@@ -1,6 +1,8 @@
 # Copyright (c) 2022-2023, PostgreSQL Global Development Group
 
-contrib_mod_args = pg_mod_args
+# These will get built during test runs or if the contrib target is ran.
+contrib_bin_args = default_bin_args + { 'build_by_default': false }
+contrib_mod_args = pg_mod_args + { 'build_by_default': false }
 
 contrib_data_dir = dir_data_extension
 contrib_data_args = {
diff --git a/contrib/oid2name/meson.build b/contrib/oid2name/meson.build
index 171d2d226b..904c94a0e1 100644
--- a/contrib/oid2name/meson.build
+++ b/contrib/oid2name/meson.build
@@ -13,7 +13,7 @@ endif
 oid2name = executable('oid2name',
   oid2name_sources,
   dependencies: [frontend_code, libpq],
-  kwargs: default_bin_args,
+  kwargs: contrib_bin_args,
 )
 contrib_targets += oid2name
 
diff --git a/contrib/vacuumlo/meson.build b/contrib/vacuumlo/meson.build
index 9fa7380590..a059dda65a 100644
--- a/contrib/vacuumlo/meson.build
+++ b/contrib/vacuumlo/meson.build
@@ -13,7 +13,7 @@ endif
 vacuumlo = executable('vacuumlo',
   vacuumlo_sources,
   dependencies: [frontend_code, libpq],
-  kwargs: default_bin_args,
+  kwargs: contrib_bin_args,
 )
 contrib_targets += vacuumlo
 
-- 
Tristan Partin
Neon (https://neon.tech)

From 6c7b3bde703014ccec91f3f6a8a7af21b36d0a1f Mon Sep 17 00:00:00 2001
From: Tristan Partin <tris...@neon.tech>
Date: Wed, 17 May 2023 09:40:02 -0500
Subject: [PATCH v1 1/7] Make finding pkg-config(python3) more robust

It is a possibility that the installation can't be found.
---
 meson.build | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/meson.build b/meson.build
index 5422885b0a..bd9cdb797e 100644
--- a/meson.build
+++ b/meson.build
@@ -1056,15 +1056,17 @@ endif
 ###############################################################
 
 pyopt = get_option('plpython')
+python3_dep = not_found_dep
 if not pyopt.disabled()
   pm = import('python')
   python3_inst = pm.find_installation(required: pyopt)
-  python3_dep = python3_inst.dependency(embed: true, required: pyopt)
-  if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt)
-    python3_dep = not_found_dep
+  if python3_inst.found()
+    python3_dep = python3_inst.dependency(embed: true, required: pyopt)
+    # Remove this check after we depend on Meson >= 1.1.0
+    if not cc.check_header('Python.h', dependencies: python3_dep, required: pyopt)
+      python3_dep = not_found_dep
+    endif
   endif
-else
-  python3_dep = not_found_dep
 endif
 
 
-- 
Tristan Partin
Neon (https://neon.tech)

From dbd92953ebe53415103a2bcaa18b4c61d620e404 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tris...@neon.tech>
Date: Fri, 1 Sep 2023 10:04:43 -0500
Subject: [PATCH v1 5/7] Use the meson compat layer for muon

Muon has a Meson compat layer which translates arguments to those that
Muon can understand, and disregards any that it doesn't.
---
 meson.build | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/meson.build b/meson.build
index bd9cdb797e..ed91a10974 100644
--- a/meson.build
+++ b/meson.build
@@ -423,6 +423,10 @@ if meson_impl not in ['muon', 'meson']
 endif
 
 meson_bin = find_program(meson_binpath, native: true)
+# Use the muon CLI compat layer
+if meson_impl == 'muon'
+  meson_args += 'meson'
+endif
 
 
 
@@ -3037,10 +3041,7 @@ else
   test_install_location = run_command(command, check: true).stdout().strip()
 endif
 
-meson_install_args = meson_args + ['install'] + {
-    'meson': ['--quiet', '--only-changed', '--no-rebuild'],
-    'muon': []
-}[meson_impl]
+meson_install_args = meson_args + ['install', '--quiet', '--only-changed', '--no-rebuild']
 
 # setup tests should be run first,
 # so define priority for these
-- 
Tristan Partin
Neon (https://neon.tech)

From c131c60f8482c213c74a225c5afdefb3aca300ad Mon Sep 17 00:00:00 2001
From: Tristan Partin <tris...@neon.tech>
Date: Fri, 1 Sep 2023 09:22:07 -0500
Subject: [PATCH v1 4/7] Tackle a FIXME in Meson comment

Removed duplication in the definition of shared modules.
---
 src/test/regress/meson.build | 24 ++++++++++++------------
 1 file changed, 12 insertions(+), 12 deletions(-)

diff --git a/src/test/regress/meson.build b/src/test/regress/meson.build
index a045c00c1f..5ba6c5485a 100644
--- a/src/test/regress/meson.build
+++ b/src/test/regress/meson.build
@@ -45,20 +45,20 @@ test_install_libs += regress_module
 
 # Get some extra C modules from contrib/spi but mark them as not to be
 # installed.
-# FIXME: avoid the duplication.
 
-autoinc_regress = shared_module('autoinc',
-  ['../../../contrib/spi/autoinc.c'],
-  kwargs: pg_test_mod_args,
-)
-test_install_libs += autoinc_regress
+extra_regress_modules = {
+  'autoinc': {},
+  'refint': {
+    'c_args': refint_cflags,
+  },
+}
 
-refint_regress = shared_module('refint',
-  ['../../../contrib/spi/refint.c'],
-  c_args: refint_cflags,
-  kwargs: pg_test_mod_args,
-)
-test_install_libs += refint_regress
+foreach m, params : extra_regress_modules
+  test_install_libs += shared_module(m,
+    '../../../contrib/spi/@0@.c'.format(m),
+    kwargs: pg_test_mod_args + params
+  )
+endforeach
 
 
 tests += {
-- 
Tristan Partin
Neon (https://neon.tech)

From 1805a1f7ccb2a3a4568afe3c153130ec10545e03 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tris...@neon.tech>
Date: Fri, 1 Sep 2023 10:57:23 -0500
Subject: [PATCH v1 6/7] Make use of find_program('meson')

I went through the trouble of teaching Meson how to return itself in the
DSL for 1.2.0. Make use of the feature to bypass the find_meson script
if the version of Meson is high enough.

Link: https://mesonbuild.com/Release-notes-for-1-2-0.html#new-override-of-find_programmeson
---
 meson.build | 73 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 38 insertions(+), 35 deletions(-)

diff --git a/meson.build b/meson.build
index ed91a10974..9302db4fde 100644
--- a/meson.build
+++ b/meson.build
@@ -385,47 +385,50 @@ install_files = files('src/tools/install_files')
 # Path to meson (for tests etc)
 ###############################################################
 
-# NB: this should really be part of meson, see
-# https://github.com/mesonbuild/meson/issues/8511
-meson_binpath_r = run_command(python, 'src/tools/find_meson', check: true)
+if meson.version().version_compare('>= 1.2.0')
+  meson_bin = find_program('meson', native: true)
+  meson_args = []
+else
+  meson_binpath_r = run_command(python, 'src/tools/find_meson', check: true)
 
-if meson_binpath_r.stdout() == ''
-  error('huh, could not run find_meson.\nerrcode: @0@\nstdout: @1@\nstderr: @2@'.format(
-    meson_binpath_r.returncode(),
-    meson_binpath_r.stdout(),
-    meson_binpath_r.stderr()))
-endif
+  if meson_binpath_r.stdout() == ''
+    error('huh, could not run find_meson.\nerrcode: @0@\nstdout: @1@\nstderr: @2@'.format(
+      meson_binpath_r.returncode(),
+      meson_binpath_r.stdout(),
+      meson_binpath_r.stderr()))
+  endif
 
-meson_binpath_s = meson_binpath_r.stdout().split('\n')
-meson_binpath_len = meson_binpath_s.length()
+  meson_binpath_s = meson_binpath_r.stdout().split('\n')
+  meson_binpath_len = meson_binpath_s.length()
 
-if meson_binpath_len < 1
-  error('unexpected introspect line @0@'.format(meson_binpath_r.stdout()))
-endif
-
-i = 0
-meson_impl = ''
-meson_binpath = ''
-meson_args = []
-foreach e : meson_binpath_s
-  if i == 0
-    meson_impl = e
-  elif i == 1
-    meson_binpath = e
-  else
-    meson_args += e
+  if meson_binpath_len < 1
+    error('unexpected introspect line @0@'.format(meson_binpath_r.stdout()))
   endif
-  i += 1
-endforeach
 
-if meson_impl not in ['muon', 'meson']
-  error('unknown meson implementation "@0@"'.format(meson_impl))
-endif
+  i = 0
+  meson_impl = ''
+  meson_binpath = ''
+  meson_args = []
+  foreach e : meson_binpath_s
+    if i == 0
+      meson_impl = e
+    elif i == 1
+      meson_binpath = e
+    else
+      meson_args += e
+    endif
+    i += 1
+  endforeach
 
-meson_bin = find_program(meson_binpath, native: true)
-# Use the muon CLI compat layer
-if meson_impl == 'muon'
-  meson_args += 'meson'
+  if meson_impl not in ['muon', 'meson']
+    error('unknown meson implementation "@0@"'.format(meson_impl))
+  endif
+
+  meson_bin = find_program(meson_binpath, native: true)
+  # Use the muon CLI compat layer
+  if meson_impl == 'muon'
+    meson_args += 'meson'
+  endif
 endif
 
 
-- 
Tristan Partin
Neon (https://neon.tech)

From 92dc6107e1f56173e0606593d75e344b941f3794 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tris...@neon.tech>
Date: Thu, 31 Aug 2023 12:37:31 -0500
Subject: [PATCH v1 3/7] Fix grammar in Meson comment

---
 contrib/meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/contrib/meson.build b/contrib/meson.build
index bd4a57c43c..618b1c50c8 100644
--- a/contrib/meson.build
+++ b/contrib/meson.build
@@ -56,7 +56,7 @@ subdir('seg')
 subdir('sepgsql')
 subdir('spi')
 subdir('sslinfo')
-# start-scripts doesn't contain build products
+# start-scripts that do not contain build products
 subdir('tablefunc')
 subdir('tcn')
 subdir('test_decoding')
-- 
Tristan Partin
Neon (https://neon.tech)

Reply via email to