Hi Tristan, Andres, Jelte, and pgsql-hackers,

Thank you for the excellent work on decoupling C++ support in Meson from
LLVM

SUMMARY: v2 PATCH TESTED AND WORKS PERFECTLY

- Built PostgreSQL 19devel (current master) with Meson

- Config: -Dllvm=disabled -Dcpp_support=auto

- Before patch: CXX = (empty) → extension fails with shell error

- After patch: CXX = ccache c++ → extension builds successfully

- Tested with minimal C++ extension → cpp_test.so created

 REPRODUCTION & FIX STEPS

1. git remote add tristan https://github.com/tristan957/postgres.git

   git fetch tristan

   git checkout -b meson-cpp tristan/meson-cpp

2. meson setup build-fixed .. -Dllvm=disabled -Dcpp_support=auto

   meson compile && meson install

3. Built test C++ extension:

    cd ~/cpp_test_ext && make clean && make


VERIFIED OUTPUT
$ grep -E "^(CXX|CXXFLAGS) =" build-fixed/src/Makefile.global

CXX = ccache c++

CXXFLAGS = -fno-strict-aliasing -fwrapv -Wall -g -O0 ...

$ ls -l ~/cpp_test_ext/*.so

  -rwxr-xr-x 1 boss boss 21568 Nov  4 12:18
/home/boss/cpp_test_ext/cpp_test.so

Patch applies cleanly and works perfectly on 19devel.

While testing the C++ PGXS patch, I noticed a usability gap:

> If no C++ compiler is installed (e.g., `g++` missing), Meson silently

> proceeds with C++ disabled — users only discover the issue when extensions

> like pg_duckdb fail with confusing build errors.

This patch adds a clear, single warning during configuration:

WARNING: No C++ compiler found on your system.

Extensions using C++ (e.g. pg_duckdb) will FAIL to build.

Install g++ or clang++ to enable C++ support.


- Only shown when `add_languages('cpp')` returns `false`

- No warning when C++ is available

- Tested on PostgreSQL 19devel (with and without `g++`)

Attached: `0001-meson-warn-when-no-C-compiler-is-found.patch`

Happy to revise if there are better ways to surface this — open to
suggestions!

Thanks again for the great work on Meson C++ support.

Best regards,

Lakshmi
From a220d781b3a53565c799ea48b92460467c089f6c Mon Sep 17 00:00:00 2001
From: Tristan Partin <[email protected]>
Date: Wed, 16 Apr 2025 20:25:21 -0500
Subject: [PATCH] meson: warn when no C++ compiler is found

---
 meson.build               | 34 +++++++++++++++++++++++-----------
 src/include/meson.build   |  2 +-
 src/makefiles/meson.build |  9 ++++++---
 3 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/meson.build b/meson.build
index 395416a606..a0afb0d5a8 100644
--- a/meson.build
+++ b/meson.build
@@ -41,13 +41,22 @@ build_system = build_machine.system()
 host_cpu = host_machine.cpu_family()
 
 cc = meson.get_compiler('c')
+have_cpp = add_languages('cpp', required: false, native: false)
+if have_cpp
+  cpp = meson.get_compiler('cpp')
+endif
+# === USER WARNING: No C++ compiler found ===
+if not have_cpp
+  warning('No C++ compiler found on your system.\n' +
+          '         Extensions using C++ (e.g. pg_duckdb) will FAIL to build.\n' +
+          '         Install g++ or clang++ to enable C++ support.')
+endif
 
 not_found_dep = dependency('', required: false)
 thread_dep = dependency('threads')
 auto_features = get_option('auto_features')
 
 
-
 ###############################################################
 # Safety first
 ###############################################################
@@ -827,15 +836,13 @@ endif
 
 llvmopt = get_option('llvm')
 llvm = not_found_dep
-if add_languages('cpp', required: llvmopt, native: false)
+if have_cpp and not llvmopt.disabled()
   llvm = dependency('llvm', version: '>=14', method: 'config-tool', required: llvmopt)
 
   if llvm.found()
 
     cdata.set('USE_LLVM', 1)
 
-    cpp = meson.get_compiler('cpp')
-
     llvm_binpath = llvm.get_variable(configtool: 'bindir')
 
     ccache = find_program('ccache', native: true, required: false)
@@ -844,8 +851,13 @@ if add_languages('cpp', required: llvmopt, native: false)
     # find via PATH, too.
     clang = find_program(llvm_binpath / 'clang', 'clang', required: true)
   endif
-elif llvmopt.auto()
-  message('llvm requires a C++ compiler')
+else
+  msg = 'llvm requires a C++ compiler'
+  if llvmopt.auto()
+    message(msg)
+  elif llvmopt.enabled()
+    error(msg)
+  endif
 endif
 
 
@@ -2061,7 +2073,7 @@ common_functional_flags = [
 ]
 
 cflags += cc.get_supported_arguments(common_functional_flags)
-if llvm.found()
+if have_cpp
   cxxflags += cpp.get_supported_arguments(common_functional_flags)
 endif
 
@@ -2085,7 +2097,7 @@ common_warning_flags = [
 ]
 
 cflags_warn += cc.get_supported_arguments(common_warning_flags)
-if llvm.found()
+if have_cpp
   cxxflags_warn += cpp.get_supported_arguments(common_warning_flags)
 endif
 
@@ -2139,7 +2151,7 @@ foreach w : negative_warning_flags
   if cc.has_argument('-W' + w)
     cflags_warn += '-Wno-' + w
   endif
-  if llvm.found() and cpp.has_argument('-W' + w)
+  if have_cpp and cpp.has_argument('-W' + w)
     cxxflags_warn += '-Wno-' + w
   endif
 endforeach
@@ -2200,7 +2212,7 @@ elif optimization == 's'
 endif
 
 cflags_builtin = cc.get_supported_arguments(common_builtin_flags)
-if llvm.found()
+if have_cpp
   cxxflags_builtin = cpp.get_supported_arguments(common_builtin_flags)
 endif
 
@@ -3929,7 +3941,7 @@ summary(
   section: 'Compiler Flags',
 )
 
-if llvm.found()
+if have_cpp
   summary(
     {
       'C++ compiler': '@0@ @1@'.format(cpp.get_id(), cpp.version()),
diff --git a/src/include/meson.build b/src/include/meson.build
index 7cb3075da2..9be2f25e4a 100644
--- a/src/include/meson.build
+++ b/src/include/meson.build
@@ -36,7 +36,7 @@ config_paths_data.set_quoted('MANDIR', dir_prefix / dir_man)
 var_cc = ' '.join(cc.cmd_array())
 var_cpp = ' '.join(cc.cmd_array() + ['-E'])
 var_cflags = ' '.join(cflags + cflags_builtin + cflags_warn + get_option('c_args'))
-if llvm.found()
+if have_cpp
   var_cxxflags = ' '.join(cxxflags + cxxflags_builtin + cxxflags_warn + get_option('cpp_args'))
 else
   var_cxxflags = ''
diff --git a/src/makefiles/meson.build b/src/makefiles/meson.build
index 0def244c90..ff62200e5f 100644
--- a/src/makefiles/meson.build
+++ b/src/makefiles/meson.build
@@ -31,7 +31,6 @@ if not working_strip
   strip_shared_cmd = [':']
 endif
 
-
 pgxs_kv = {
   'PACKAGE_URL': pg_url,
   'PACKAGE_VERSION': pg_version,
@@ -119,16 +118,20 @@ pgxs_kv = {
   'LIBS': var_libs,
 }
 
+if have_cpp
+  pgxs_kv += {
+    'CXX': ' '.join(cpp.cmd_array()),
+  }
+endif
+
 if llvm.found()
   pgxs_kv += {
     'CLANG': clang.full_path(),
-    'CXX': ' '.join(cpp.cmd_array()),
     'LLVM_BINPATH': llvm_binpath,
   }
 else
   pgxs_kv += {
     'CLANG': '',
-    'CXX': '',
     'LLVM_BINPATH': '',
   }
 endif
-- 
2.39.5

Reply via email to