Hide ICU C++ APIs from pg_locale.h
authorJohn Naylor <[email protected]>
Wed, 9 Jul 2025 07:20:22 +0000 (14:20 +0700)
committerJohn Naylor <[email protected]>
Wed, 9 Jul 2025 07:20:22 +0000 (14:20 +0700)
The cpluspluscheck script wraps our headers in `extern "C"`. This
disables name mangling, which is necessary for the C++ templates
in system ICU headers. cpluspluscheck thus fails when the build is
configured with ICU (the default). CI worked around this by disabling
ICU, but let's make it work so others can run the script.

We can specify we only want the C APIs by defining U_SHOW_CPLUSPLUS_API
to be 0 in pg_locale.h. Extensions that want the C++ APIs can include
ICU headers separately before including PostgreSQL headers.

ICU documentation:
https://github.com/unicode-org/icu/blob/main/docs/processes/release/tasks/healthy-code.md#test-icu4c-headers

Suggested-by: Andres Freund <[email protected]>
Reviewed-by: Peter Eisentraut <[email protected]>
Reviewed-by: Tom Lane <[email protected]>
Reviewed-by: Andres Freund <[email protected]>
Discussion: https://postgr.es/m/20220323002024.f2g6tivduzrktgfa%40alap3.anarazel.de
Discussion: https://postgr.es/m/CANWCAZbgiaz1_0-F4SD%2B%3D-e9onwAnQdBGJbhg94EqUu4Gb7WyA%40mail.gmail.com

.cirrus.tasks.yml
src/include/utils/pg_locale.h

index 92057006c9309aea9a9e57bdab50f137dedee46c..1a366975d824fb3694803482b265e7478d489d46 100644 (file)
@@ -938,14 +938,11 @@ task:
   # - Don't use ccache, the files are uncacheable, polluting ccache's
   #   cache
   # - Use -fmax-errors, as particularly cpluspluscheck can be very verbose
-  # - XXX have to disable ICU to avoid errors:
-  #   https://postgr.es/m/20220323002024.f2g6tivduzrktgfa%40alap3.anarazel.de
   ###
   always:
     headers_headerscheck_script: |
       time ./configure \
         ${LINUX_CONFIGURE_FEATURES} \
-        --without-icu \
         --quiet \
         CC="gcc" CXX"=g++" CLANG="clang-16"
       make -s -j${BUILD_JOBS} clean
index 44ff60a25b4ce0110d82a33a52e428ff30fd6722..1cd7c76a0a7b121633d539bc22108eb02105d282 100644 (file)
@@ -15,6 +15,9 @@
 #include "mb/pg_wchar.h"
 
 #ifdef USE_ICU
+/* only include the C APIs, to avoid errors in cpluspluscheck */
+#undef U_SHOW_CPLUSPLUS_API
+#define U_SHOW_CPLUSPLUS_API 0
 #include <unicode/ucol.h>
 #endif