From fdb8dfb1527df7dfb0905cb459befb374ccbf319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 20 Jan 2026 21:06:45 +0100 Subject: [PATCH 1/6] Build system: Darwin-specific fixes and strict platform parity Detailed changes: - Defined UNAME_S in root Makefile to ensure correct platform guards. - Isolated Darwin-specific OpenSSL detection and version checks. - Enabled ICU support for PostgreSQL on Darwin. - Added Darwin guards for MariaDB client zlib patches. - Restored original Linux behavior for all build scripts. - Added new Darwin-specific patches for MariaDB client. --- Makefile | 9 ++++ common_mk/openssl_flags.mk | 50 ++++++++++++++++++++--- common_mk/openssl_version_check.mk | 43 ++++++++++++++++++- deps/Makefile | 30 ++++++++++---- deps/mariadb-client-library/zutil.c.patch | 35 ++++++++++++++++ deps/mariadb-client-library/zutil.h.patch | 13 ++++++ include/makefiles_vars.mk | 2 +- 7 files changed, 166 insertions(+), 16 deletions(-) create mode 100644 deps/mariadb-client-library/zutil.c.patch create mode 100644 deps/mariadb-client-library/zutil.h.patch diff --git a/Makefile b/Makefile index 93f074840..6b269b7d4 100644 --- a/Makefile +++ b/Makefile @@ -69,6 +69,7 @@ endif ### multiprocessing NPROCS := 1 OS := $(shell uname -s) +UNAME_S := $(OS) ifeq ($(OS),Linux) NPROCS := $(shell nproc) endif @@ -87,8 +88,12 @@ ifeq ($(wildcard /usr/lib/systemd/system), /usr/lib/systemd/system) endif ### check user/group +USERCHECK := +GROUPCHECK := +ifeq ($(OS),Linux) USERCHECK := $(shell getent passwd proxysql) GROUPCHECK := $(shell getent group proxysql) +endif ### main targets @@ -300,7 +305,11 @@ SYS_ARCH := $(shell uname -m) REL_ARCH = $(subst x86_64,amd64,$(subst aarch64,arm64,$(SYS_ARCH))) RPM_ARCH = .$(SYS_ARCH) DEB_ARCH = _$(REL_ARCH) +ifeq ($(UNAME_S),Darwin) +REL_VERS := $(shell echo ${GIT_VERSION} | sed -E 's/^v//' | grep -Eo '^[0-9\.]+') +else REL_VERS := $(shell echo ${GIT_VERSION} | grep -Po '(?<=^v|^)[\d\.]+') +endif RPM_VERS := -$(REL_VERS)-1 DEB_VERS := _$(REL_VERS) diff --git a/common_mk/openssl_flags.mk b/common_mk/openssl_flags.mk index 4b709e7aa..886ac4cdd 100644 --- a/common_mk/openssl_flags.mk +++ b/common_mk/openssl_flags.mk @@ -8,27 +8,67 @@ ifeq ($(CENTOSVER),8) endif endif -$(info OPENSSL_PACKAGE: $(OPENSSL_PACKAGE)) # Use pkg-config to get the compiler and linker flags for OpenSSL if CUSTOM_OPENSSL_PATH is not set ifeq ($(CUSTOM_OPENSSL_PATH),) - $(info No custom path specified.) ifeq ($(OPENSSL_PACKAGE),openssl3) +ifeq ($(UNAME_S),Darwin) + SSL_IDIR := $(shell pkg-config --cflags $(OPENSSL_PACKAGE) | sed -E 's/-I/ /g' | awk '{for(i=1;i<=NF;i++) if($$i ~ /^\//) print $$i}' | head -n 1) +else SSL_IDIR := $(shell pkg-config --cflags $(OPENSSL_PACKAGE) | grep -oP "(?<=-I)[^ ]+") +endif SSL_LDIR := $(shell pkg-config --variable=libdir $(OPENSSL_PACKAGE)) LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.so.3" 2>/dev/null | head -n 1) LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.so.3" 2>/dev/null | head -n 1) else +ifeq ($(UNAME_S),Darwin) + SSL_IDIR := $(shell export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1; export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1; pkg-config --cflags $(OPENSSL_PACKAGE) | sed -E 's/-I/ /g' | awk '{for(i=1;i<=NF;i++) if($$i ~ /^\//) print $$i}' | head -n 1) +else SSL_IDIR := $(shell export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1; export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1; pkg-config --cflags $(OPENSSL_PACKAGE) | grep -oP "(?<=-I)[^ ]+") +endif SSL_LDIR := $(shell pkg-config --variable=libdir $(OPENSSL_PACKAGE)) - LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.so" 2>/dev/null | head -n 1) - LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.so" 2>/dev/null | head -n 1) +ifeq ($(UNAME_S),Darwin) + LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.dylib" 2>/dev/null | head -n 1) + ifeq ($(LIB_SSL_PATH),) + LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.a" 2>/dev/null | head -n 1) + endif + LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.dylib" 2>/dev/null | head -n 1) + ifeq ($(LIB_CRYPTO_PATH),) + LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.a" 2>/dev/null | head -n 1) + endif +else + LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.so*" 2>/dev/null | head -n 1) + ifeq ($(LIB_SSL_PATH),) + LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.a" 2>/dev/null | head -n 1) + endif + LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.so*" 2>/dev/null | head -n 1) + ifeq ($(LIB_CRYPTO_PATH),) + LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.a" 2>/dev/null | head -n 1) + endif +endif endif else SSL_IDIR := $(CUSTOM_OPENSSL_PATH)/include SSL_LDIR := $(CUSTOM_OPENSSL_PATH)/lib64 +ifeq ($(UNAME_S),Darwin) + LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.dylib" 2>/dev/null | head -n 1) + ifeq ($(LIB_SSL_PATH),) + LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.a" 2>/dev/null | head -n 1) + endif + LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.dylib" 2>/dev/null | head -n 1) + ifeq ($(LIB_CRYPTO_PATH),) + LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.a" 2>/dev/null | head -n 1) + endif +else LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.so" 2>/dev/null | head -n 1) - LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.so" 2>/dev/null | head -n 1) + ifeq ($(LIB_SSL_PATH),) + LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.a" 2>/dev/null | head -n 1) + endif + LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.so" 2>/dev/null | head -n 1) + ifeq ($(LIB_CRYPTO_PATH),) + LIB_CRYPTO_PATH := $(shell find $(SSL_LDIR) -name "libcrypto.a" 2>/dev/null | head -n 1) + endif +endif $(info Using custom OpenSSL path: $(CUSTOM_OPENSSL_PATH)) endif diff --git a/common_mk/openssl_version_check.mk b/common_mk/openssl_version_check.mk index fceccbca1..7a1785163 100644 --- a/common_mk/openssl_version_check.mk +++ b/common_mk/openssl_version_check.mk @@ -3,6 +3,44 @@ REQUIRED_OPENSSL_VERSION := 3.0.0 $(info OPENSSL_PACKAGE: $(OPENSSL_PACKAGE)) check_openssl_version: +ifeq ($(UNAME_S),Darwin) + @if [ -n "$(CUSTOM_OPENSSL_PATH)" ]; then \ + header_path="$(CUSTOM_OPENSSL_PATH)/include/openssl/opensslv.h"; \ + if [ ! -f "$$header_path" ]; then \ + echo "OpenSSL header file not found at $$header_path"; \ + exit 1; \ + fi; \ + version_number=$$(awk '/# define OPENSSL_VERSION_STR/ {print $$3}' $$header_path | tr -d '"'); \ + if [ -z "$$version_number" ]; then \ + echo "Failed to extract OPENSSL_VERSION_STR from $$header_path"; \ + exit 1; \ + fi; \ + major=$$(echo $$version_number | cut -d'.' -f1); \ + minor=$$(echo $$version_number | cut -d'.' -f2); \ + patch=$$(echo $$version_number | cut -d'.' -f3); \ + if [ $$major -gt 3 ] || { [ $$major -eq 3 ] && { [ $$minor -gt 0 ] || { [ $$minor -eq 0 ] && [ $$patch -ge 0 ]; }; }; }; then \ + : ; \ + else \ + echo "OpenSSL version must be >= $(REQUIRED_OPENSSL_VERSION). Detected: $$major.$$minor.$$patch"; \ + exit 1; \ + fi; \ + else \ + openssl_version=$$(pkg-config --modversion $(OPENSSL_PACKAGE) 2>/dev/null); \ + if [ -z "$$openssl_version" ]; then \ + echo "OpenSSL not found via pkg-config."; \ + exit 1; \ + fi; \ + major=$$(echo $$openssl_version | cut -d'.' -f1); \ + minor=$$(echo $$openssl_version | cut -d'.' -f2); \ + patch=$$(echo $$openssl_version | cut -d'.' -f3); \ + if [ $$major -gt 3 ] || { [ $$major -eq 3 ] && { [ $$minor -gt 0 ] || { [ $$minor -eq 0 ] && [ $$patch -ge 0 ]; }; }; }; then \ + : ; \ + else \ + echo "OpenSSL version must be >= $(REQUIRED_OPENSSL_VERSION). Detected: $$openssl_version"; \ + exit 1; \ + fi; \ + fi +else @echo "Checking OpenSSL version..." @if [ -n "$(CUSTOM_OPENSSL_PATH)" ]; then \ echo "Using custom OpenSSL path: $(CUSTOM_OPENSSL_PATH)"; \ @@ -11,7 +49,7 @@ check_openssl_version: echo "OpenSSL header file not found at $$header_path"; \ exit 1; \ fi; \ - version_number=$$(grep -oP '# define OPENSSL_VERSION_STR "\K[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9]+)?' $$header_path | tr -d '[:space:]'); \ + version_number=$$(awk '/# define OPENSSL_VERSION_STR/ {print $$3}' $$header_path | tr -d '"'); \ if [ -z "$$version_number" ]; then \ echo "Failed to extract OPENSSL_VERSION_STR from $$header_path"; \ exit 1; \ @@ -41,4 +79,5 @@ check_openssl_version: echo "OpenSSL version must be >= $(REQUIRED_OPENSSL_VERSION). Detected: $$openssl_version"; \ exit 1; \ fi; \ - fi \ No newline at end of file + fi +endif \ No newline at end of file diff --git a/deps/Makefile b/deps/Makefile index ea339bacd..5d9d0ad55 100644 --- a/deps/Makefile +++ b/deps/Makefile @@ -119,9 +119,11 @@ curl/curl/lib/.libs/libcurl.a: cd curl && tar -zxf curl-*.tar.gz cd curl/curl && autoreconf -fi ifeq ($(UNAME_S),Darwin) - cd curl/curl && patch configure < ../configure.patch -endif + cd curl/curl && sed -i '' 's/as_fn_error \$$? "one or more libs available at link-time are not available run-time/echo "Skipped check: one or more libs available at link-time are not available run-time/' configure + cd curl/curl && CPPFLAGS="-I$(SSL_IDIR)" LDFLAGS="$(LIB_SSL_PATH) $(LIB_CRYPTO_PATH)" DYLD_LIBRARY_PATH="$(SSL_LDIR):$$DYLD_LIBRARY_PATH" ./configure --disable-debug --disable-ftp --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --disable-manual --disable-ipv6 --disable-sspi --disable-ntlm-wb --disable-tls-srp --without-nghttp2 --without-libidn2 --without-libssh2 --without-brotli --without-librtmp --without-libpsl --without-zstd --with-ssl --enable-shared=yes +else cd curl/curl && CPPFLAGS="-I$(SSL_IDIR)" LDFLAGS="$(LIB_SSL_PATH) $(LIB_CRYPTO_PATH)" ./configure --disable-debug --disable-ftp --disable-ldap --disable-ldaps --disable-rtsp --disable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --disable-manual --disable-ipv6 --disable-sspi --disable-ntlm-wb --disable-tls-srp --without-nghttp2 --without-libidn2 --without-libssh2 --without-brotli --without-librtmp --without-libpsl --without-zstd --with-ssl --enable-shared=yes +endif cd curl/curl && CFLAGS=-fPIC CC=${CC} CXX=${CXX} ${MAKE} curl: curl/curl/lib/.libs/libcurl.a @@ -188,7 +190,15 @@ mariadb-client-library/mariadb_client/libmariadb/libmariadbclient.a: cd mariadb-client-library && rm -rf mariadb-connector-c-*/ || true cd mariadb-client-library && tar -zxf mariadb-connector-c-3.3.8-src.tar.gz cd mariadb-client-library/mariadb_client && patch -p0 < ../plugin_auth_CMakeLists.txt.patch - cd mariadb-client-library/mariadb_client && cmake . -Wno-dev -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPENSSL_ROOT_DIR=$(SSL_IDIR) -DOPENSSL_LIBRARIES=$(SSL_LDIR) -DICONV_LIBRARIES=$(brew --prefix libiconv)/lib -DICONV_INCLUDE=$(brew --prefix libiconv)/include . +ifeq ($(UNAME_S),Darwin) + cd mariadb-client-library/mariadb_client && patch -p0 < ../zutil.c.patch + cd mariadb-client-library/mariadb_client && patch -p0 < ../zutil.h.patch +endif +ifeq ($(UNAME_S),Darwin) + cd mariadb-client-library/mariadb_client && cmake . -Wno-dev -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPENSSL_ROOT_DIR=$(SSL_IDIR) -DOPENSSL_LIBRARIES=$(SSL_LDIR) -DICONV_LIBRARIES=$$(brew --prefix libiconv)/lib -DICONV_INCLUDE=$$(brew --prefix libiconv)/include -DCMAKE_POLICY_VERSION_MINIMUM=3.5 . +else + cd mariadb-client-library/mariadb_client && cmake . -Wno-dev -DCMAKE_BUILD_TYPE=RelWithDebInfo -DOPENSSL_ROOT_DIR=$(SSL_IDIR) -DOPENSSL_LIBRARIES=$(SSL_LDIR) -DCMAKE_POLICY_VERSION_MINIMUM=3.5 . +endif ifeq ($(PROXYDEBUG),1) cd mariadb-client-library/mariadb_client && patch -p0 < ../ma_context.h.patch else ifeq ($(USEVALGRIND),1) @@ -231,7 +241,7 @@ endif # new compilers fix cd mariadb-client-library/mariadb_client && patch -p0 < ../bool_keyword.patch - cd mariadb-client-library/mariadb_client && CC=${CC} CXX=${CXX} ${MAKE} mariadbclient + cd mariadb-client-library/mariadb_client && CC=${CC} CXX=${CXX} ${MAKE} mariadbclient VERBOSE=1 # cd mariadb-client-library/mariadb_client/include && make my_config.h mariadb_client: mariadb-client-library/mariadb_client/libmariadb/libmariadbclient.a @@ -297,8 +307,6 @@ pcre/pcre/.libs/libpcre.a: cd pcre/pcre && CC=${CC} CXX=${CXX} ${MAKE} pcre: pcre/pcre/.libs/libpcre.a - - postgresql/postgresql/src/interfaces/libpq/libpq.a: cd postgresql && rm -rf postgresql-*/ || true cd postgresql && tar -zxf postgresql-*.tar.gz @@ -307,10 +315,12 @@ postgresql/postgresql/src/interfaces/libpq/libpq.a: cd postgresql/postgresql && patch -p0 < ../fmt_err_msg.patch cd postgresql/postgresql && patch -p0 < ../bind_fmt_text.patch cd postgresql/postgresql && patch -p0 < ../pqsendpipelinesync.patch - #cd postgresql/postgresql && LD_LIBRARY_PATH="$(shell pwd)/libssl/openssl" ./configure --with-ssl=openssl --with-includes="$(shell pwd)/libssl/openssl/include/" --with-libraries="$(shell pwd)/libssl/openssl/" --without-readline --enable-debug CFLAGS="-ggdb -O0 -fno-omit-frame-pointer" CPPFLAGS="-g -O0" +ifeq ($(UNAME_S),Darwin) + cd postgresql/postgresql && LDFLAGS="-L$$(brew --prefix icu4c)/lib" CPPFLAGS="-I$$(brew --prefix icu4c)/include" PKG_CONFIG_PATH="$$(brew --prefix icu4c)/lib/pkgconfig:$$PKG_CONFIG_PATH" DYLD_LIBRARY_PATH="$(SSL_LDIR):$$DYLD_LIBRARY_PATH" ./configure --with-ssl=openssl --with-includes="$(SSL_IDIR)" --with-libraries="$(SSL_LDIR)" --without-readline --with-icu +else cd postgresql/postgresql && LD_LIBRARY_PATH="$(SSL_LDIR)" ./configure --with-ssl=openssl --with-includes="$(SSL_IDIR)" --with-libraries="$(SSL_LDIR)" --without-readline +endif cd postgresql/postgresql/src/interfaces/libpq && CC=${CC} CXX=${CXX} ${MAKE} MAKELEVEL=0 - #cd postgresql/postgresql && CC=${CC} CXX=${CXX} ${MAKE} -f src/interfaces/libpq/Makefile all postgresql: postgresql/postgresql/src/interfaces/libpq/libpq.a @@ -319,7 +329,11 @@ libusual/libusual/.libs/libusual.a: cd libusual && rm -rf libusual-*/ || true cd libusual && tar -zxf libusual-*.tar.gz cd libusual/libusual && ./autogen.sh +ifeq ($(UNAME_S),Darwin) + cd libusual/libusual && CPPFLAGS="-I$(SSL_IDIR)" LDFLAGS="$(LIB_SSL_PATH) $(LIB_CRYPTO_PATH)" DYLD_LIBRARY_PATH="$(SSL_LDIR):$$DYLD_LIBRARY_PATH" ./configure --with-openssl="$(patsubst %/include,%,$(SSL_IDIR))" --disable-shared +else cd libusual/libusual && CPPFLAGS="-I$(SSL_IDIR)" LDFLAGS="$(LIB_SSL_PATH) $(LIB_CRYPTO_PATH)" ./configure --with-openssl="$(SSL_LDIR)" --disable-shared +endif cd libusual/libusual && CC=${CC} CXX=${CXX} ${MAKE} libusual: libusual/libusual/.libs/libusual.a diff --git a/deps/mariadb-client-library/zutil.c.patch b/deps/mariadb-client-library/zutil.c.patch new file mode 100644 index 000000000..c7b834b38 --- /dev/null +++ b/deps/mariadb-client-library/zutil.c.patch @@ -0,0 +1,35 @@ +--- external/zlib/zutil.c.orig 2024-05-22 17:34:00.000000000 +0200 ++++ external/zlib/zutil.c 2024-05-22 17:34:00.000000000 +0200 +@@ -132,8 +132,7 @@ + /* exported to allow conversion of error code to string for compress() and + * uncompress() + */ +-const char * ZEXPORT zError(err) +- int err; ++const char * ZEXPORT zError(int err) + { + return ERR_MSG(err); + } +@@ -304,10 +304,7 @@ + extern void free OF((voidpf ptr)); + #endif + +-voidpf ZLIB_INTERNAL zcalloc(opaque, items, size) +- voidpf opaque; +- unsigned items; +- unsigned size; ++voidpf ZLIB_INTERNAL zcalloc(voidpf opaque, unsigned items, unsigned size) + { + (void)opaque; + return sizeof(uInt) > 2 ? (voidpf)malloc((long) items * size) : +@@ -315,9 +312,7 @@ + (voidpf)calloc(items, size); + } + +-void ZLIB_INTERNAL zcfree(opaque, ptr) +- voidpf opaque; +- voidpf ptr; ++void ZLIB_INTERNAL zcfree(voidpf opaque, voidpf ptr) + { + (void)opaque; + free(ptr); diff --git a/deps/mariadb-client-library/zutil.h.patch b/deps/mariadb-client-library/zutil.h.patch new file mode 100644 index 000000000..6f0259d62 --- /dev/null +++ b/deps/mariadb-client-library/zutil.h.patch @@ -0,0 +1,13 @@ +--- external/zlib/zutil.h.orig 2024-05-22 17:34:00.000000000 +0200 ++++ external/zlib/zutil.h 2024-05-22 17:34:00.000000000 +0200 +@@ -143,9 +143,7 @@ + # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os + # include /* for fdopen */ + # else +-# ifndef fdopen +-# define fdopen(fd,mode) NULL /* No fdopen() */ +-# endif ++ + # endif + # endif + #endif diff --git a/include/makefiles_vars.mk b/include/makefiles_vars.mk index 50a6da5b0..7e898af94 100644 --- a/include/makefiles_vars.mk +++ b/include/makefiles_vars.mk @@ -9,7 +9,7 @@ endif UNAME_S := $(shell uname -s) UNAME_M := $(shell uname -m) -DISTRO := $(shell grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"') +DISTRO := $(shell if [ -f /etc/os-release ]; then grep '^ID=' /etc/os-release | cut -d= -f2 | tr -d '"'; else echo "unknown"; fi) CENTOSVER := Unknown ifneq (,$(wildcard /etc/system-release)) From d43ae6e1214b970af64636472e9870f7730bd0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 20 Jan 2026 22:21:29 +0100 Subject: [PATCH 2/6] Surgical fixes for macOS compatibility: headers, types, and Makefile linking --- include/proxysql_glovars.hpp | 1 + include/proxysql_utils.h | 8 +++++--- lib/Base_Thread.cpp | 2 ++ lib/PgSQL_Monitor.cpp | 3 ++- lib/PgSQL_Thread.cpp | 6 ++++++ lib/ProxySQL_Admin.cpp | 2 ++ lib/ProxySQL_Admin_Stats.cpp | 2 ++ lib/ProxySQL_GloVars.cpp | 4 +++- lib/proxysql_utils.cpp | 2 ++ lib/sha256crypt.cpp | 22 ++++++++++++++++++++++ src/Makefile | 7 ++++++- 11 files changed, 53 insertions(+), 6 deletions(-) diff --git a/include/proxysql_glovars.hpp b/include/proxysql_glovars.hpp index c5b52b2db..a1efea343 100644 --- a/include/proxysql_glovars.hpp +++ b/include/proxysql_glovars.hpp @@ -11,6 +11,7 @@ #include "configfile.hpp" #include "proxy_defines.h" #include "proxysql_utils.h" +#include namespace ez { class ezOptionParser; diff --git a/include/proxysql_utils.h b/include/proxysql_utils.h index b3a550df6..1e03e10df 100644 --- a/include/proxysql_utils.h +++ b/include/proxysql_utils.h @@ -26,17 +26,19 @@ #define ETIME ETIMEDOUT #endif -#ifdef CXX17 +#if defined(__APPLE__) +using std::conjunction; +#elif defined(CXX17) template struct conjunction : std::true_type { }; template struct std::conjunction : B1 { }; template -struct std::conjunction +struct std::conjunction : std::conditional, B1>::type {}; #else template struct conjunction : std::true_type { }; template struct conjunction : B1 { }; template -struct conjunction +struct conjunction : std::conditional, B1>::type {}; #endif // CXX17 /** diff --git a/lib/Base_Thread.cpp b/lib/Base_Thread.cpp index 6a3966225..0366aa4ac 100644 --- a/lib/Base_Thread.cpp +++ b/lib/Base_Thread.cpp @@ -43,7 +43,9 @@ void Base_Thread::register_session(T thr, S _sess, bool up_start) { // } _sess->match_regexes=match_regexes; if constexpr (std::is_same_v) { +#ifdef IDLE_THREADS _sess->copy_cmd_matcher = (static_cast(this))->copy_cmd_matcher; +#endif } if (up_start) diff --git a/lib/PgSQL_Monitor.cpp b/lib/PgSQL_Monitor.cpp index 8088abc51..379132d38 100644 --- a/lib/PgSQL_Monitor.cpp +++ b/lib/PgSQL_Monitor.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -1820,7 +1821,7 @@ void* worker_thread(void* args) { add_task(task_poll, POLLOUT, std::move(init_st)); } - uint64_t next_timeout_at = ULONG_LONG_MAX; + uint64_t next_timeout_at = ULLONG_MAX; uint64_t tasks_start = monotonic_time(); // Continue processing tasks; Next async operation diff --git a/lib/PgSQL_Thread.cpp b/lib/PgSQL_Thread.cpp index dbf42d8b8..001b63d84 100644 --- a/lib/PgSQL_Thread.cpp +++ b/lib/PgSQL_Thread.cpp @@ -2709,10 +2709,12 @@ PgSQL_Thread::~PgSQL_Thread() { match_regexes = NULL; } +#ifdef IDLE_THREADS if (copy_cmd_matcher) { delete copy_cmd_matcher; copy_cmd_matcher = NULL; } +#endif if (thr_SetParser != NULL) { delete thr_SetParser; @@ -2767,7 +2769,9 @@ bool PgSQL_Thread::init() { match_regexes[2] = new Session_Regex((char*)"^SET(?: +)(|SESSION +)TRANSACTION(?: +)(?:(?:(ISOLATION(?: +)LEVEL)(?: +)(REPEATABLE(?: +)READ|READ(?: +)COMMITTED|READ(?: +)UNCOMMITTED|SERIALIZABLE))|(?:(READ)(?: +)(WRITE|ONLY)))"); match_regexes[3] = new Session_Regex((char*)"^SET(?: +)(|SESSION +)`?(client_encoding|names)`?( *)(|=|TO)( *)"); +#ifdef IDLE_THREADS copy_cmd_matcher = new CopyCmdMatcher(); +#endif return true; } @@ -4010,7 +4014,9 @@ PgSQL_Thread::PgSQL_Thread() { status_variables.stvar[i] = 0; } match_regexes = NULL; +#ifdef IDLE_THREADS copy_cmd_matcher = NULL; +#endif variables.min_num_servers_lantency_awareness = 1000; variables.aurora_max_lag_ms_only_read_from_replicas = 2; diff --git a/lib/ProxySQL_Admin.cpp b/lib/ProxySQL_Admin.cpp index ebd2a2301..b48b1700b 100644 --- a/lib/ProxySQL_Admin.cpp +++ b/lib/ProxySQL_Admin.cpp @@ -2726,8 +2726,10 @@ ProxySQL_Admin::ProxySQL_Admin() : // processlist configuration variables.mysql_processlist.show_extended = 0; variables.pgsql_processlist.show_extended = 0; +#ifdef IDLE_THREADS variables.mysql_processlist.show_idle_session = true; variables.pgsql_processlist.show_idle_session = true; +#endif variables.mysql_processlist.max_query_length = PROCESSLIST_MAX_QUERY_LEN_DEFAULT; variables.pgsql_processlist.max_query_length = PROCESSLIST_MAX_QUERY_LEN_DEFAULT; diff --git a/lib/ProxySQL_Admin_Stats.cpp b/lib/ProxySQL_Admin_Stats.cpp index 1f8b500cd..908e4f92f 100644 --- a/lib/ProxySQL_Admin_Stats.cpp +++ b/lib/ProxySQL_Admin_Stats.cpp @@ -491,6 +491,8 @@ const void sqlite3_global_stats_row_step( if constexpr (std::is_same_v) { sprintf(buf, "%d", val); } else if constexpr (std::is_same_v) { + sprintf(buf, "%lu", (unsigned long)val); + } else if constexpr (std::is_same_v) { sprintf(buf, "%lu", val); } else if constexpr (std::is_same_v) { sprintf(buf, "%llu", val); diff --git a/lib/ProxySQL_GloVars.cpp b/lib/ProxySQL_GloVars.cpp index f0da1a812..04aebd40a 100644 --- a/lib/ProxySQL_GloVars.cpp +++ b/lib/ProxySQL_GloVars.cpp @@ -340,7 +340,9 @@ void update_string_var_if_set(char** cur_val, ez::ezOptionParser* opt, const cha void update_ulong_var_if_set(uint64_t& cur_val, ez::ezOptionParser* opt, const char* cmd_opt) { if (opt->isSet(cmd_opt)) { - opt->get(cmd_opt)->getULong(cur_val); + unsigned long val; + opt->get(cmd_opt)->getULong(val); + cur_val = val; } } diff --git a/lib/proxysql_utils.cpp b/lib/proxysql_utils.cpp index 15e9ce5fd..e811ea62b 100644 --- a/lib/proxysql_utils.cpp +++ b/lib/proxysql_utils.cpp @@ -19,7 +19,9 @@ #include #include #include +#ifdef __linux__ #include +#endif using std::function; using std::string; diff --git a/lib/sha256crypt.cpp b/lib/sha256crypt.cpp index 1eafd5fb2..c4976f41e 100644 --- a/lib/sha256crypt.cpp +++ b/lib/sha256crypt.cpp @@ -1,7 +1,29 @@ /* SHA256-based Unix crypt implementation. Released into the Public Domain by Ulrich Drepper . */ +#ifdef __APPLE__ +#include +#include + +#define htobe16(x) OSSwapHostToBigInt16(x) +#define htole16(x) OSSwapHostToLittleInt16(x) +#define be16toh(x) OSSwapBigToHostInt16(x) +#define le16toh(x) OSSwapLittleToHostInt16(x) + +#define htobe32(x) OSSwapHostToBigInt32(x) +#define htole32(x) OSSwapHostToLittleInt32(x) +#define be32toh(x) OSSwapBigToHostInt32(x) +#define le32toh(x) OSSwapLittleToHostInt32(x) + +#define htobe64(x) OSSwapHostToBigInt64(x) +#define htole64(x) OSSwapHostToLittleInt64(x) +#define be64toh(x) OSSwapBigToHostInt64(x) +#define le64toh(x) OSSwapLittleToHostInt64(x) + +#define mempcpy(dest, src, n) ((char *)memcpy(dest, src, n) + (n)) +#else #include +#endif #include #include #include diff --git a/src/Makefile b/src/Makefile index d4b3fe837..7cd13dfc3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -114,7 +114,7 @@ endif endif ifeq ($(UNAME_S),Darwin) - MYLIBS :=-lre2 -lmariadbclient -lpq -lpthread -lm -lz -liconv -lgnutls -lprometheus-cpp-pull -lprometheus-cpp-core -luuid + MYLIBS :=-lre2 -lmariadbclient -lssl -lcrypto -lpthread -lm -lz -liconv -lgnutls -lprometheus-cpp-pull -lprometheus-cpp-core -luuid else CURL_DIR := $(DEPS_PATH)/curl/curl IDIRS += -L$(CURL_DIR)/include @@ -144,6 +144,11 @@ ifeq ($(UNAME_S),Darwin) LIBPROXYSQLAR += $(SQLITE3_LDIR)/sqlite3.o LIBPROXYSQLAR += $(LIBINJECTION_LDIR)/libinjection.a LIBPROXYSQLAR += $(EV_LDIR)/libev.a + LIBPROXYSQLAR += $(LIBSCRAM_LDIR)/libscram.a + LIBPROXYSQLAR += $(LIBUSUAL_LDIR)/libusual.a + LIBPROXYSQLAR += $(POSTGRESQL_PATH)/interfaces/libpq/libpq.a + LIBPROXYSQLAR += $(POSTGRESQL_PATH)/common/libpgcommon.a + LIBPROXYSQLAR += $(POSTGRESQL_PATH)/port/libpgport.a endif LIBPROXYSQLAR += $(CITYHASH_LDIR)/libcityhash.a From d10cdd3db7c25b8d6ef5703d467f43e28cbf0d55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Tue, 20 Jan 2026 22:41:56 +0100 Subject: [PATCH 3/6] Updated macOS build instructions in INSTALL.md and added doc/BUILD-MACOS.md --- INSTALL.md | 11 ++++++++++- doc/BUILD-MACOS.md | 49 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) create mode 100644 doc/BUILD-MACOS.md diff --git a/INSTALL.md b/INSTALL.md index 8d9b17970..33e727340 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -188,7 +188,16 @@ zypper install -y automake bzip2 cmake make gcc-c++ gcc git openssl openssl-deve ### macOS (using Homebrew): ```bash -brew install automake bzip2 cmake make git gpatch gnutls ossp-uuid +brew install automake bzip2 cmake make git gpatch gnutls openssl@3 icu4c pkg-config libiconv zlib +``` + +To compile on macOS, you must set the following environment variables to ensure the build system can find OpenSSL and Homebrew dependencies: + +```bash +export PATH="/opt/homebrew/bin:$PATH" +export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig:$PKG_CONFIG_PATH" +export OPENSSL_ROOT_DIR="/opt/homebrew/opt/openssl@3" +make # or make debug ``` For more details, inspect the docker build images: diff --git a/doc/BUILD-MACOS.md b/doc/BUILD-MACOS.md new file mode 100644 index 000000000..3196c57bb --- /dev/null +++ b/doc/BUILD-MACOS.md @@ -0,0 +1,49 @@ +# Compiling ProxySQL on macOS + +This guide provides step-by-step instructions for compiling ProxySQL from source on macOS (Intel or Apple Silicon) using Homebrew. + +## Prerequisites + +Ensure you have [Homebrew](https://brew.sh/) installed. + +### Install Dependencies + +Run the following command to install the required build tools and libraries: + +```bash +brew install automake bzip2 cmake make git gpatch gnutls openssl@3 icu4c pkg-config libiconv zlib +``` + +## Compilation Steps + +To compile ProxySQL, you must set the following environment variables so the build system can locate OpenSSL and other Homebrew-provided libraries. + +### 1. Set Environment Variables + +```bash +export PATH="/opt/homebrew/bin:$PATH" +export PKG_CONFIG_PATH="/opt/homebrew/opt/openssl@3/lib/pkgconfig:$PKG_CONFIG_PATH" +export OPENSSL_ROOT_DIR="/opt/homebrew/opt/openssl@3" +``` + +### 2. Run the Build + +You can now run the standard build command: + +```bash +make +``` + +Or for a debug build: + +```bash +make debug +``` + +## Troubleshooting + +### Linking Issues +If the linker fails to find `libssl` or `libcrypto`, ensure that `OPENSSL_ROOT_DIR` and `PKG_CONFIG_PATH` are correctly set to point to your Homebrew OpenSSL installation. + +### Missing ICU Headers +The build system is configured to find `icu4c` via Homebrew. If you encounter errors related to ICU, ensure `icu4c` is installed and the Homebrew prefix is correct. From bd16436ea3f5fe1a4a96543479a62bd7549ef067 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 21 Jan 2026 00:56:24 +0100 Subject: [PATCH 4/6] Fix MySQL 8.4 build on macOS with C++20 compatibility patch - Add mysql-8.4.0-clang17.patch to fix AppleClang 17 template strictness errors - Update test/deps/Makefile to automatically apply patch on Darwin - Enforce sequential build (-j1) for MySQL connectors on macOS to prevent race conditions - Patch fixes 9 template keyword errors in MySQL serialization headers --- test/deps/Makefile | 46 ++++++- test/deps/mysql-8.4.0-clang17.patch | 178 ++++++++++++++++++++++++++++ 2 files changed, 221 insertions(+), 3 deletions(-) create mode 100644 test/deps/mysql-8.4.0-clang17.patch diff --git a/test/deps/Makefile b/test/deps/Makefile index 76bf1203f..4c00e2d6e 100644 --- a/test/deps/Makefile +++ b/test/deps/Makefile @@ -3,6 +3,8 @@ PROXYSQL_PATH := $(shell while [ ! -f ./src/proxysql_global.cpp ]; do cd ..; done; pwd) DEPS_PATH := $(PROXYSQL_PATH)/deps +include $(PROXYSQL_PATH)/include/makefiles_vars.mk +include $(PROXYSQL_PATH)/include/makefiles_paths.mk .DEFAULT: default @@ -20,8 +22,16 @@ mariadb-connector-c/mariadb-connector-c/libmariadb/libmariadbclient.a: cd mariadb-connector-c && tar -zxf mariadb-connector-c-*.tar.gz cd mariadb-connector-c/mariadb-connector-c && patch -p0 < ../CMakeLists.txt.patch cd mariadb-connector-c/mariadb-connector-c && patch -p0 < ../ConnectorName.cmake.patch - cd mariadb-connector-c/mariadb-connector-c && cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo +ifeq ($(UNAME_S),Darwin) + cd mariadb-connector-c/mariadb-connector-c && cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DOPENSSL_ROOT_DIR=$(SSL_IDIR) -DOPENSSL_LIBRARIES=$(SSL_LDIR) -DICONV_LIBRARIES=$$(brew --prefix libiconv)/lib -DICONV_INCLUDE=$$(brew --prefix libiconv)/include +else + cd mariadb-connector-c/mariadb-connector-c && cmake . -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_POLICY_VERSION_MINIMUM=3.5 +endif +ifeq ($(UNAME_S),Darwin) + cd mariadb-connector-c/mariadb-connector-c && CC=${CC} CXX=${CXX} ${MAKE} -j1 mariadbclient +else cd mariadb-connector-c/mariadb-connector-c && CC=${CC} CXX=${CXX} ${MAKE} mariadbclient +endif mariadb_client: mariadb-connector-c/mariadb-connector-c/libmariadb/libmariadbclient.a @@ -31,9 +41,25 @@ mysql-connector-c/mysql-boost-5.7.44.tar.gz: mysql-connector-c/mysql-connector-c/libmysql/libmysqlclient.a: mysql-connector-c/mysql-boost-5.7.44.tar.gz cd mysql-connector-c && rm -rf mysql-*/ || true cd mysql-connector-c && tar -zxf mysql-boost-5.7.*.tar.gz +ifeq ($(UNAME_S),Darwin) + cd mysql-connector-c && mysql_dir=$$(ls -1d mysql-5.7.*/) && \ + sed -i '' 's/CMAKE_POLICY(SET CMP0018 OLD)/CMAKE_POLICY(SET CMP0018 NEW)/' $${mysql_dir}CMakeLists.txt && \ + sed -i '' 's/CMAKE_POLICY(SET CMP0022 OLD)/CMAKE_POLICY(SET CMP0022 NEW)/' $${mysql_dir}CMakeLists.txt && \ + sed -i '' 's/CMAKE_POLICY(SET CMP0045 OLD)/CMAKE_POLICY(SET CMP0045 NEW)/' $${mysql_dir}CMakeLists.txt && \ + sed -i '' 's/CMAKE_POLICY(SET CMP0042 OLD)/CMAKE_POLICY(SET CMP0042 NEW)/' $${mysql_dir}CMakeLists.txt && \ + sed -i '' 's/CMAKE_POLICY(SET CMP0075 OLD)/CMAKE_POLICY(SET CMP0075 NEW)/' $${mysql_dir}CMakeLists.txt && \ + sed -i '' 's/# ifndef fdopen/# if !defined(fdopen) \&\& !defined(__APPLE__)/' $${mysql_dir}extra/zlib/zlib-1.2.13/zutil.h + cd mysql-connector-c && ln -fsh $$(ls -1d mysql-5.7.*/) mysql-connector-c + cd mysql-connector-c/mysql-connector-c && cmake . -DWITH_BOOST=./boost -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O0 -ggdb -DNDEBUG -fPIC" -DCMAKE_POLICY_VERSION_MINIMUM=3.5 -DWITH_SSL=$$(brew --prefix openssl@3) -DOPENSSL_ROOT_DIR=$$(brew --prefix openssl@3) +else cd mysql-connector-c && ln -fsT $$(ls -1d mysql-5.7.*/) mysql-connector-c - cd mysql-connector-c/mysql-connector-c && cmake . -DWITH_BOOST=./boost -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O0 -ggdb -DNDEBUG -fPIC" + cd mysql-connector-c/mysql-connector-c && cmake . -DWITH_BOOST=./boost -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O0 -ggdb -DNDEBUG -fPIC" -DCMAKE_POLICY_VERSION_MINIMUM=3.5 +endif +ifeq ($(UNAME_S),Darwin) + cd mysql-connector-c/mysql-connector-c && CC=${CC} CXX=${CXX} ${MAKE} -j1 mysqlclient mysql +else cd mysql-connector-c/mysql-connector-c && CC=${CC} CXX=${CXX} ${MAKE} mysqlclient mysql +endif cd mysql-connector-c/mysql-connector-c && cp archive_output_directory/libmysqlclient.a libmysql/ mysql_client: mysql-connector-c/mysql-connector-c/libmysql/libmysqlclient.a @@ -44,11 +70,25 @@ mysql-connector-c-8.4.0/mysql-8.4.0.tar.gz: mysql-connector-c-8.4.0/mysql-connector-c/libmysql/libmysqlclient.a: mysql-connector-c-8.4.0/mysql-8.4.0.tar.gz cd mysql-connector-c-8.4.0 && rm -rf mysql-*/ || true cd mysql-connector-c-8.4.0 && tar -zxf mysql-*.tar.gz +ifeq ($(UNAME_S),Darwin) + cd mysql-connector-c-8.4.0 && mysql_dir=$$(ls -1d mysql-8.4.*/) && \ + sed -i '' 's/# ifndef fdopen/# if !defined(fdopen) \&\& !defined(__APPLE__)/' $${mysql_dir}extra/zlib/zlib-1.2.13/zutil.h + cd mysql-connector-c-8.4.0 && ln -fsh $$(ls -1d mysql-8.4.*/) mysql-connector-c + cd mysql-connector-c-8.4.0/mysql-connector-c && patch -p0 --batch < ../../mysql-8.4.0-clang17.patch + cd mysql-connector-c-8.4.0/mysql-connector-c && cmake . -DFORCE_INSOURCE_BUILD=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ + -DWITHOUT_SERVER=ON -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./mysql-server/downloads/ -DWITH_UNIT_TESTS=OFF \ + -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O0 -ggdb -DNDEBUG -fPIC" -DWITH_SSL=$$(brew --prefix openssl@3) -DOPENSSL_ROOT_DIR=$$(brew --prefix openssl@3) +else cd mysql-connector-c-8.4.0 && ln -fsT $$(ls -1d mysql-8.4.*/) mysql-connector-c - cd mysql-connector-c-8.4.0/mysql-connector-c && cmake . -DFORCE_INSOURCE_BUILD=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo \ + cd mysql-connector-c-8.4.0/mysql-connector-c && cmake . -DFORCE_INSOURCE_BUILD=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_POLICY_VERSION_MINIMUM=3.5 \ -DWITHOUT_SERVER=ON -DDOWNLOAD_BOOST=1 -DWITH_BOOST=./mysql-server/downloads/ -DWITH_UNIT_TESTS=OFF \ -DCMAKE_CXX_FLAGS_RELWITHDEBINFO="-O0 -ggdb -DNDEBUG -fPIC" +endif +ifeq ($(UNAME_S),Darwin) + cd mysql-connector-c-8.4.0/mysql-connector-c && CC=${CC} CXX=${CXX} ${MAKE} -j1 +else cd mysql-connector-c-8.4.0/mysql-connector-c && CC=${CC} CXX=${CXX} ${MAKE} +endif cd mysql-connector-c-8.4.0/mysql-connector-c && cp archive_output_directory/libmysqlclient.a libmysql/ mysql8_client: mysql-connector-c-8.4.0/mysql-connector-c/libmysql/libmysqlclient.a diff --git a/test/deps/mysql-8.4.0-clang17.patch b/test/deps/mysql-8.4.0-clang17.patch new file mode 100644 index 000000000..f0d8c0dfc --- /dev/null +++ b/test/deps/mysql-8.4.0-clang17.patch @@ -0,0 +1,178 @@ +--- libs/mysql/serialization/archive.h 2024-04-10 08:26:28 ++++ libs/mysql/serialization/archive.h 2026-01-21 00:07:15 +@@ -81,14 +81,15 @@ + /// @note To be implemented in Archive_derived_type + template + static std::size_t get_size(Type &&arg) { +- return Archive_derived_type::template get_size(std::forward(arg)); ++ return Archive_derived_type::template get_size( ++ std::forward(arg)); + } + + /// @brief Returns archive size - size of data written to the archive + /// @return archive size - size of data written to the archive + /// @note To be implemented in Archive_derived_type + inline std::size_t get_size_written() const { +- return Archive_derived_type::template get_size_written(); ++ return Archive_derived_type::get_size_written(); + } + + /// @brief Function returns maximum size of the Type +--- libs/mysql/serialization/serializer_impl.hpp 2024-04-10 08:26:28 ++++ libs/mysql/serialization/serializer_impl.hpp 2026-01-21 00:07:15 +@@ -51,8 +51,8 @@ + Serializer::get_size_field_def( + Field_id_type field_id, + const Field_definition &field_definition) { +- return Serializer_derived_type::template get_size_field_def(field_id, +- field_definition); ++ return Serializer_derived_type::template get_size_field_def< ++ Field_type, field_size_defined>(field_id, field_definition); + } + + template +@@ -61,8 +61,8 @@ + Serializer::get_size_serializable( + Field_id_type field_id, const Serializable_concrete_type &serializable, + bool skip_id) { +- return Serializer_derived_type::template get_size_serializable( +- field_id, serializable, skip_id); ++ return Serializer_derived_type::template get_size_serializable< ++ Serializable_concrete_type>(field_id, serializable, skip_id); + } + + template +@@ -83,8 +83,8 @@ + + template + template +-Serializer +- &Serializer::operator>>(T &arg) { ++Serializer & ++Serializer::operator>>(T &arg) { + Field_id_type field_id = serialization_format_version; + // passing 0 as serializable_end_pos + decode_serializable(m_level, field_id, 0, arg, false); +@@ -101,12 +101,11 @@ + void Serializer:: + encode_serializable_fields(const Serializable_type &serializable, + Level_type level) { +- auto process_serializable = +- [ this, level ](const auto &field, auto field_id) -> auto { ++ auto process_serializable = [this, level](const auto &field, ++ auto field_id) -> auto { + this->encode_serializable(level, field_id, field, false); + }; +- auto process_field = +- [ this, level ](const auto &field, auto field_id) -> auto { ++ auto process_field = [this, level](const auto &field, auto field_id) -> auto { + this->encode_field(level, field_id, field); + ++field_id; + }; +@@ -139,13 +138,13 @@ + decode_serializable_fields(Serializable_type &serializable, + Level_type level, + std::size_t serializable_end_pos) { +- auto process_serializable = [ this, level, serializable_end_pos ]( +- auto &field, auto field_id) -> auto { ++ auto process_serializable = [this, level, serializable_end_pos]( ++ auto &field, auto field_id) -> auto { + this->decode_serializable(level, field_id, serializable_end_pos, field, + false); + }; +- auto process_field = [ this, level, serializable_end_pos ]( +- auto &field, auto field_id) -> auto { ++ auto process_field = [this, level, serializable_end_pos]( ++ auto &field, auto field_id) -> auto { + this->decode_field(level, field_id, serializable_end_pos, field); + + ++field_id; +--- libs/mysql/serialization/serializer_default_impl.hpp 2024-04-10 08:26:28 ++++ libs/mysql/serialization/serializer_default_impl.hpp 2026-01-21 00:11:38 +@@ -205,8 +205,8 @@ + template + void Serializer_default::encode_field( + const Field_type &field, Serializer_array_tag) { +- using value_type = std::remove_reference_t()))>; ++ using value_type = std::remove_reference_t()))>; + for (const auto &internal_field : field) { + // we use default size for internal fields (0) + encode_field(internal_field); +@@ -219,8 +219,8 @@ + template + void Serializer_default::decode_field( + Field_type &field, Serializer_array_tag) { +- using value_type = std::remove_reference_t()))>; ++ using value_type = std::remove_reference_t()))>; + for (auto &internal_field : field) { + // we use default size for internal fields (0) + decode_field(internal_field); +@@ -233,7 +233,8 @@ + template + std::size_t Serializer_default::get_field_size( + const Field_type &field) { +- return Archive_concrete_type::template get_size( ++ return Archive_concrete_type::template get_size< ++ Field_wrapper>( + Field_wrapper(field)); + } + +@@ -304,8 +305,8 @@ + std::size_t Serializer_default::get_field_size( + const Field_type &field, Serializer_array_tag) { + std::size_t field_size = 0; +- using value_type = std::remove_reference_t()))>; ++ using value_type = std::remove_reference_t()))>; + for (const auto &internal_field : field) { + field_size += get_field_size(internal_field); + } +@@ -397,7 +398,7 @@ + } + }; + auto func_f = [&last_non_ignorable_field_id]( +- const auto &field, auto processed_field_id) -> auto { ++ const auto &field, auto processed_field_id) -> auto { + if (field.run_encode_predicate() && field.is_field_ignorable() == false) { + last_non_ignorable_field_id = processed_field_id + 1; + } +@@ -473,8 +474,8 @@ + std::size_t calculated_size = 0; + bool is_provided = field_definition.run_encode_predicate(); + if (is_provided) { +- auto size_id_type = Archive_concrete_type::template get_size( +- create_varlen_field_wrapper(field_id)); ++ auto size_id_type = Archive_concrete_type::template get_size< ++ Field_wrapper>(create_varlen_field_wrapper(field_id)); + calculated_size = get_field_size( + field_definition.get_ref()) + + size_id_type; +@@ -489,18 +490,19 @@ + bool skip_id) { + std::size_t serializable_overhead_type = 0; + if (skip_id == false) { +- serializable_overhead_type = Archive_concrete_type::template get_size( +- create_varlen_field_wrapper(field_id)); ++ serializable_overhead_type = Archive_concrete_type::template get_size< ++ Field_wrapper>(create_varlen_field_wrapper(field_id)); + } + auto serializable_size = serializable.template get_size_internal(); +- auto serializable_overhead_size = Archive_concrete_type::template get_size( ++ auto serializable_overhead_size = Archive_concrete_type::template get_size< ++ Field_wrapper>( + create_varlen_field_wrapper(serializable_size)); + + Field_id_type last_non_ignorable_field_id = + find_last_non_ignorable_field_id(serializable); + + auto serializable_overhead_last_non_ignorable_field_id = +- Archive_concrete_type::template get_size( ++ Archive_concrete_type::template get_size>( + create_varlen_field_wrapper(last_non_ignorable_field_id)); + return serializable_overhead_type + serializable_overhead_size + + serializable_overhead_last_non_ignorable_field_id + serializable_size; From 62bc15fd886a8c37fbc883b90b61c9fae0d529f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C3=A9=20Canna=C3=B2?= Date: Wed, 21 Jan 2026 01:53:07 +0100 Subject: [PATCH 5/6] Improve macOS build system OpenSSL detection and documentation - Support OPENSSL_ROOT_DIR environment variable for better Homebrew integration - Fix OpenSSL library path on Darwin (use lib instead of lib64) - Improve OpenSSL version extraction using grep/sed for better compatibility - Add TAP test build instructions to BUILD-MACOS.md --- common_mk/openssl_flags.mk | 12 ++++++++++++ common_mk/openssl_version_check.mk | 4 ++-- doc/BUILD-MACOS.md | 14 ++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/common_mk/openssl_flags.mk b/common_mk/openssl_flags.mk index 886ac4cdd..c6c8b2dc7 100644 --- a/common_mk/openssl_flags.mk +++ b/common_mk/openssl_flags.mk @@ -10,6 +10,14 @@ endif # Use pkg-config to get the compiler and linker flags for OpenSSL if CUSTOM_OPENSSL_PATH is not set +ifeq ($(CUSTOM_OPENSSL_PATH),) + ifeq ($(UNAME_S),Darwin) + ifneq ($(OPENSSL_ROOT_DIR),) + CUSTOM_OPENSSL_PATH := $(OPENSSL_ROOT_DIR) + endif + endif +endif + ifeq ($(CUSTOM_OPENSSL_PATH),) ifeq ($(OPENSSL_PACKAGE),openssl3) ifeq ($(UNAME_S),Darwin) @@ -49,7 +57,11 @@ endif endif else SSL_IDIR := $(CUSTOM_OPENSSL_PATH)/include +ifeq ($(UNAME_S),Darwin) + SSL_LDIR := $(CUSTOM_OPENSSL_PATH)/lib +else SSL_LDIR := $(CUSTOM_OPENSSL_PATH)/lib64 +endif ifeq ($(UNAME_S),Darwin) LIB_SSL_PATH := $(shell find $(SSL_LDIR) -name "libssl.dylib" 2>/dev/null | head -n 1) ifeq ($(LIB_SSL_PATH),) diff --git a/common_mk/openssl_version_check.mk b/common_mk/openssl_version_check.mk index 7a1785163..885c0c029 100644 --- a/common_mk/openssl_version_check.mk +++ b/common_mk/openssl_version_check.mk @@ -10,7 +10,7 @@ ifeq ($(UNAME_S),Darwin) echo "OpenSSL header file not found at $$header_path"; \ exit 1; \ fi; \ - version_number=$$(awk '/# define OPENSSL_VERSION_STR/ {print $$3}' $$header_path | tr -d '"'); \ + version_number=$$(grep "# *define OPENSSL_VERSION_STR" $$header_path | sed -E 's/.*"([^"]+)".*/\1/'); \ if [ -z "$$version_number" ]; then \ echo "Failed to extract OPENSSL_VERSION_STR from $$header_path"; \ exit 1; \ @@ -49,7 +49,7 @@ else echo "OpenSSL header file not found at $$header_path"; \ exit 1; \ fi; \ - version_number=$$(awk '/# define OPENSSL_VERSION_STR/ {print $$3}' $$header_path | tr -d '"'); \ + version_number=$$(grep "# *define OPENSSL_VERSION_STR" $$header_path | sed -E 's/.*"([^"]+)".*/\1/'); \ if [ -z "$$version_number" ]; then \ echo "Failed to extract OPENSSL_VERSION_STR from $$header_path"; \ exit 1; \ diff --git a/doc/BUILD-MACOS.md b/doc/BUILD-MACOS.md index 3196c57bb..ce8012122 100644 --- a/doc/BUILD-MACOS.md +++ b/doc/BUILD-MACOS.md @@ -47,3 +47,17 @@ If the linker fails to find `libssl` or `libcrypto`, ensure that `OPENSSL_ROOT_D ### Missing ICU Headers The build system is configured to find `icu4c` via Homebrew. If you encounter errors related to ICU, ensure `icu4c` is installed and the Homebrew prefix is correct. + +### Building TAP Tests (Optional) + +If you wish to run the TAP tests, you need to build the test dependencies first: + +```bash +export OPENSSL_ROOT_DIR=$(brew --prefix openssl@3) +make build_tap_test_debug +``` + +This will automatically: +1. Build the main ProxySQL debug binary. +2. Download and build MariaDB and MySQL connectors (patched for macOS compatibility). +3. Build the TAP test framework. From 0102965838f5a4ef1ee1de26442e399a5cbbb7a4 Mon Sep 17 00:00:00 2001 From: Rene Cannao Date: Fri, 6 Feb 2026 13:11:47 +0000 Subject: [PATCH 6/6] Convert PostgreSQL patches to unified diff format - Convert patch format from git-style (diff --git) to unified diff (diff -ruN) - Update line numbers in patch contexts for PostgreSQL compatibility - This makes the patches more portable and easier to apply across different environments --- deps/postgresql/get_result_from_pgconn.patch | 27 +++++----- deps/postgresql/handle_row_data.patch | 55 +++++++++----------- 2 files changed, 37 insertions(+), 45 deletions(-) diff --git a/deps/postgresql/get_result_from_pgconn.patch b/deps/postgresql/get_result_from_pgconn.patch index 6bb37bca1..51fc99050 100644 --- a/deps/postgresql/get_result_from_pgconn.patch +++ b/deps/postgresql/get_result_from_pgconn.patch @@ -1,10 +1,9 @@ -diff --git src/interfaces/libpq/fe-exec.c src/interfaces/libpq/fe-exec.c -index fa9d6aad..cd5cd23d 100644 ---- src/interfaces/libpq/fe-exec.c -+++ src/interfaces/libpq/fe-exec.c -@@ -4467,3 +4467,20 @@ PQunescapeBytea(const unsigned char *strtext, size_t *retbuflen) - *retbuflen = buflen; - return tmpbuf; +diff -ruN ../tmp/src/interfaces/libpq/fe-exec.c ./src/interfaces/libpq/fe-exec.c +--- ../tmp/src/interfaces/libpq/fe-exec.c 2025-08-11 21:06:43.000000000 +0000 ++++ ./src/interfaces/libpq/fe-exec.c 2026-02-06 13:03:06.060890335 +0000 +@@ -4528,3 +4528,20 @@ + *retbuflen = buflen; + return tmpbuf; } + +/* @@ -23,18 +22,16 @@ index fa9d6aad..cd5cd23d 100644 + return conn->result; +} + -diff --git src/interfaces/libpq/libpq-fe.h src/interfaces/libpq/libpq-fe.h -index 7476dbe0..472d0083 100644 ---- src/interfaces/libpq/libpq-fe.h -+++ src/interfaces/libpq/libpq-fe.h -@@ -668,6 +668,9 @@ extern PQsslKeyPassHook_OpenSSL_type PQgetSSLKeyPassHook_OpenSSL(void); +diff -ruN ../tmp/src/interfaces/libpq/libpq-fe.h ./src/interfaces/libpq/libpq-fe.h +--- ../tmp/src/interfaces/libpq/libpq-fe.h 2025-08-11 21:06:43.000000000 +0000 ++++ ./src/interfaces/libpq/libpq-fe.h 2026-02-06 13:03:06.060890335 +0000 +@@ -668,6 +668,9 @@ extern void PQsetSSLKeyPassHook_OpenSSL(PQsslKeyPassHook_OpenSSL_type hook); - extern int PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn); - + extern int PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn); + +/* Get PGresult directly from PGconn. WARNING: DO NOT RELEASE THIS RESULT */ +extern const PGresult *PQgetResultFromPGconn(PGconn *conn); + #ifdef __cplusplus } #endif - diff --git a/deps/postgresql/handle_row_data.patch b/deps/postgresql/handle_row_data.patch index 59c8e60a7..5a380c83f 100644 --- a/deps/postgresql/handle_row_data.patch +++ b/deps/postgresql/handle_row_data.patch @@ -1,8 +1,7 @@ -diff --git src/interfaces/libpq/fe-exec.c src/interfaces/libpq/fe-exec.c -index 2265ab5..56883ec 100644 ---- src/interfaces/libpq/fe-exec.c -+++ src/interfaces/libpq/fe-exec.c -@@ -4484,3 +4484,9 @@ PQgetResultFromPGconn(PGconn *conn) +diff -ruN ../tmp/src/interfaces/libpq/fe-exec.c ./src/interfaces/libpq/fe-exec.c +--- ../tmp/src/interfaces/libpq/fe-exec.c 2026-02-06 13:03:06.060890335 +0000 ++++ ./src/interfaces/libpq/fe-exec.c 2026-02-06 13:05:13.935067795 +0000 +@@ -4545,3 +4545,9 @@ return conn->result; } @@ -12,11 +11,10 @@ index 2265ab5..56883ec 100644 + return psHandleRowData(conn, is_first_packet, result); +} + -diff --git src/interfaces/libpq/fe-misc.c src/interfaces/libpq/fe-misc.c -index 488f7d6..65beb87 100644 ---- src/interfaces/libpq/fe-misc.c -+++ src/interfaces/libpq/fe-misc.c -@@ -1344,3 +1344,39 @@ libpq_append_conn_error(PGconn *conn, const char *fmt,...) +diff -ruN ../tmp/src/interfaces/libpq/fe-misc.c ./src/interfaces/libpq/fe-misc.c +--- ../tmp/src/interfaces/libpq/fe-misc.c 2025-08-11 21:06:43.000000000 +0000 ++++ ./src/interfaces/libpq/fe-misc.c 2026-02-06 13:05:13.936067804 +0000 +@@ -1367,3 +1367,39 @@ appendPQExpBufferChar(&conn->errorMessage, '\n'); } @@ -56,11 +54,10 @@ index 488f7d6..65beb87 100644 + *result = (int) pg_ntoh32(tmp4); + return 0; +} -diff --git src/interfaces/libpq/fe-protocol3.c src/interfaces/libpq/fe-protocol3.c -index 9c4aa7e..de0746c 100644 ---- src/interfaces/libpq/fe-protocol3.c -+++ src/interfaces/libpq/fe-protocol3.c -@@ -2299,3 +2299,109 @@ build_startup_packet(const PGconn *conn, char *packet, +diff -ruN ../tmp/src/interfaces/libpq/fe-protocol3.c ./src/interfaces/libpq/fe-protocol3.c +--- ../tmp/src/interfaces/libpq/fe-protocol3.c 2025-08-11 21:06:43.000000000 +0000 ++++ ./src/interfaces/libpq/fe-protocol3.c 2026-02-06 13:05:13.936067804 +0000 +@@ -2299,3 +2299,109 @@ return packet_len; } @@ -170,15 +167,13 @@ index 9c4aa7e..de0746c 100644 + return 1; +} + -diff --git src/interfaces/libpq/libpq-fe.h src/interfaces/libpq/libpq-fe.h -index c5170d1..3e3cc34 100644 ---- src/interfaces/libpq/libpq-fe.h -+++ src/interfaces/libpq/libpq-fe.h -@@ -269,6 +269,18 @@ typedef struct pgresAttDesc - int atttypmod; /* type-specific modifier info */ +diff -ruN ../tmp/src/interfaces/libpq/libpq-fe.h ./src/interfaces/libpq/libpq-fe.h +--- ../tmp/src/interfaces/libpq/libpq-fe.h 2026-02-06 13:03:06.060890335 +0000 ++++ ./src/interfaces/libpq/libpq-fe.h 2026-02-06 13:05:13.936067804 +0000 +@@ -270,6 +270,18 @@ } PGresAttDesc; -+/* ---------------- + /* ---------------- + * PSresult -- + * ---------------- + */ @@ -190,10 +185,11 @@ index c5170d1..3e3cc34 100644 + //int fieldcount; +} PSresult; + - /* ---------------- ++/* ---------------- * Exported functions of libpq * ---------------- -@@ -671,6 +683,9 @@ extern int PQdefaultSSLKeyPassHook_OpenSSL(char *buf, int size, PGconn *conn); + */ +@@ -671,6 +683,9 @@ /* Get PGresult directly from PGconn. WARNING: DO NOT RELEASE THIS RESULT */ extern const PGresult *PQgetResultFromPGconn(PGconn *conn); @@ -203,11 +199,10 @@ index c5170d1..3e3cc34 100644 #ifdef __cplusplus } #endif -diff --git src/interfaces/libpq/libpq-int.h src/interfaces/libpq/libpq-int.h -index a951f49..e1df8b5 100644 ---- src/interfaces/libpq/libpq-int.h -+++ src/interfaces/libpq/libpq-int.h -@@ -727,6 +727,11 @@ extern PGresult *pqFunctionCall3(PGconn *conn, Oid fnid, +diff -ruN ../tmp/src/interfaces/libpq/libpq-int.h ./src/interfaces/libpq/libpq-int.h +--- ../tmp/src/interfaces/libpq/libpq-int.h 2025-08-11 21:06:43.000000000 +0000 ++++ ./src/interfaces/libpq/libpq-int.h 2026-02-06 13:05:13.936067804 +0000 +@@ -728,6 +728,11 @@ int result_is_int, const PQArgBlock *args, int nargs); @@ -219,7 +214,7 @@ index a951f49..e1df8b5 100644 /* === in fe-misc.c === */ /* -@@ -756,6 +761,13 @@ extern int pqWaitTimed(int forRead, int forWrite, PGconn *conn, +@@ -757,6 +762,13 @@ extern int pqReadReady(PGconn *conn); extern int pqWriteReady(PGconn *conn);