Building with meson on NixOS/nixpkgs

Started by Wolfgang Waltheralmost 2 years ago14 messages
#1Wolfgang Walther
walther@technowledgy.de
3 attachment(s)

To build on NixOS/nixpkgs I came up with a few small patches to
meson.build. All of this works fine with Autoconf/Make already.

Attachments:

0001-Fallback-to-uuid-for-ossp-uuid-with-meson.patchtext/x-patch; charset=UTF-8; name=0001-Fallback-to-uuid-for-ossp-uuid-with-meson.patchDownload
From 24ae72b9b0adc578c6729eff59c9038e6b4ac517 Mon Sep 17 00:00:00 2001
From: Wolfgang Walther <walther@technowledgy.de>
Date: Sat, 2 Mar 2024 17:18:38 +0100
Subject: [PATCH 1/3] Fallback to uuid for ossp-uuid with meson

The upstream name for the ossp-uuid package / pkg-config file is "uuid". Many
distributions change this to be "ossp-uuid" to not conflict with e2fsprogs.

This lookup fails on distributions which don't change this name, for example
NixOS / nixpkgs. Both "ossp-uuid" and "uuid" are also checked in configure.ac.
---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index c8fdfeb0ec3..d9ad1ce902f 100644
--- a/meson.build
+++ b/meson.build
@@ -1346,7 +1346,7 @@ if uuidopt != 'none'
     uuidfunc = 'uuid_to_string'
     uuidheader = 'uuid.h'
   elif uuidopt == 'ossp'
-    uuid = dependency('ossp-uuid', required: true)
+    uuid = dependency('ossp-uuid', 'uuid', required: true)
     uuidfunc = 'uuid_export'
     uuidheader = 'uuid.h'
   else
-- 
2.44.0

0002-Fallback-to-clang-in-PATH-with-meson.patchtext/x-patch; charset=UTF-8; name=0002-Fallback-to-clang-in-PATH-with-meson.patchDownload
From 56e0abbcc3b950b6e93eddc6ede453ce529423ea Mon Sep 17 00:00:00 2001
From: Wolfgang Walther <walther@technowledgy.de>
Date: Sat, 2 Mar 2024 22:06:25 +0100
Subject: [PATCH 2/3] Fallback to clang in PATH with meson

Some distributions put clang into a different path than the llvm binary path.

For example, this is the case on NixOS / nixpkgs, which failed to find clang
with meson before this patch.
---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index d9ad1ce902f..7c64fb04ea5 100644
--- a/meson.build
+++ b/meson.build
@@ -759,7 +759,7 @@ if add_languages('cpp', required: llvmopt, native: false)
     llvm_binpath = llvm.get_variable(configtool: 'bindir')
 
     ccache = find_program('ccache', native: true, required: false)
-    clang = find_program(llvm_binpath / 'clang', required: true)
+    clang = find_program(llvm_binpath / 'clang', 'clang', required: true)
   endif
 elif llvmopt.auto()
   message('llvm requires a C++ compiler')
-- 
2.44.0

0003-Support-absolute-bindir-libdir-in-regression-tests-w.patchtext/x-patch; charset=UTF-8; name=0003-Support-absolute-bindir-libdir-in-regression-tests-w.patchDownload
From 62f10689d843227fca6d54e86462d0be5c4f434f Mon Sep 17 00:00:00 2001
From: Wolfgang Walther <walther@technowledgy.de>
Date: Mon, 11 Mar 2024 19:54:41 +0100
Subject: [PATCH 3/3] Support absolute bindir/libdir in regression tests with
 meson

Passing an absolute bindir/libdir will install the binaries and libraries to
<build>/tmp_install/<bindir> and <build>/tmp_install/<libdir> respectively.

This is path is correctly passed to the regression test suite via configure/make,
but not via meson, yet. This is because the "/" operator in the following expression
throws away the whole left side when the right side is an absolute path:

  test_install_location / get_option('libdir')

This was already correctly handled for dir_prefix, which is likely absolute as well.
This patch handles both bindir and libdir in the same way - prefixing absolute paths
with the tmp_install path correctly.
---
 meson.build | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/meson.build b/meson.build
index 7c64fb04ea5..e8438209058 100644
--- a/meson.build
+++ b/meson.build
@@ -3044,15 +3044,17 @@ test_install_destdir = meson.build_root() / 'tmp_install/'
 if build_system != 'windows'
   # On unixoid systems this is trivial, we just prepend the destdir
   assert(dir_prefix.startswith('/')) # enforced by meson
-  test_install_location = '@0@@1@'.format(test_install_destdir, dir_prefix)
+  temp_install_bindir = '@0@@1@'.format(test_install_destdir, dir_prefix / dir_bin)
+  temp_install_libdir = '@0@@1@'.format(test_install_destdir, dir_prefix / dir_lib)
 else
   # drives, drive-relative paths, etc make this complicated on windows, call
   # into a copy of meson's logic for it
   command = [
     python, '-c',
     'import sys; from pathlib import PurePath; d1=sys.argv[1]; d2=sys.argv[2]; print(str(PurePath(d1, *PurePath(d2).parts[1:])))',
-    test_install_destdir, dir_prefix]
-  test_install_location = run_command(command, check: true).stdout().strip()
+    test_install_destdir]
+  temp_install_bindir = run_command(command, dir_prefix / dir_bin, check: true).stdout().strip()
+  temp_install_libdir = run_command(command, dir_prefix / dir_lib, check: true).stdout().strip()
 endif
 
 meson_install_args = meson_args + ['install'] + {
@@ -3089,7 +3091,6 @@ testport = 40000
 
 test_env = environment()
 
-temp_install_bindir = test_install_location / get_option('bindir')
 test_initdb_template = meson.build_root() / 'tmp_install' / 'initdb-template'
 test_env.set('PG_REGRESS', pg_regress.full_path())
 test_env.set('REGRESS_SHLIB', regress_module.full_path())
@@ -3104,7 +3105,7 @@ test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
 # that works (everything but windows, basically). On windows everything
 # library-like gets installed into bindir, solving that issue.
 if library_path_var != ''
-  test_env.prepend(library_path_var, test_install_location / get_option('libdir'))
+  test_env.prepend(library_path_var, temp_install_libdir)
 endif
 
 
-- 
2.44.0

#2Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Wolfgang Walther (#1)
Re: Building with meson on NixOS/nixpkgs

Hi,

Thank you for the patches!

On Sat, 16 Mar 2024 at 14:48, Wolfgang Walther <walther@technowledgy.de> wrote:

To build on NixOS/nixpkgs I came up with a few small patches to
meson.build. All of this works fine with Autoconf/Make already.

I do not have NixOS but I confirm that patches cleanly apply to master
and do pass CI. I have a small feedback:

0001 & 0002: Adding code comments to explain why they have fallback
could be nice.
0003: Looks good to me.

--
Regards,
Nazir Bilal Yavuz
Microsoft

#3Alvaro Herrera
alvherre@alvh.no-ip.org
In reply to: Wolfgang Walther (#1)
Re: Building with meson on NixOS/nixpkgs

On 2024-Mar-16, Wolfgang Walther wrote:

The upstream name for the ossp-uuid package / pkg-config file is "uuid". Many
distributions change this to be "ossp-uuid" to not conflict with e2fsprogs.

I can confirm that this is true for Debian, at least; the packaging
rules have this in override_dh_install:

install -D -m 644 debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/uuid.pc \
debian/libossp-uuid-dev/usr/lib/pkgconfig/ossp-uuid.pc

which matches the fact that Engelschall's official repository has the
file named simply uuid.pc:
https://github.com/rse/uuid/blob/master/uuid.pc.in

--
Álvaro Herrera PostgreSQL Developer — https://www.EnterpriseDB.com/

#4Wolfgang Walther
walther@technowledgy.de
In reply to: Nazir Bilal Yavuz (#2)
3 attachment(s)
Re: Building with meson on NixOS/nixpkgs

Nazir Bilal Yavuz:

0001 & 0002: Adding code comments to explain why they have fallback
could be nice.
0003: Looks good to me.

Added some comments in the attached.

Best,

Wolfgang

Attachments:

v2-0001-Fallback-to-uuid-for-ossp-uuid-with-meson.patchtext/x-patch; charset=UTF-8; name=v2-0001-Fallback-to-uuid-for-ossp-uuid-with-meson.patchDownload
From 2d271aafd96a0ea21710a06ac5236e47217c36d1 Mon Sep 17 00:00:00 2001
From: Wolfgang Walther <walther@technowledgy.de>
Date: Sat, 2 Mar 2024 17:18:38 +0100
Subject: [PATCH v2 1/3] Fallback to uuid for ossp-uuid with meson

The upstream name for the ossp-uuid package / pkg-config file is "uuid". Many
distributions change this to be "ossp-uuid" to not conflict with e2fsprogs.

This lookup fails on distributions which don't change this name, for example
NixOS / nixpkgs. Both "ossp-uuid" and "uuid" are also checked in configure.ac.
---
 meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index c8fdfeb0ec3..942c79c8be3 100644
--- a/meson.build
+++ b/meson.build
@@ -1346,7 +1346,8 @@ if uuidopt != 'none'
     uuidfunc = 'uuid_to_string'
     uuidheader = 'uuid.h'
   elif uuidopt == 'ossp'
-    uuid = dependency('ossp-uuid', required: true)
+    # upstream is called "uuid", but many distros change this to "ossp-uuid"
+    uuid = dependency('ossp-uuid', 'uuid', required: true)
     uuidfunc = 'uuid_export'
     uuidheader = 'uuid.h'
   else
-- 
2.44.0

v2-0002-Fallback-to-clang-in-PATH-with-meson.patchtext/x-patch; charset=UTF-8; name=v2-0002-Fallback-to-clang-in-PATH-with-meson.patchDownload
From f150a8dcb92b08eab40b5dfec130a18f297c709f Mon Sep 17 00:00:00 2001
From: Wolfgang Walther <walther@technowledgy.de>
Date: Sat, 2 Mar 2024 22:06:25 +0100
Subject: [PATCH v2 2/3] Fallback to clang in PATH with meson

Some distributions put clang into a different path than the llvm binary path.

For example, this is the case on NixOS / nixpkgs, which failed to find clang
with meson before this patch.
---
 meson.build | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 942c79c8be3..f9e96b01cfa 100644
--- a/meson.build
+++ b/meson.build
@@ -759,7 +759,10 @@ if add_languages('cpp', required: llvmopt, native: false)
     llvm_binpath = llvm.get_variable(configtool: 'bindir')
 
     ccache = find_program('ccache', native: true, required: false)
-    clang = find_program(llvm_binpath / 'clang', required: true)
+
+    # Some distros put LLVM and clang in different paths, so fallback to
+    # find via PATH, too.
+    clang = find_program(llvm_binpath / 'clang', 'clang', required: true)
   endif
 elif llvmopt.auto()
   message('llvm requires a C++ compiler')
-- 
2.44.0

v2-0003-Support-absolute-bindir-libdir-in-regression-test.patchtext/x-patch; charset=UTF-8; name=v2-0003-Support-absolute-bindir-libdir-in-regression-test.patchDownload
From fddee56b5e27a3b5e4c406e8caa2d230b49eb447 Mon Sep 17 00:00:00 2001
From: Wolfgang Walther <walther@technowledgy.de>
Date: Mon, 11 Mar 2024 19:54:41 +0100
Subject: [PATCH v2 3/3] Support absolute bindir/libdir in regression tests
 with meson

Passing an absolute bindir/libdir will install the binaries and libraries to
<build>/tmp_install/<bindir> and <build>/tmp_install/<libdir> respectively.

This is path is correctly passed to the regression test suite via configure/make,
but not via meson, yet. This is because the "/" operator in the following expression
throws away the whole left side when the right side is an absolute path:

  test_install_location / get_option('libdir')

This was already correctly handled for dir_prefix, which is likely absolute as well.
This patch handles both bindir and libdir in the same way - prefixing absolute paths
with the tmp_install path correctly.
---
 meson.build | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/meson.build b/meson.build
index f9e96b01cfa..144c443b5e4 100644
--- a/meson.build
+++ b/meson.build
@@ -3048,15 +3048,17 @@ test_install_destdir = meson.build_root() / 'tmp_install/'
 if build_system != 'windows'
   # On unixoid systems this is trivial, we just prepend the destdir
   assert(dir_prefix.startswith('/')) # enforced by meson
-  test_install_location = '@0@@1@'.format(test_install_destdir, dir_prefix)
+  temp_install_bindir = '@0@@1@'.format(test_install_destdir, dir_prefix / dir_bin)
+  temp_install_libdir = '@0@@1@'.format(test_install_destdir, dir_prefix / dir_lib)
 else
   # drives, drive-relative paths, etc make this complicated on windows, call
   # into a copy of meson's logic for it
   command = [
     python, '-c',
     'import sys; from pathlib import PurePath; d1=sys.argv[1]; d2=sys.argv[2]; print(str(PurePath(d1, *PurePath(d2).parts[1:])))',
-    test_install_destdir, dir_prefix]
-  test_install_location = run_command(command, check: true).stdout().strip()
+    test_install_destdir]
+  temp_install_bindir = run_command(command, dir_prefix / dir_bin, check: true).stdout().strip()
+  temp_install_libdir = run_command(command, dir_prefix / dir_lib, check: true).stdout().strip()
 endif
 
 meson_install_args = meson_args + ['install'] + {
@@ -3093,7 +3095,6 @@ testport = 40000
 
 test_env = environment()
 
-temp_install_bindir = test_install_location / get_option('bindir')
 test_initdb_template = meson.build_root() / 'tmp_install' / 'initdb-template'
 test_env.set('PG_REGRESS', pg_regress.full_path())
 test_env.set('REGRESS_SHLIB', regress_module.full_path())
@@ -3108,7 +3109,7 @@ test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
 # that works (everything but windows, basically). On windows everything
 # library-like gets installed into bindir, solving that issue.
 if library_path_var != ''
-  test_env.prepend(library_path_var, test_install_location / get_option('libdir'))
+  test_env.prepend(library_path_var, temp_install_libdir)
 endif
 
 
-- 
2.44.0

#5Noname
walther@technowledgy.de
In reply to: Wolfgang Walther (#1)
4 attachment(s)
Re: Building with meson on NixOS/nixpkgs

Wolfgang Walther:

To build on NixOS/nixpkgs I came up with a few small patches to
meson.build. All of this works fine with Autoconf/Make already.

In v3, I added another small patch for meson, this one about proper
handling of -Dlibedit_preferred when used together with -Dreadline=enabled.

Best,

Wolfgang

Attachments:

v3-0001-Fallback-to-uuid-for-ossp-uuid-with-meson.patchtext/x-patch; charset=UTF-8; name=v3-0001-Fallback-to-uuid-for-ossp-uuid-with-meson.patchDownload
From 1e7db8b57f69ed9866fdf874bbd0dcb33d25c045 Mon Sep 17 00:00:00 2001
From: Wolfgang Walther <walther@technowledgy.de>
Date: Sat, 2 Mar 2024 17:18:38 +0100
Subject: [PATCH v3 1/4] Fallback to uuid for ossp-uuid with meson

The upstream name for the ossp-uuid package / pkg-config file is "uuid". Many
distributions change this to be "ossp-uuid" to not conflict with e2fsprogs.

This lookup fails on distributions which don't change this name, for example
NixOS / nixpkgs. Both "ossp-uuid" and "uuid" are also checked in configure.ac.
---
 meson.build | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 18b5be842e3..4be5f65e8b6 100644
--- a/meson.build
+++ b/meson.build
@@ -1346,7 +1346,8 @@ if uuidopt != 'none'
     uuidfunc = 'uuid_to_string'
     uuidheader = 'uuid.h'
   elif uuidopt == 'ossp'
-    uuid = dependency('ossp-uuid', required: true)
+    # upstream is called "uuid", but many distros change this to "ossp-uuid"
+    uuid = dependency('ossp-uuid', 'uuid', required: true)
     uuidfunc = 'uuid_export'
     uuidheader = 'uuid.h'
   else
-- 
2.44.0

v3-0002-Fallback-to-clang-in-PATH-with-meson.patchtext/x-patch; charset=UTF-8; name=v3-0002-Fallback-to-clang-in-PATH-with-meson.patchDownload
From 28e8067b6b04ac601946fab4aa0849b3dfec5a7d Mon Sep 17 00:00:00 2001
From: Wolfgang Walther <walther@technowledgy.de>
Date: Sat, 2 Mar 2024 22:06:25 +0100
Subject: [PATCH v3 2/4] Fallback to clang in PATH with meson

Some distributions put clang into a different path than the llvm binary path.

For example, this is the case on NixOS / nixpkgs, which failed to find clang
with meson before this patch.
---
 meson.build | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index 4be5f65e8b6..4a6af978fd4 100644
--- a/meson.build
+++ b/meson.build
@@ -759,7 +759,10 @@ if add_languages('cpp', required: llvmopt, native: false)
     llvm_binpath = llvm.get_variable(configtool: 'bindir')
 
     ccache = find_program('ccache', native: true, required: false)
-    clang = find_program(llvm_binpath / 'clang', required: true)
+
+    # Some distros put LLVM and clang in different paths, so fallback to
+    # find via PATH, too.
+    clang = find_program(llvm_binpath / 'clang', 'clang', required: true)
   endif
 elif llvmopt.auto()
   message('llvm requires a C++ compiler')
-- 
2.44.0

v3-0003-Support-absolute-bindir-libdir-in-regression-test.patchtext/x-patch; charset=UTF-8; name=v3-0003-Support-absolute-bindir-libdir-in-regression-test.patchDownload
From 01fda05ea14e8cf0d201b749c84b1f3cb532f353 Mon Sep 17 00:00:00 2001
From: Wolfgang Walther <walther@technowledgy.de>
Date: Mon, 11 Mar 2024 19:54:41 +0100
Subject: [PATCH v3 3/4] Support absolute bindir/libdir in regression tests
 with meson

Passing an absolute bindir/libdir will install the binaries and libraries to
<build>/tmp_install/<bindir> and <build>/tmp_install/<libdir> respectively.

This is path is correctly passed to the regression test suite via configure/make,
but not via meson, yet. This is because the "/" operator in the following expression
throws away the whole left side when the right side is an absolute path:

  test_install_location / get_option('libdir')

This was already correctly handled for dir_prefix, which is likely absolute as well.
This patch handles both bindir and libdir in the same way - prefixing absolute paths
with the tmp_install path correctly.
---
 meson.build | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/meson.build b/meson.build
index 4a6af978fd4..3e628659843 100644
--- a/meson.build
+++ b/meson.build
@@ -3048,15 +3048,17 @@ test_install_destdir = meson.build_root() / 'tmp_install/'
 if build_system != 'windows'
   # On unixoid systems this is trivial, we just prepend the destdir
   assert(dir_prefix.startswith('/')) # enforced by meson
-  test_install_location = '@0@@1@'.format(test_install_destdir, dir_prefix)
+  temp_install_bindir = '@0@@1@'.format(test_install_destdir, dir_prefix / dir_bin)
+  temp_install_libdir = '@0@@1@'.format(test_install_destdir, dir_prefix / dir_lib)
 else
   # drives, drive-relative paths, etc make this complicated on windows, call
   # into a copy of meson's logic for it
   command = [
     python, '-c',
     'import sys; from pathlib import PurePath; d1=sys.argv[1]; d2=sys.argv[2]; print(str(PurePath(d1, *PurePath(d2).parts[1:])))',
-    test_install_destdir, dir_prefix]
-  test_install_location = run_command(command, check: true).stdout().strip()
+    test_install_destdir]
+  temp_install_bindir = run_command(command, dir_prefix / dir_bin, check: true).stdout().strip()
+  temp_install_libdir = run_command(command, dir_prefix / dir_lib, check: true).stdout().strip()
 endif
 
 meson_install_args = meson_args + ['install'] + {
@@ -3093,7 +3095,6 @@ testport = 40000
 
 test_env = environment()
 
-temp_install_bindir = test_install_location / get_option('bindir')
 test_initdb_template = meson.build_root() / 'tmp_install' / 'initdb-template'
 test_env.set('PG_REGRESS', pg_regress.full_path())
 test_env.set('REGRESS_SHLIB', regress_module.full_path())
@@ -3108,7 +3109,7 @@ test_env.set('PG_TEST_EXTRA', get_option('PG_TEST_EXTRA'))
 # that works (everything but windows, basically). On windows everything
 # library-like gets installed into bindir, solving that issue.
 if library_path_var != ''
-  test_env.prepend(library_path_var, test_install_location / get_option('libdir'))
+  test_env.prepend(library_path_var, temp_install_libdir)
 endif
 
 
-- 
2.44.0

v3-0004-Support-falling-back-to-non-preferred-readline-im.patchtext/x-patch; charset=UTF-8; name=v3-0004-Support-falling-back-to-non-preferred-readline-im.patchDownload
From f9dae8de174f27b44d6268a345d7cd03eb023561 Mon Sep 17 00:00:00 2001
From: Wolfgang Walther <walther@technowledgy.de>
Date: Fri, 29 Mar 2024 19:38:59 +0100
Subject: [PATCH v3 4/4] Support falling back to non-preferred readline
 implementation with meson

To build with -Dreadline=enabled one can use either readline or libedit. The
-Dlibedit_preferred flag is supposed to control the order of names to lookup.
This works fine when either both libraries are present or -Dreadline is set to
auto. However, explicitly enabling readline with only libedit present, but not
setting libedit_preferred, or alternatively enabling readline with only readline
present, but setting libedit_preferred, too, are both broken. This is because
cc.find_library will throw an error for a not found dependency as soon as the
first required dependency is checked, thus it's impossible to fallback to the
alternative.

Here we only check the second of the two dependencies for requiredness, thus
we only fail when none of the two can be found.
---
 meson.build | 23 +++++++++++++++++------
 1 file changed, 17 insertions(+), 6 deletions(-)

diff --git a/meson.build b/meson.build
index 3e628659843..3e899432485 100644
--- a/meson.build
+++ b/meson.build
@@ -1080,15 +1080,26 @@ endif
 
 if not get_option('readline').disabled()
   libedit_preferred = get_option('libedit_preferred')
-  # Set the order of readline dependencies
-  check_readline_deps = libedit_preferred ? \
-    ['libedit', 'readline'] : ['readline', 'libedit']
+  # Set the order of readline dependencies.
+  # cc.find_library breaks and throws on the first dependency which
+  # is marked as required=true and can't be found. Thus, we only mark
+  # the last dependency to look up as required, to not throw too early.
+  check_readline_deps = [
+    {
+      'name': libedit_preferred ? 'libedit' : 'readline',
+      'required': false
+    },
+    {
+      'name': libedit_preferred ? 'readline' : 'libedit',
+      'required': get_option('readline')
+    }
+  ]
 
   foreach readline_dep : check_readline_deps
-    readline = dependency(readline_dep, required: false)
+    readline = dependency(readline_dep['name'], required: false)
     if not readline.found()
-      readline = cc.find_library(readline_dep,
-        required: get_option('readline'),
+      readline = cc.find_library(readline_dep['name'],
+        required: readline_dep['required'],
         dirs: test_lib_d)
     endif
     if readline.found()
-- 
2.44.0

#6Nazir Bilal Yavuz
byavuz81@gmail.com
In reply to: Noname (#5)
Re: Building with meson on NixOS/nixpkgs

Hi,

From your prior reply:

On Thu, 21 Mar 2024 at 23:44, Wolfgang Walther <walther@technowledgy.de> wrote:

Nazir Bilal Yavuz:

0001 & 0002: Adding code comments to explain why they have fallback
could be nice.
0003: Looks good to me.

Added some comments in the attached.

Comments look good, thanks.

On Fri, 29 Mar 2024 at 21:48, <walther@technowledgy.de> wrote:

In v3, I added another small patch for meson, this one about proper
handling of -Dlibedit_preferred when used together with -Dreadline=enabled.

You are right. I confirm the bug and your proposed patch fixes this.

--
Regards,
Nazir Bilal Yavuz
Microsoft

#7Peter Eisentraut
peter@eisentraut.org
In reply to: Noname (#5)
Re: Building with meson on NixOS/nixpkgs

On 29.03.24 19:47, walther@technowledgy.de wrote:

-    uuid = dependency('ossp-uuid', required: true)
+    # upstream is called "uuid", but many distros change this to 

"ossp-uuid"

+ uuid = dependency('ossp-uuid', 'uuid', required: true)

How would this behave if you have only uuid.pc from e2fsprogs installed
but choose -Duuid=ossp? Then it would pick up uuid.pc here, but fail to
compile later?

#8Noname
walther@technowledgy.de
In reply to: Peter Eisentraut (#7)
Re: Building with meson on NixOS/nixpkgs

Peter Eisentraut:

On 29.03.24 19:47, walther@technowledgy.de wrote:

-    uuid = dependency('ossp-uuid', required: true)
+    # upstream is called "uuid", but many distros change this to 

"ossp-uuid"

+    uuid = dependency('ossp-uuid', 'uuid', required: true)

How would this behave if you have only uuid.pc from e2fsprogs installed
but choose -Duuid=ossp?  Then it would pick up uuid.pc here, but fail to
compile later?

It would still fail the meson setup step, because for e2fs we have:

uuidfunc = 'uuid_generate'
uuidheader = 'uuid/uuid.h'

while for ossp we have:

uuidfunc = 'uuid_export'
uuidheader = 'uuid.h'

and later we do:

if not cc.has_header_symbol(uuidheader, uuidfunc, args: test_c_args,
dependencies: uuid)
error('uuid library @0@ missing required function
@1@'.format(uuidopt, uuidfunc))
endif

Best,

Wolfgang

#9Tristan Partin
tristan@neon.tech
In reply to: Noname (#5)
Re: Building with meson on NixOS/nixpkgs

Heikki asked me to take a look at this patchset for the commitfest.
Looks good to me.

Heikki, just be careful rebasing the first patch. You need to make sure
the newly set `required: false` gets carried forward.

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

#10Heikki Linnakangas
hlinnaka@iki.fi
In reply to: Tristan Partin (#9)
Re: Building with meson on NixOS/nixpkgs

On 26/07/2024 23:01, Tristan Partin wrote:

Heikki asked me to take a look at this patchset for the commitfest.
Looks good to me.

Heikki, just be careful rebasing the first patch. You need to make sure
the newly set `required: false` gets carried forward.

Committed and backpatched to v16 and v17. Thanks for the good
explanations in the commit messages, Walther!

--
Heikki Linnakangas
Neon (https://neon.tech)

#11Andres Freund
andres@anarazel.de
In reply to: Heikki Linnakangas (#10)
Re: Building with meson on NixOS/nixpkgs

Hi,

commit 4d8de281b5834c8f5e0be6ae21e884e69dffd4ce
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: 2024-07-27 13:53:11 +0300

Fallback to clang in PATH with meson

Some distributions put clang into a different path than the llvm
binary path.

For example, this is the case on NixOS / nixpkgs, which failed to find
clang with meson before this patch.

I think this is a bad change unfortunately - this way clang and llvm version
can mismatch. Yes, we've done it that way for autoconf, but back then LLVM
broke compatibility far less often.

commit a00fae9d43e5adabc56e64a4df6d332062666501
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: 2024-07-27 13:53:08 +0300

Fallback to uuid for ossp-uuid with meson

The upstream name for the ossp-uuid package / pkg-config file is
"uuid". Many distributions change this to be "ossp-uuid" to not
conflict with e2fsprogs.

This lookup fails on distributions which don't change this name, for
example NixOS / nixpkgs. Both "ossp-uuid" and "uuid" are also checked
in configure.ac.

Author: Wolfgang Walther
Reviewed-by: Nazir Bilal Yavuz, Alvaro Herrera, Peter Eisentraut
Reviewed-by: Tristan Partin
Discussion: /messages/by-id/ca8f37e1-a2c3-40e2-91f6-59c3d3652ad4@technowledgy.de
Backpatch: 16-, where meson support was added

I think this is a redundant change with

commit 2416fdb3ee30bdd2810408f93f14d47bff840fea
Author: Andres Freund <andres@anarazel.de>
Date: 2024-07-20 13:51:08 -0700

meson: Add support for detecting ossp-uuid without pkg-config

This is necessary as ossp-uuid on windows installs neither a pkg-config nor a
cmake dependency information. Nor is there another supported uuid
implementation available on windows.

Reported-by: Dave Page <dpage@pgadmin.org>
Reviewed-by: Tristan Partin <tristan@partin.io>
Discussion: /messages/by-id/20240709065101.xhc74r3mdg2lmn4w@awork3.anarazel.de
Backpatch: 16-, where meson support was added

Greetings,

Andres Freund

#12Tristan Partin
tristan@partin.io
In reply to: Andres Freund (#11)
1 attachment(s)
Re: Building with meson on NixOS/nixpkgs

On Fri Aug 9, 2024 at 11:14 AM CDT, Andres Freund wrote:

Hi,

commit 4d8de281b5834c8f5e0be6ae21e884e69dffd4ce
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: 2024-07-27 13:53:11 +0300

Fallback to clang in PATH with meson

Some distributions put clang into a different path than the llvm
binary path.

For example, this is the case on NixOS / nixpkgs, which failed to find
clang with meson before this patch.

I think this is a bad change unfortunately - this way clang and llvm version
can mismatch. Yes, we've done it that way for autoconf, but back then LLVM
broke compatibility far less often.

See the attached patch on how we could make this situation better.

commit a00fae9d43e5adabc56e64a4df6d332062666501
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date: 2024-07-27 13:53:08 +0300

Fallback to uuid for ossp-uuid with meson

The upstream name for the ossp-uuid package / pkg-config file is
"uuid". Many distributions change this to be "ossp-uuid" to not
conflict with e2fsprogs.

This lookup fails on distributions which don't change this name, for
example NixOS / nixpkgs. Both "ossp-uuid" and "uuid" are also checked
in configure.ac.

Author: Wolfgang Walther
Reviewed-by: Nazir Bilal Yavuz, Alvaro Herrera, Peter Eisentraut
Reviewed-by: Tristan Partin
Discussion: /messages/by-id/ca8f37e1-a2c3-40e2-91f6-59c3d3652ad4@technowledgy.de
Backpatch: 16-, where meson support was added

I think this is a redundant change with

commit 2416fdb3ee30bdd2810408f93f14d47bff840fea
Author: Andres Freund <andres@anarazel.de>
Date: 2024-07-20 13:51:08 -0700

meson: Add support for detecting ossp-uuid without pkg-config

This is necessary as ossp-uuid on windows installs neither a pkg-config nor a
cmake dependency information. Nor is there another supported uuid
implementation available on windows.

Reported-by: Dave Page <dpage@pgadmin.org>
Reviewed-by: Tristan Partin <tristan@partin.io>
Discussion: /messages/by-id/20240709065101.xhc74r3mdg2lmn4w@awork3.anarazel.de
Backpatch: 16-, where meson support was added

I'm not sure I would call them redundant. It's cheaper (and better) to
do a pkg-config lookup than it is to do the various checks in your
patch. I think the two patches are complementary. Yours services Windows
plus anywhere else that doesn't have a pkg-config file, while Wolfgang's
services distros that install the pkg-config with a different name.

--
Tristan Partin
https://tristan.partin.io

Attachments:

v1-0001-Use-the-found-LLVM-version-when-finding-clang.patchtext/x-patch; charset=utf-8; name=v1-0001-Use-the-found-LLVM-version-when-finding-clang.patchDownload
From 3dacd3b73c316bafd60c7aef9e6192591c6bf5f1 Mon Sep 17 00:00:00 2001
From: Tristan Partin <tristan@neon.tech>
Date: Fri, 9 Aug 2024 11:41:09 -0500
Subject: [PATCH v1] Use the found LLVM version when finding clang

find_program(version:) can be used to restrict the version of the
program to be found. In this case, we need a clang that is compatible
with LLVM.

Prior to 4d8de281b5834c8f5e0be6ae21e884e69dffd4ce, this worked as
intended, but since that change it was possible to pick an incompatible
clang and LLVM combination.

Reported-by: Andres Freund <andres@anarazel.de>
---
 meson.build | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/meson.build b/meson.build
index cc176f11b5d..73101e84036 100644
--- a/meson.build
+++ b/meson.build
@@ -802,7 +802,7 @@ if add_languages('cpp', required: llvmopt, native: false)
 
     # Some distros put LLVM and clang in different paths, so fallback to
     # find via PATH, too.
-    clang = find_program(llvm_binpath / 'clang', 'clang', required: true)
+    clang = find_program(llvm_binpath / 'clang', 'clang', version: llvm.version(), required: true)
   endif
 elif llvmopt.auto()
   message('llvm requires a C++ compiler')
-- 
Tristan Partin
Neon (https://neon.tech)

#13Wolfgang Walther
walther@technowledgy.de
In reply to: Tristan Partin (#12)
Re: Building with meson on NixOS/nixpkgs

Tristan Partin:

On Fri Aug 9, 2024 at 11:14 AM CDT, Andres Freund wrote:
[..]

commit a00fae9d43e5adabc56e64a4df6d332062666501
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:   2024-07-27 13:53:08 +0300

    Fallback to uuid for ossp-uuid with meson
[..]

I think this is a redundant change with

commit 2416fdb3ee30bdd2810408f93f14d47bff840fea
Author: Andres Freund <andres@anarazel.de>
Date:   2024-07-20 13:51:08 -0700

    meson: Add support for detecting ossp-uuid without pkg-config
[..]

I'm not sure I would call them redundant. It's cheaper (and better) to
do a pkg-config lookup than it is to do the various checks in your
patch. I think the two patches are complementary. Yours services Windows
plus anywhere else that doesn't have a pkg-config file, while Wolfgang's
services distros that install the pkg-config with a different name.

Agreed.

There is also a small difference in output for meson: When uuid is
queried via pkg-config, meson also detects the version, so I get this
output:

External libraries
[..]
uuid : YES 1.6.2

Without pkg-config:

External libraries
[..]
uuid : YES

Best,

Wolfgang

#14Wolfgang Walther
walther@technowledgy.de
In reply to: Tristan Partin (#12)
Re: Building with meson on NixOS/nixpkgs

Tristan Partin:

On Fri Aug 9, 2024 at 11:14 AM CDT, Andres Freund wrote:

commit 4d8de281b5834c8f5e0be6ae21e884e69dffd4ce
Author: Heikki Linnakangas <heikki.linnakangas@iki.fi>
Date:   2024-07-27 13:53:11 +0300

    Fallback to clang in PATH with meson
[..]

I think this is a bad change unfortunately - this way clang and llvm
version
can mismatch. Yes, we've done it that way for autoconf, but back then
LLVM
broke compatibility far less often.

See the attached patch on how we could make this situation better.

Works great.

With the correct clang on path:

Program clang found: YES 18.1.8 18.1.8
(/nix/store/mr1y1rxkx59dr2bci2akmw2zkbbpmc15-clang-wrapper-18.1.8/bin/clang)

With a mismatching version on path:

Program
/nix/store/x4gwwwlw2ylv0d9vjmkx3dmlcb7gingd-llvm-18.1.8/bin/clang clang
found: NO found 16.0.6 but need: '18.1.8'
(/nix/store/r85xsa9z0s04n0y21xhrii47bh74g2a8-clang-wrapper-16.0.6/bin/clang)

Yes, the match is exact, also fails with a newer version:

Program
/nix/store/x4gwwwlw2ylv0d9vjmkx3dmlcb7gingd-llvm-18.1.8/bin/clang clang
found: NO found 19.1.0 but need: '18.1.8'
(/nix/store/rjsfx6sxjpkgd4f9hl9apm0n8dk7jd9w-clang-wrapper-19.1.0-rc2/bin/clang)

+1 for this patch.

Best,

Wolfgang