From c6b54b4b3850c01212dccb2a518770031b2bebb3 Mon Sep 17 00:00:00 2001
From: Andrew Dunstan <andrew@dunslane.net>
Date: Sat, 22 Aug 2026 17:21:02 -0400
Subject: [PATCH 4/4] meson: report the GNU host triplet in PG_VERSION_STR

The meson build composed the platform part of PG_VERSION_STR from
host_machine.cpu_family() and host_system, producing strings like
"aarch64-linux", where configure substitutes the GNU host triplet,
"aarch64-unknown-linux-gnu".  Two regression tests match against that
string, and both have quietly been doing the wrong thing on meson builds
ever since meson support arrived in 16.  collate.linux.utf8 skips itself
unless version() matches "linux-gnu", so it has never run at all;
infinite_recurse skips itself when version() matches
"powerpc64[^,]*-linux-gnu", so on ppc64 Linux it has been running the
very case it is meant to stay away from.

Fix by asking the compiler for its own target triplet with -dumpmachine
where it supports that, falling back to meson's idea of the host
otherwise.

Backpatch to 19
---
 meson.build | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)

diff --git a/meson.build b/meson.build
index f4cde249242..c0c10367b08 100644
--- a/meson.build
+++ b/meson.build
@@ -3293,10 +3293,23 @@ cdata.set('MEMSET_LOOP_LIMIT', memset_loop_limit)
 cdata.set_quoted('DLSUFFIX', dlsuffix)
 
 
+# configure substitutes the GNU host triplet into PG_VERSION_STR, and some
+# regression tests match against it: collate.linux.utf8 looks for "linux-gnu",
+# and infinite_recurse looks for "powerpc64[^,]*-linux-gnu".  Meson's own idea
+# of the host is just cpu_family-system, which never contains the ABI suffix,
+# so ask the compiler for the triplet when it can tell us.
+host_tuple = '@0@-@1@'.format(host_machine.cpu_family(), host_system)
+if cc.get_id() in ['gcc', 'clang']
+  dumpmachine = run_command(cc.cmd_array(), '-dumpmachine', check: false)
+  if dumpmachine.returncode() == 0 and dumpmachine.stdout().strip() != ''
+    host_tuple = dumpmachine.stdout().strip()
+  endif
+endif
+
 # built later than the rest of the version metadata, we need SIZEOF_VOID_P
 cdata.set_quoted('PG_VERSION_STR',
-  'PostgreSQL @0@ on @1@-@2@, compiled by @3@-@4@, @5@-bit'.format(
-    pg_version, host_machine.cpu_family(), host_system,
+  'PostgreSQL @0@ on @1@, compiled by @2@-@3@, @4@-bit'.format(
+    pg_version, host_tuple,
     cc.get_id(), cc.version(), cdata.get('SIZEOF_VOID_P') * 8,
   )
 )
-- 
2.43.0

