You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by al...@apache.org on 2025/07/20 19:05:57 UTC
(kudu) branch master updated: KUDU-3678: Fix PostgreSQL build on MacOS 15
This is an automated email from the ASF dual-hosted git repository.
alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git
The following commit(s) were added to refs/heads/master by this push:
new 3e93df43a KUDU-3678: Fix PostgreSQL build on MacOS 15
3e93df43a is described below
commit 3e93df43ae1b9bfff21af6dd8a0c5c0d43202cf0
Author: Jeffrey Smith <je...@gmail.com>
AuthorDate: Sat Jul 19 14:24:55 2025 -0400
KUDU-3678: Fix PostgreSQL build on MacOS 15
This pulls in a slightly modified patch from postgres to fix detection
of strchrnul() in MacOS 15. MacOS 15.4 now has that function, but
only when MACOSX_DEPLOYMENT_TARGET >= 15.4. Postgres' current
deployment target is 15.0, causing the build to fail.
Change-Id: Idb27f2d401360da69a6d49b5f33fd472c7083065
Reviewed-on: http://gerrit.cloudera.org:8080/23197
Tested-by: Alexey Serbin <al...@apache.org>
Reviewed-by: Alexey Serbin <al...@apache.org>
---
thirdparty/download-thirdparty.sh | 6 +-
.../postgres-fix-strchrnul-macos-check.patch | 214 +++++++++++++++++++++
2 files changed, 218 insertions(+), 2 deletions(-)
diff --git a/thirdparty/download-thirdparty.sh b/thirdparty/download-thirdparty.sh
index f586386d3..d867efa22 100755
--- a/thirdparty/download-thirdparty.sh
+++ b/thirdparty/download-thirdparty.sh
@@ -459,13 +459,15 @@ fetch_and_patch \
$GUMBO_QUERY_PATCHLEVEL \
"patch -p1 < $TP_DIR/patches/gumbo-query-namespace.patch"
-POSTGRES_PATCHLEVEL=1
+POSTGRES_PATCHLEVEL=2
fetch_and_patch \
$POSTGRES_NAME.tar.gz \
$POSTGRES_SOURCE \
$POSTGRES_PATCHLEVEL \
"patch -p0 < $TP_DIR/patches/postgres-root-can-run-initdb.patch" \
- "patch -p0 < $TP_DIR/patches/postgres-no-check-root.patch"
+ "patch -p0 < $TP_DIR/patches/postgres-no-check-root.patch" \
+ "patch -p1 < $TP_DIR/patches/postgres-fix-strchrnul-macos-check.patch"
+
POSTGRES_JDBC_PATCHLEVEL=0
fetch_and_patch \
diff --git a/thirdparty/patches/postgres-fix-strchrnul-macos-check.patch b/thirdparty/patches/postgres-fix-strchrnul-macos-check.patch
new file mode 100644
index 000000000..fce778249
--- /dev/null
+++ b/thirdparty/patches/postgres-fix-strchrnul-macos-check.patch
@@ -0,0 +1,214 @@
+From 6da2ba1d8a031984eb016fed6741bb2ac945f19d Mon Sep 17 00:00:00 2001
+From: Tom Lane <tg...@sss.pgh.pa.us>
+Date: Tue, 1 Apr 2025 16:49:51 -0400
+Subject: [PATCH] Fix detection and handling of strchrnul() for macOS 15.4.
+
+As of 15.4, macOS has strchrnul(), but access to it is blocked behind
+a check for MACOSX_DEPLOYMENT_TARGET >= 15.4. But our does-it-link
+configure check finds it, so we try to use it, and fail with the
+present default deployment target (namely 15.0). This accounts for
+today's buildfarm failures on indri and sifaka.
+
+This is the identical problem that we faced some years ago when Apple
+introduced preadv and pwritev in the same way. We solved that in
+commit f014b1b9b by using AC_CHECK_DECLS instead of AC_CHECK_FUNCS
+to check the functions' availability. So do the same now for
+strchrnul(). Interestingly, we already had a workaround for
+"the link check doesn't agree with <string.h>" cases with glibc,
+which we no longer need since only the header declaration is being
+checked.
+
+Testing this revealed that the meson version of this check has never
+worked, because it failed to use "-Werror=unguarded-availability-new".
+(Apparently nobody's tried to build with meson on macOS versions that
+lack preadv/pwritev as standard.) Adjust that while at it. Also,
+we had never put support for "-Werror=unguarded-availability-new"
+into v13, but we need that now.
+
+Co-authored-by: Tom Lane <tg...@sss.pgh.pa.us>
+Co-authored-by: Peter Eisentraut <pe...@eisentraut.org>
+Discussion: https://postgr.es/m/385134.1743523038@sss.pgh.pa.us
+Backpatch-through: 13
+---
+ configure | 14 +++++++++++++-
+ configure.ac | 2 +-
+ meson.build | 21 ++++++++++++++++++---
+ src/include/pg_config.h.in | 7 ++++---
+ src/port/snprintf.c | 29 +++++++++++++----------------
+ 5 files changed, 49 insertions(+), 24 deletions(-)
+
+diff --git a/configure b/configure
+index 30d949c3c4660..3d0e701c74513 100755
+--- a/configure 2025-07-18 15:13:39
++++ b/configure 2025-07-18 15:13:57
+@@ -15263,7 +15263,7 @@
+ LIBS_including_readline="$LIBS"
+ LIBS=`echo "$LIBS" | sed -e 's/-ledit//g' -e 's/-lreadline//g'`
+
+-for ac_func in backtrace_symbols copyfile copy_file_range getifaddrs getpeerucred inet_pton kqueue mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strchrnul strsignal syncfs sync_file_range uselocale wcstombs_l
++for ac_func in backtrace_symbols copyfile copy_file_range elf_aux_info getauxval getifaddrs getpeerucred inet_pton kqueue localeconv_l mbstowcs_l memset_s posix_fallocate ppoll pthread_is_threaded_np setproctitle setproctitle_fast strsignal syncfs sync_file_range uselocale wcstombs_l
+ do :
+ as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+@@ -15955,6 +15955,18 @@ cat >>confdefs.h <<_ACEOF
+ #define HAVE_DECL_PWRITEV $ac_have_decl
+ _ACEOF
+
++ac_fn_c_check_decl "$LINENO" "strchrnul" "ac_cv_have_decl_strchrnul" "#include <string.h>
++"
++if test "x$ac_cv_have_decl_strchrnul" = xyes; then :
++ ac_have_decl=1
++else
++ ac_have_decl=0
++fi
++
++cat >>confdefs.h <<_ACEOF
++#define HAVE_DECL_STRCHRNUL $ac_have_decl
++_ACEOF
++
+
+ # This is probably only present on macOS, but may as well check always
+ ac_fn_c_check_decl "$LINENO" "F_FULLFSYNC" "ac_cv_have_decl_F_FULLFSYNC" "#include <fcntl.h>
+diff --git a/configure.ac b/configure.ac
+index 25cdfcf65af71..47a287926bc5d 100644
+--- a/configure.ac
++++ b/configure.ac
+@@ -1772,7 +1772,6 @@ AC_CHECK_FUNCS(m4_normalize([
+ pthread_is_threaded_np
+ setproctitle
+ setproctitle_fast
+- strchrnul
+ strsignal
+ syncfs
+ sync_file_range
+@@ -1812,6 +1811,7 @@ AC_CHECK_DECLS([strlcat, strlcpy, strnlen, strsep])
+ # won't handle deployment target restrictions on macOS
+ AC_CHECK_DECLS([preadv], [], [], [#include <sys/uio.h>])
+ AC_CHECK_DECLS([pwritev], [], [], [#include <sys/uio.h>])
++AC_CHECK_DECLS([strchrnul], [], [], [#include <string.h>])
+
+ # This is probably only present on macOS, but may as well check always
+ AC_CHECK_DECLS(F_FULLFSYNC, [], [], [#include <fcntl.h>])
+diff --git a/meson.build b/meson.build
+index b8da4966297d8..ba7916d149337 100644
+--- a/meson.build
++++ b/meson.build
+@@ -2577,6 +2577,7 @@ decl_checks = [
+ decl_checks += [
+ ['preadv', 'sys/uio.h'],
+ ['pwritev', 'sys/uio.h'],
++ ['strchrnul', 'string.h'],
+ ]
+
+ # Check presence of some optional LLVM functions.
+@@ -2593,8 +2594,23 @@ foreach c : decl_checks
+ args = c.get(2, {})
+ varname = 'HAVE_DECL_' + func.underscorify().to_upper()
+
+- found = cc.has_header_symbol(header, func,
+- args: test_c_args, include_directories: postgres_inc,
++ found = cc.compiles('''
++#include <@0@>
++
++int main()
++{
++#ifndef @1@
++ (void) @1@;
++#endif
++
++return 0;
++}
++'''.format(header, func),
++ name: 'test whether @0@ is declared'.format(func),
++ # need to add cflags_warn to get at least
++ # -Werror=unguarded-availability-new if applicable
++ args: test_c_args + cflags_warn,
++ include_directories: postgres_inc,
+ kwargs: args)
+ cdata.set10(varname, found, description:
+ '''Define to 1 if you have the declaration of `@0@', and to 0 if you
+@@ -2802,7 +2818,6 @@ func_checks = [
+ ['shm_unlink', {'dependencies': [rt_dep], 'define': false}],
+ ['shmget', {'dependencies': [cygipc_dep], 'define': false}],
+ ['socket', {'dependencies': [socket_dep], 'define': false}],
+- ['strchrnul'],
+ ['strerror_r', {'dependencies': [thread_dep]}],
+ ['strlcat'],
+ ['strlcpy'],
+diff --git a/src/include/pg_config.h.in b/src/include/pg_config.h.in
+index 92f0616c4007f..2ac6157588369 100644
+--- a/src/include/pg_config.h.in
++++ b/src/include/pg_config.h.in
+@@ -103,6 +103,10 @@
+ don't. */
+ #undef HAVE_DECL_PWRITEV
+
++/* Define to 1 if you have the declaration of `strchrnul', and to 0 if you
++ don't. */
++#undef HAVE_DECL_STRCHRNUL
++
+ /* Define to 1 if you have the declaration of `strlcat', and to 0 if you
+ don't. */
+ #undef HAVE_DECL_STRLCAT
+@@ -373,9 +377,6 @@
+ /* Define to 1 if you have the <stdlib.h> header file. */
+ #undef HAVE_STDLIB_H
+
+-/* Define to 1 if you have the `strchrnul' function. */
+-#undef HAVE_STRCHRNUL
+-
+ /* Define to 1 if you have the `strerror_r' function. */
+ #undef HAVE_STRERROR_R
+
+diff --git a/src/port/snprintf.c b/src/port/snprintf.c
+index f8f2018ea0c14..d7f18b42d19ac 100644
+--- a/src/port/snprintf.c
++++ b/src/port/snprintf.c
+@@ -338,13 +338,22 @@ static void leading_pad(int zpad, int signvalue, int *padlen,
+ static void trailing_pad(int padlen, PrintfTarget *target);
+
+ /*
+- * If strchrnul exists (it's a glibc-ism), it's a good bit faster than the
+- * equivalent manual loop. If it doesn't exist, provide a replacement.
++ * If strchrnul exists (it's a glibc-ism, but since adopted by some other
++ * platforms), it's a good bit faster than the equivalent manual loop.
++ * Use it if possible, and if it doesn't exist, use this replacement.
+ *
+ * Note: glibc declares this as returning "char *", but that would require
+ * casting away const internally, so we don't follow that detail.
++ *
++ * Note: macOS has this too as of Sequoia 15.4, but it's hidden behind
++ * a deployment-target check that causes compile errors if the deployment
++ * target isn't high enough. So !HAVE_DECL_STRCHRNUL may mean "yes it's
++ * declared, but it doesn't compile". To avoid failing in that scenario,
++ * use a macro to avoid matching <string.h>'s name.
+ */
+-#ifndef HAVE_STRCHRNUL
++#if !HAVE_DECL_STRCHRNUL
++
++#define strchrnul pg_strchrnul
+
+ static inline const char *
+ strchrnul(const char *s, int c)
+@@ -354,19 +363,7 @@ strchrnul(const char *s, int c)
+ return s;
+ }
+
+-#else
+-
+-/*
+- * glibc's <string.h> declares strchrnul only if _GNU_SOURCE is defined.
+- * While we typically use that on glibc platforms, configure will set
+- * HAVE_STRCHRNUL whether it's used or not. Fill in the missing declaration
+- * so that this file will compile cleanly with or without _GNU_SOURCE.
+- */
+-#ifndef _GNU_SOURCE
+-extern char *strchrnul(const char *s, int c);
+-#endif
+-
+-#endif /* HAVE_STRCHRNUL */
++#endif /* !HAVE_DECL_STRCHRNUL */
+
+
+ /*
+