Skip to content

Fix macOS compilation and add static zstd linking#5465

Merged
renecannao merged 4 commits intov3.0from
v3.0-mac260320
Mar 20, 2026
Merged

Fix macOS compilation and add static zstd linking#5465
renecannao merged 4 commits intov3.0from
v3.0-mac260320

Conversation

@renecannao
Copy link
Copy Markdown
Contributor

@renecannao renecannao commented Mar 20, 2026

Summary

This PR fixes compilation issues on macOS and adds static linking for the zstd compression library, eliminating runtime dependencies on Homebrew/system zstd.

Fixes #5462

Changes

1. Fix macOS Compilation Issues (88be144)

Problem: ProxySQL failed to compile on macOS due to:

  • Missing include paths for Homebrew-installed headers (zstd, etc.)
  • Invalid pthread_t cast on macOS where pthread_t is a pointer type (_opaque_pthread_t *), not an integral type like on Linux

Solution:

  • Added -I/opt/homebrew/include to Darwin-specific include paths in src/Makefile and lib/Makefile
  • Fixed pthread_t cast in lib/log_utils.cpp using reinterpret_cast<uintptr_t>

2. Add Static Zstd Linking (3f1b0a1)

Problem: zstd was dynamically linked from Homebrew on macOS, creating a runtime dependency and potential compatibility issues.

Solution:

  • Added zstd v1.5.7 as a static dependency in deps/zstd/
  • Added zstd build rules to deps/Makefile
  • Added ZSTD_PATH, ZSTD_IDIR, ZSTD_LDIR to include/makefiles_paths.mk
  • Added zstd include path to lib/Makefile and src/Makefile
  • Linked zstd statically in LIBPROXYSQLAR for all platforms
  • Removed -lzstd from dynamic linking flags
  • Replaced clickhouse-cpp bundled zstd with our static zstd

3. Documentation (df97ae9)

  • Added deps/zstd/README.md documenting source, version, and usage
  • Added comments in deps/Makefile for zstd build rule
  • Added comments in include/makefiles_paths.mk for ZSTD paths
  • Updated INSTALL.md to note zstd is bundled and statically linked

4. Cleanup (9fd4bcf)

  • Added zstd to cleanall target in deps/Makefile
  • Added deps/zstd/zstd-*/ to .gitignore

Files Changed

File Change
.gitignore Add zstd extracted sources
INSTALL.md Note zstd is bundled
deps/Makefile Add zstd build rules and cleanup
deps/zstd/README.md New documentation file
deps/zstd/zstd Symlink to extracted source
deps/zstd/zstd-1.5.7.tar.gz Zstd source tarball
include/makefiles_paths.mk Add ZSTD_* paths
lib/Makefile Add zstd include path, Darwin paths
lib/log_utils.cpp Fix pthread_t cast for macOS
src/Makefile Add zstd include path, static linking, remove dynamic -lzstd

Benefits

  1. No runtime zstd dependency - Users don't need to install zstd via Homebrew
  2. Consistent behavior - Same zstd version across all platforms
  3. Easier distribution - Binary works without external dependencies
  4. Cross-platform - Works on Linux, macOS, and FreeBSD

Testing

Tested on:

  • macOS Sequoia (Darwin 25.3.0) - Apple Silicon (M1)
  • Homebrew OpenSSL 3.6.1

Before (dynamic linking)

otool -L src/proxysql | grep zstd
/opt/homebrew/opt/zstd/lib/libzstd.1.dylib

After (static linking)

otool -L src/proxysql | grep zstd
(no output - zstd is statically linked)

Build Instructions

macOS

export PATH="/opt/homebrew/bin:$PATH"
make build_deps && make

Linux

make build_deps && make

Summary by CodeRabbit

  • Documentation

    • Clarified that Zstandard compression library is already included with ProxySQL and requires no separate installation on any platform.
  • Chores

    • Integrated Zstandard compression library as a vendored dependency to support compressed protocol features.

- Add Homebrew include paths for zstd headers on macOS
- Fix pthread_t cast on macOS where it's a pointer type

On macOS, pthread_t is defined as _opaque_pthread_t * (a pointer),
unlike Linux where it's an integral type. Use reinterpret_cast<uintptr_t>
for proper conversion.

Related: #5462
- Add zstd v1.5.7 as a static dependency in deps/
- Add zstd build rules to deps/Makefile
- Add ZSTD_PATH, ZSTD_IDIR, ZSTD_LDIR to makefiles_paths.mk
- Add zstd include path to lib/Makefile and src/Makefile
- Link zstd statically in LIBPROXYSQLAR for all platforms
- Remove -lzstd from dynamic linking flags (Linux and macOS)
- Replace clickhouse-cpp bundled zstd with our static zstd

This eliminates the runtime dependency on system/Homebrew zstd
and ensures consistent behavior across platforms.

Related: #5462
- Add README.md to deps/zstd documenting source and usage
- Add comments in deps/Makefile for zstd build rule
- Add comments in include/makefiles_paths.mk for ZSTD paths
- Update INSTALL.md to note zstd is bundled and statically linked

Related: #5462
- Add zstd cleanup to deps/Makefile cleanall target
- Add deps/zstd/zstd-*/ to .gitignore for extracted sources
Copilot AI review requested due to automatic review settings March 20, 2026 20:25
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

📝 Walkthrough

Walkthrough

The pull request introduces zstd as a vendored dependency to ProxySQL with corresponding build infrastructure. Changes include adding a .gitignore pattern for zstd build artifacts, creating deps/Makefile rules to download and compile libzstd.a, adding zstd path variables to the build system, updating compiler include and linker library directories across platforms, and fixing a macOS-specific pthread_t casting incompatibility in the logging module.

Changes

Cohort / File(s) Summary
Versioning & Documentation
.gitignore, INSTALL.md
Added zstd directory ignore pattern; clarified that zstd is statically linked and pre-included with ProxySQL.
Zstd Vendoring
deps/Makefile, deps/zstd/README.md, deps/zstd/zstd
Introduced zstd build target with download/extract/compile rules for libzstd.a; added vendor documentation specifying version 1.5.7, dual licensing, and usage in MySQL/PostgreSQL compressed protocols.
Build System Integration
include/makefiles_paths.mk, src/Makefile, lib/Makefile
Added ZSTD_PATH, ZSTD_IDIR, and ZSTD_LDIR variables; updated compiler include paths with -I$(ZSTD_IDIR) and added macOS Homebrew paths (-I/opt/homebrew/include, -L/opt/homebrew/lib); replaced dynamic -lzstd linking with static $(ZSTD_LDIR)/libzstd.a in archive; removed bundled ClickHouse zstd reference.
Source Code
lib/log_utils.cpp
Fixed pthread_t cast for macOS compatibility by using reinterpret_cast<uintptr_t> instead of direct static_cast<unsigned>, since pthread_t is pointer-typed on macOS.

Poem

🐰 A curious rabbit unpacks zstd's way,
Bundling compression for Darwin's own day,
From Homebrew paths to the Makefile's care,
pthread_t now fixed—no more casting nightmare!

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Fix macOS compilation and add static zstd linking' clearly and concisely summarizes the main changes: addressing macOS compilation issues and implementing static zstd dependency bundling.
Linked Issues check ✅ Passed The PR fully addresses both objectives from #5462: adding Homebrew include paths to Darwin sections in Makefiles [src/Makefile, lib/Makefile] and fixing the pthread_t cast using reinterpret_cast<uintptr_t> in lib/log_utils.cpp.
Out of Scope Changes check ✅ Passed All changes are directly related to the stated objectives: macOS compilation fixes, static zstd bundling and integration, documentation updates, and build system cleanup. No unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch v3.0-mac260320

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves ProxySQL's build process and cross-platform compatibility by fixing macOS-specific compilation errors and transitioning to static linking for the zstd compression library. It also lays foundational work for future AI-driven capabilities through extensive new documentation and a Retrieval-Augmented Generation (RAG) Proof of Concept, alongside general updates to the project's changelog and contributing guidelines.

Highlights

  • macOS Compilation Fixes: Resolved compilation issues on macOS by adding necessary include paths for Homebrew-installed headers and correcting pthread_t casting in lib/log_utils.cpp.
  • Static Zstd Linking: Integrated the zstd compression library (v1.5.7) as a static dependency, eliminating runtime reliance on external zstd installations and ensuring consistent behavior across platforms.
  • Build System Enhancements: Updated the main Makefile with new versioning logic, introduced feature flags for different release tiers (v3.1.x, v4.0.x AI/MCP), and enforced C++17 as the minimum standard.
  • Comprehensive Documentation Additions: Added extensive new documentation covering AI/RAG features, macOS build instructions, and a detailed release notes generation workflow.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: .github/workflows/** (23)
    • .github/workflows/CI-3p-aiomysql.yml
    • .github/workflows/CI-3p-django-framework.yml
    • .github/workflows/CI-3p-laravel-framework.yml
    • .github/workflows/CI-3p-mariadb-connector-c.yml
    • .github/workflows/CI-3p-mysql-connector-j.yml
    • .github/workflows/CI-3p-pgjdbc.yml
    • .github/workflows/CI-3p-php-pdo-mysql.yml
    • .github/workflows/CI-3p-php-pdo-pgsql.yml
    • .github/workflows/CI-3p-postgresql.yml
    • .github/workflows/CI-3p-sqlalchemy.yml
    • .github/workflows/CI-basictests.yml
    • .github/workflows/CI-builds.yml
    • .github/workflows/CI-codeql.yml
    • .github/workflows/CI-maketest.yml
    • .github/workflows/CI-package-build.yml
    • .github/workflows/CI-repltests.yml
    • .github/workflows/CI-selftests.yml
    • .github/workflows/CI-shuntest.yml
    • .github/workflows/CI-taptests-asan.yml
    • .github/workflows/CI-taptests-groups.yml
    • .github/workflows/CI-taptests-ssl.yml
    • .github/workflows/CI-taptests.yml
    • .github/workflows/CI-trigger.yml
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR aims to fix macOS compilation issues and remove runtime zstd dependencies by bundling and statically linking zstd, while also including broad dependency, CI, and documentation updates.

Changes:

  • Add Homebrew include paths / macOS-specific fixes and introduce bundled static zstd.
  • Extend build tooling (OpenSSL detection/flags) and update several vendored dependency pins/patches.
  • Add/refresh substantial documentation and CI workflow orchestration.

Reviewed changes

Copilot reviewed 107 out of 1006 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
doc/LLM_Bridge/TESTING.md Adds detailed NL2SQL testing guide documentation
doc/BUILD-MACOS.md Adds macOS build instructions via Homebrew
doc/ANOMALY_DETECTION/README.md Adds anomaly detection documentation
doc/AI-DOCUMENTATION-FRAMEWORK.md Adds framework for AI-generated documentation standards
deps/zstd/zstd Adds zstd version pointer/symlink entry
deps/zstd/README.md Documents bundled zstd source/version/build
deps/sqlite3/throw.patch Updates sqlite patch offsets / changes toupper declaration patching
deps/sqlite3/sqlite3_pass_exts.patch Updates sqlite patch offsets
deps/sqlite3/sqlite3.c-multiplication-overflow.patch Removes sqlite overflow patch
deps/sqlite3/sqlite3 Updates sqlite amalgamation version pointer
deps/sqlite3/sqlite-vec-source/sqlite-vec.h.tmpl Adds sqlite-vec header template
deps/sqlite3/sqlite-vec-source/sqlite-vec.h Adds generated sqlite-vec header
deps/sqlite3/sqlite-vec-source/README.md Adds sqlite-vec integration documentation
deps/sqlite3/from_unixtime.patch Updates sqlite from_unixtime patch metadata/offsets
deps/sqlite3/README.md Adds ProxySQL sqlite-vec integration overview
deps/postgresql/pqsendpipelinesync.patch Adds libpq pipeline sync API patch
deps/postgresql/postgresql Adds PostgreSQL version pointer
deps/postgresql/handle_row_data.patch Adds ProxySQL-specific lightweight libpq row handler patches
deps/postgresql/get_result_from_pgconn.patch Adds helper to access PGresult from PGconn
deps/postgresql/fmt_err_msg.patch Adds formatted error verbosity modes to psql/libpq
deps/postgresql/bind_fmt_text.patch Adjusts libpq text parameter length handling
deps/mariadb-client-library/zutil.h.patch Removes custom fdopen override patching
deps/mariadb-client-library/zutil.c.patch Modernizes zlib function prototypes for C compilers
deps/mariadb-client-library/mariadb_lib.c.metadata_column_check.patch Adds integrity check for metadata column-count packet
deps/mariadb-client-library/bool_keyword.patch Renames bool typedef to bbool in MariaDB connector headers/tests
deps/libusual/libusual Adds libusual version pointer
deps/libssl/verify-bio_st-match.sh Removes verification script
deps/libssl/openssl Removes OpenSSL version pointer
deps/libssl/curve448.c-multiplication-overflow.patch Removes OpenSSL overflow patch
deps/libssl/a_time.c-multiplication-overflow.patch Removes OpenSSL overflow patch
deps/libssl/README.md Notes OpenSSL linking behavior change
deps/libscram/scram.c.diff Switches strtok to strtok_r in scram diff
deps/libscram/include/scram.h Adds vendored scram header
deps/libscram/include/scram-internal.h Adds scram internal typedef/header helpers
deps/libscram/Makefile Adds standalone build Makefile for libscram
deps/libmicrohttpd/libmicrohttpd Updates libmicrohttpd version pointer
deps/libmicrohttpd/connection.c-snprintf-overflow.patch Removes libmicrohttpd overflow patch
deps/libconfig/libconfig Updates libconfig version pointer
deps/curl/curl Updates curl version pointer
deps/coredumper/includes.patch Removes coredumper includes patch
deps/coredumper/coredumper Updates coredumper version pointer
deps/clickhouse-cpp/wire_format.patch Removes clickhouse include patch
deps/clickhouse-cpp/clickhouse-cpp Updates clickhouse-cpp version pointer
common_mk/openssl_version_check.mk Adds OpenSSL version checking target logic
common_mk/openssl_flags.mk Adds OpenSSL include/lib path detection logic
RELEASE_NOTES_WORKFLOW.md Adds release notes generation workflow documentation
README.md Adds TOC + updates install links/examples + PGSQL admin examples
RAG_POC/sql-examples.md Adds SQL examples for RAG index querying
RAG_POC/schema.sql Adds SQLite schema for RAG PoC
RAG_POC/sample_sqlite.sql Adds sample SQLite config for ingestion testing
RAG_POC/sample_mysql.sql Adds sample MySQL dataset for ingestion testing
RAG_POC/rag_system_prompt.md Adds agent system prompt for RAG orchestrator
RAG_POC/mcp-tools.md Defines MCP tool contracts for RAG querying
RAG_POC/embeddings-design.md Adds embeddings design blueprint
RAG_POC/architecture-runtime-retrieval.md Adds runtime retrieval architecture blueprint
RAG_POC/architecture-data-model.md Adds data model/ingestion architecture blueprint
RAG_POC/Makefile Adds PoC build Makefile for rag_ingest
RAG_POC/EMBEDDING_TEST_PLAN.md Adds embedding test plan documentation
RAG_IMPLEMENTATION_SUMMARY.md Adds RAG implementation summary document
RAG_IMPLEMENTATION_COMPLETE.md Adds RAG implementation completion document
RAG_FILE_SUMMARY.md Adds RAG file inventory summary document
RAG_COMPLETION_SUMMARY.md Adds RAG completion summary document
ProxySQL-3.0.4-Release-Notes.md Adds ProxySQL 3.0.4 release notes document
INSTALL.md Updates installation instructions + adds macOS section + repo URLs
CONTRIBUTING.md Adds contributing guide
.github/workflows/CI-trigger.yml Adds CI trigger workflow orchestration entrypoint
.github/workflows/CI-taptests.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-taptests-ssl.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-taptests-groups.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-taptests-asan.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-shuntest.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-selftests.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-repltests.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-package-build.yml Updates branch patterns + adds trigger input
.github/workflows/CI-maketest.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-codeql.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-builds.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-basictests.yml Refactors workflow triggering via workflow_run
.github/workflows/CI-3p-sqlalchemy.yml Splits mysql/mariadb/pgsql jobs + workflow_run
.github/workflows/CI-3p-postgresql.yml Adds new third-party PostgreSQL workflow
.github/workflows/CI-3p-php-pdo-pgsql.yml Adds new third-party PHP PDO PGSQL workflow
.github/workflows/CI-3p-php-pdo-mysql.yml Splits mysql/mariadb jobs + workflow_run
.github/workflows/CI-3p-pgjdbc.yml Adds new pgjdbc workflow
.github/workflows/CI-3p-mysql-connector-j.yml Splits mysql/mariadb jobs + workflow_run
.github/workflows/CI-3p-mariadb-connector-c.yml Splits mysql/mariadb jobs + workflow_run
.github/workflows/CI-3p-laravel-framework.yml Splits mysql/mariadb/pgsql jobs + workflow_run
.github/workflows/CI-3p-django-framework.yml Splits mysql/mariadb/pgsql jobs + workflow_run
.github/workflows/CI-3p-aiomysql.yml Adds new aiomysql workflow with mysql/mariadb jobs
.github/ISSUE_TEMPLATE/bug_report.md Adds bug report issue template
.aider.conf.yml Adds repository-local aider configuration
Comments suppressed due to low confidence (1)

deps/postgresql/pqsendpipelinesync.patch:1

  • The header comment says “without flushing the send buffer”, but the implementation calls pqPipelineFlush(conn). Either update the comment to reflect the actual behavior (flushes conditionally in pipeline mode), or change the implementation if true “no flush” semantics are required by callers.
diff --git src/interfaces/libpq/fe-exec.c src/interfaces/libpq/fe-exec.c

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

echo "OpenSSL header file not found at $$header_path"; \
exit 1; \
fi; \
version_number=$$(grep "# *define OPENSSL_VERSION_STR" $$header_path | sed -E 's/.*"([^"]+)".*/\1/'); \
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPENSSL_VERSION_STR is typically a string like "OpenSSL 3.6.1 11 Feb 2025", so splitting on . yields a non-numeric major (e.g. "OpenSSL 3"), breaking numeric comparisons and potentially failing valid builds. Prefer parsing OPENSSL_VERSION_NUMBER from opensslv.h (hex) or extract only the numeric X.Y.Z portion via a regex before comparing.

Suggested change
version_number=$$(grep "# *define OPENSSL_VERSION_STR" $$header_path | sed -E 's/.*"([^"]+)".*/\1/'); \
version_number=$$(grep "# *define OPENSSL_VERSION_STR" $$header_path | sed -E 's/.*OpenSSL ([0-9]+\.[0-9]+\.[0-9]+).*/\1/'); \

Copilot uses AI. Check for mistakes.
Comment on lines +18 to +21
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 \
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OPENSSL_VERSION_STR is typically a string like "OpenSSL 3.6.1 11 Feb 2025", so splitting on . yields a non-numeric major (e.g. "OpenSSL 3"), breaking numeric comparisons and potentially failing valid builds. Prefer parsing OPENSSL_VERSION_NUMBER from opensslv.h (hex) or extract only the numeric X.Y.Z portion via a regex before comparing.

Copilot uses AI. Check for mistakes.
ifeq ($(UNAME_S),Darwin)
SSL_LDIR := $(CUSTOM_OPENSSL_PATH)/lib
else
SSL_LDIR := $(CUSTOM_OPENSSL_PATH)/lib64
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting SSL_LDIR to $(CUSTOM_OPENSSL_PATH)/lib64 on non-Darwin breaks common layouts where OpenSSL installs into lib/ (not lib64/). Consider probing both lib64 and lib (or using pkg-config --variable=libdir when available) to reduce build failures for custom OpenSSL installs.

Suggested change
SSL_LDIR := $(CUSTOM_OPENSSL_PATH)/lib64
# Prefer lib64 when present, but fall back to lib to support installations
# that use lib/ instead of lib64/.
ifneq ("$(wildcard $(CUSTOM_OPENSSL_PATH)/lib64)","")
SSL_LDIR := $(CUSTOM_OPENSSL_PATH)/lib64
else
SSL_LDIR := $(CUSTOM_OPENSSL_PATH)/lib
endif

Copilot uses AI. Check for mistakes.
pull_request:
paths-ignore:
- '.github/**'
- '**.md'
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ignore glob for markdown has a trailing space ('**.md' ), which can prevent GitHub Actions from matching it as intended and cause workflows to run on markdown-only changes. Remove the trailing whitespace so the pattern is exactly **.md.

Suggested change
- '**.md'
- '**.md'

Copilot uses AI. Check for mistakes.
Comment thread README.md
Comment on lines +8 to +11
Table of Contents
=================

- [Introduction](#introduction)
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The ToC links (#introduction, etc.) may not resolve correctly because the headings now include embedded HTML (Introduction<a name="..."></a>), which alters GitHub’s auto-generated heading IDs. To keep stable anchors, consider using plain Markdown headings (e.g. ## Introduction) and place explicit anchors on separate lines (e.g. <a id="introduction"></a>) or rely solely on GitHub’s generated IDs without manual <a name=...> tags.

Copilot uses AI. Check for mistakes.
/* ProxySQL special handler function */
extern int PShandleRowData(PGconn *conn, bool is_first_packet, PSresult* result);

+/* Send a pipeline sync message without flushing the send buffer */
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The header comment says “without flushing the send buffer”, but the implementation calls pqPipelineFlush(conn). Either update the comment to reflect the actual behavior (flushes conditionally in pipeline mode), or change the implementation if true “no flush” semantics are required by callers.

Suggested change
+/* Send a pipeline sync message without flushing the send buffer */
+/* Send a pipeline sync message (see implementation for flushing behavior) */

Copilot uses AI. Check for mistakes.
Comment thread deps/libscram/Makefile
Comment on lines +13 to +20
LIBUSUAL_DIR ?= /path/to/libusual

# OpenSSL dir
LIBOPENSSL_DIR ?= /path/to/openssl

# PostgreSQL dir
POSTGRESQL_DIR ?= /path/to/postgresql
POSTGRESQL_INCLUDE_DIR = $(POSTGRESQL_DIR)/src/include/
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default include paths are placeholder /path/to/... values, so invoking this Makefile without explicitly setting variables will fail and can break automated dependency builds if it’s wired into deps/Makefile. Prefer deriving defaults from the repository root (relative paths), or fail fast with a clear $(error ...) message when these variables are unset, so builds don’t proceed with invalid include directories.

Suggested change
LIBUSUAL_DIR ?= /path/to/libusual
# OpenSSL dir
LIBOPENSSL_DIR ?= /path/to/openssl
# PostgreSQL dir
POSTGRESQL_DIR ?= /path/to/postgresql
POSTGRESQL_INCLUDE_DIR = $(POSTGRESQL_DIR)/src/include/
ifndef LIBUSUAL_DIR
$(error LIBUSUAL_DIR is not set. Please invoke make with LIBUSUAL_DIR=<path to libusual>)
endif
# OpenSSL dir
ifndef LIBOPENSSL_DIR
$(error LIBOPENSSL_DIR is not set. Please invoke make with LIBOPENSSL_DIR=<path to OpenSSL>)
endif
# PostgreSQL dir
ifndef POSTGRESQL_DIR
$(error POSTGRESQL_DIR is not set. Please invoke make with POSTGRESQL_DIR=<path to PostgreSQL source tree>)
endif
POSTGRESQL_INCLUDE_DIR ?= $(POSTGRESQL_DIR)/src/include/

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +9
#if !defined(bool) && !defined(bool_defined) && (!defined(HAVE_BOOL) || !defined(__cplusplus))
-typedef char bool; /* Ordinary boolean values 0 1 */
+typedef char bbool; /* Ordinary boolean values 0 1 */
#endif
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Renaming the typedef from bool to bbool avoids clashing with the C++ keyword, but it can break any C compilation units that relied on this header providing a bool typedef (especially if they don’t include <stdbool.h>). A safer fix is to ensure the typedef never activates under __cplusplus (e.g. tighten the preprocessor condition), or switch C code to <stdbool.h> while keeping C++ builds unaffected—without changing the exposed type name for C consumers.

Copilot uses AI. Check for mistakes.
#endif

#define SQLITE_VEC_VERSION "v${VERSION}"
// TODO rm
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The // TODO rm marker is committed in the public template and will likely be perpetuated into generated headers or downstream copies. Remove the TODO (or convert it into a meaningful comment) to avoid shipping “temporary” notes in vendored third-party templates.

Suggested change
// TODO rm
// Build date of this SQLite vector extension, substituted during template expansion.

Copilot uses AI. Check for mistakes.
Comment thread doc/BUILD-MACOS.md
@@ -0,0 +1,63 @@
# Compiling ProxySQL on macOS
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR title/description focuses on macOS compilation fixes and static zstd linking, but the diff includes many additional, unrelated changes (large RAG PoC documentation set, multiple dependency bumps, extensive CI workflow refactors, new contributor docs). Consider splitting these into separate PRs (or updating the PR description to explicitly cover the broader scope) to keep review, rollback, and release risk manageable.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a wide range of changes, including fixes for macOS compilation, static linking of the zstd library, and a significant number of new features and documentation related to AI, RAG, and anomaly detection. The build system has been substantially refactored to support these new features and improve cross-platform compatibility. My review focuses on the new code and build script modifications. I've identified a few potential issues: a library linking order problem in a new Makefile, a security concern regarding SQL injection in a proof-of-concept tool, and a misconfiguration in the build script for locating OpenSSL on macOS. These should be addressed to ensure build stability and security.

Comment thread RAG_POC/rag_ingest.cpp
Comment on lines +1011 to +1038
static void insert_doc(MySQLDB& db,
int source_id,
const std::string& source_name,
const std::string& doc_id,
const std::string& pk_json,
const std::string& title,
const std::string& body,
const std::string& meta_json) {
g_logger.debug(std::string("Inserting document: ") + doc_id +
", title_length=" + std::to_string(title.size()) +
", body_length=" + std::to_string(body.size()));

std::string e_doc_id = sql_escape_single_quotes(doc_id);
std::string e_source_name = sql_escape_single_quotes(source_name);
std::string e_pk_json = sql_escape_single_quotes(pk_json);
std::string e_title = sql_escape_single_quotes(title);
std::string e_body = sql_escape_single_quotes(body);
std::string e_meta = sql_escape_single_quotes(meta_json);

// Use std::ostringstream to avoid fixed buffer size issues
std::ostringstream sql;
sql << "INSERT INTO rag_documents(doc_id, source_id, source_name, pk_json, title, body, metadata_json) "
<< "VALUES('" << e_doc_id << "', " << source_id << ", '" << e_source_name << "', '"
<< e_pk_json << "', '" << e_title << "', '" << e_body << "', '" << e_meta << "')";

db.execute(sql.str().c_str());
g_logger.trace("Document inserted successfully");
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The functions insert_doc, insert_chunk, insert_fts, and insert_vec construct SQL queries by manually escaping strings and concatenating them. This is a common source of SQL injection vulnerabilities and is considered a security risk. Even for a proof-of-concept tool, it's a best practice to use prepared statements with parameter binding. The MySQL C API provides functions like mysql_stmt_init, mysql_stmt_prepare, mysql_stmt_bind_param, and mysql_stmt_execute for this purpose. Using them would eliminate this entire class of vulnerability.

Comment thread deps/Makefile
Comment on lines +230 to +232
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 .
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The OPENSSL_ROOT_DIR variable for CMake is incorrectly being set to $(SSL_IDIR), which is an include directory path (e.g., /opt/homebrew/opt/openssl@3/include). CMake's find_package(OpenSSL) module expects OPENSSL_ROOT_DIR to be the root prefix of the OpenSSL installation (e.g., /opt/homebrew/opt/openssl@3), from which it can locate the include/ and lib/ subdirectories. This misconfiguration can lead to build failures when CMake cannot find the OpenSSL libraries. A variable holding the OpenSSL prefix should be used instead. For example, you could define SSL_PREFIX in common_mk/openssl_flags.mk using pkg-config --variable=prefix openssl and then use -DOPENSSL_ROOT_DIR=$(SSL_PREFIX) here.

Comment thread RAG_POC/Makefile
# Use static libcurl
CURL_STATIC_LIB := $(ROOT_DIR)/deps/curl/curl/lib/.libs/libcurl.a

LIBS := -lmariadbclient -lssl -lcrypto -lcrypt -ldl -lpthread $(CURL_STATIC_LIB) -lz
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The order of libraries in this LIBS definition can be problematic. Linkers generally require that libraries are listed in an order where a library is listed after any other libraries that depend on it. Both libmariadbclient and libcurl depend on libssl and libcrypto. A safer ordering would be to list $(CURL_STATIC_LIB) and -lmariadbclient before -lssl and -lcrypto.

LIBS := -lmariadbclient $(CURL_STATIC_LIB) -lssl -lcrypto -lcrypt -ldl -lpthread -lz

@renecannao renecannao changed the base branch from v2.x to v3.0 March 20, 2026 20:39
@renecannao
Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 20, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
lib/Makefile (1)

36-44: ⚠️ Potential issue | 🟠 Major

Variable ordering issue: LDIRS is appended before it's defined.

The Darwin block on lines 36-39 appends to LDIRS using +=, but LDIRS is defined later on lines 41-44. This means the Darwin-specific library paths (-L/usr/local/lib -L/opt/homebrew/lib) will be lost because LDIRS is overwritten by the assignment on line 41.

🐛 Proposed fix: Move Darwin block after LDIRS definition
 			-I$(ZSTD_IDIR) \
 
-ifeq ($(UNAME_S),Linux)
-	IDIRS += -I$(COREDUMPER_IDIR)
-endif
-ifeq ($(UNAME_S),Darwin)
-	IDIRS += -I/usr/local/include -I/opt/homebrew/include
-	LDIRS += -L/usr/local/lib -L/opt/homebrew/lib
-endif
-
 LDIRS :=	-L$(JEMALLOC_LDIR) \
 			-L$(RE2_LDIR) \
 			-L$(LIBINJECTION_LDIR) \
 			-L$(PROMETHEUS_LDIR)
+
+ifeq ($(UNAME_S),Linux)
+	IDIRS += -I$(COREDUMPER_IDIR)
+endif
+ifeq ($(UNAME_S),Darwin)
+	IDIRS += -I/usr/local/include -I/opt/homebrew/include
+	LDIRS += -L/usr/local/lib -L/opt/homebrew/lib
+endif
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@lib/Makefile` around lines 36 - 44, The Darwin-specific append to LDIRS (the
ifeq block testing UNAME_S == Darwin) is currently before the LDIRS definition
so its += additions get overwritten; move the entire ifeq $(UNAME_S),Darwin ...
endif block to after the LDIRS := ... assignment (or alternately change the main
LDIRS to use += instead of :=) so that the Darwin -L/usr/local/lib and
-L/opt/homebrew/lib entries are preserved; reference the LDIRS variable and the
ifeq (UNAME_S,Darwin) block when making the change.
🧹 Nitpick comments (2)
deps/Makefile (1)

186-186: Consider declaring zstd as a PHONY target.

While the target works correctly because no file named zstd exists in this directory, declaring it as PHONY is best practice and ensures the rule always runs when invoked. Note: Other similar targets in this file (lz4, ev, curl) also lack PHONY declarations, so this is consistent with existing patterns.

♻️ Suggested improvement
 zstd: zstd/zstd/lib/libzstd.a
+.PHONY: zstd
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@deps/Makefile` at line 186, Declare the zstd Makefile target as phony so it
always runs: add a .PHONY entry including the target name "zstd" (e.g., .PHONY:
zstd) near the other PHONY declarations or at the top of the file; update any
grouped PHONY line that already lists lz4, ev, curl to include zstd for
consistency with targets like lz4/ev/curl and ensure no behavior changes to the
rule "zstd: zstd/zstd/lib/libzstd.a".
deps/zstd/README.md (1)

16-19: Minor path clarification in build example.

The build example shows cd zstd/zstd/lib after extracting, but the first zstd in the path is ambiguous since the reader is already in deps/zstd/. Consider clarifying:

📝 Suggested documentation improvement
 ```bash
-cd deps/zstd && tar -zxf zstd-1.5.7.tar.gz
-cd zstd/zstd/lib && make libzstd.a
+# From repository root:
+cd deps/zstd && tar -zxf zstd-1.5.7.tar.gz
+cd deps/zstd/zstd-1.5.7/lib && make libzstd.a
</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @deps/zstd/README.md around lines 16 - 19, Update the README build example to
remove the ambiguous relative path by explicitly showing commands from the
repository root: after extracting zstd-1.5.7, change the second cd to the full
path (e.g., deps/zstd/zstd-1.5.7/lib) so the sequence is unambiguous; include a
short note like "From repository root:" to clarify the context and replace the
current cd zstd/zstd/lib example in the README.


</details>

</blockquote></details>

</blockquote></details>

<details>
<summary>🤖 Prompt for all review comments with AI agents</summary>

Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In @lib/Makefile:

  • Around line 36-44: The Darwin-specific append to LDIRS (the ifeq block testing
    UNAME_S == Darwin) is currently before the LDIRS definition so its += additions
    get overwritten; move the entire ifeq $(UNAME_S),Darwin ... endif block to after
    the LDIRS := ... assignment (or alternately change the main LDIRS to use +=
    instead of :=) so that the Darwin -L/usr/local/lib and -L/opt/homebrew/lib
    entries are preserved; reference the LDIRS variable and the ifeq
    (UNAME_S,Darwin) block when making the change.

Nitpick comments:
In @deps/Makefile:

  • Line 186: Declare the zstd Makefile target as phony so it always runs: add a
    .PHONY entry including the target name "zstd" (e.g., .PHONY: zstd) near the
    other PHONY declarations or at the top of the file; update any grouped PHONY
    line that already lists lz4, ev, curl to include zstd for consistency with
    targets like lz4/ev/curl and ensure no behavior changes to the rule "zstd:
    zstd/zstd/lib/libzstd.a".

In @deps/zstd/README.md:

  • Around line 16-19: Update the README build example to remove the ambiguous
    relative path by explicitly showing commands from the repository root: after
    extracting zstd-1.5.7, change the second cd to the full path (e.g.,
    deps/zstd/zstd-1.5.7/lib) so the sequence is unambiguous; include a short note
    like "From repository root:" to clarify the context and replace the current cd zstd/zstd/lib example in the README.

</details>

---

<details>
<summary>ℹ️ Review info</summary>

<details>
<summary>⚙️ Run configuration</summary>

**Configuration used**: defaults

**Review profile**: CHILL

**Plan**: Pro

**Run ID**: `4fcdc7da-54d0-4be1-adf0-001103af52fc`

</details>

<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between 540fa174b4160a47b53ae734776b65e663d325e3 and 9fd4bcfe24f1541257ca6e1d77fe79fb3877f7d7.

</details>

<details>
<summary>⛔ Files ignored due to path filters (1)</summary>

* `deps/zstd/zstd-1.5.7.tar.gz` is excluded by `!**/*.gz`

</details>

<details>
<summary>📒 Files selected for processing (9)</summary>

* `.gitignore`
* `INSTALL.md`
* `deps/Makefile`
* `deps/zstd/README.md`
* `deps/zstd/zstd`
* `include/makefiles_paths.mk`
* `lib/Makefile`
* `lib/log_utils.cpp`
* `src/Makefile`

</details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@renecannao renecannao merged commit 0e955cd into v3.0 Mar 20, 2026
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix compilation issues on macOS (missing zstd includes, pthread_t cast)

2 participants