Skip to content

Commit 175e034

Browse files
committed
fix(ci): resolve macOS MySQL linkage check failures
Fix two issues in the MySQL linkage verification: 1. otool -L output includes the binary name on its first line, causing false positives when binaries are named mysql_backend_test. Skip the first line and match only against library dependency lines. 2. Brew's mariadb-connector-c is keg-only (not symlinked). Add CMAKE_PREFIX_PATH for macOS CI and add find_library/find_path fallback in CMakeLists.txt for system-installed libmariadb.
1 parent 72b6914 commit 175e034

2 files changed

Lines changed: 49 additions & 5 deletions

File tree

.github/workflows/ci.yml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,8 @@ jobs:
345345
if: runner.os == 'macOS'
346346
run: |
347347
brew install ninja googletest mariadb-connector-c
348+
# mariadb-connector-c is keg-only; export paths for CMake discovery
349+
echo "CMAKE_PREFIX_PATH=/opt/homebrew/opt/mariadb-connector-c" >> $GITHUB_ENV
348350
349351
- name: Build and install common_system
350352
run: |
@@ -361,8 +363,13 @@ jobs:
361363
362364
- name: Configure CMake with MySQL
363365
run: |
366+
CMAKE_EXTRA_ARGS=""
367+
if [ -n "$CMAKE_PREFIX_PATH" ]; then
368+
CMAKE_EXTRA_ARGS="-DCMAKE_PREFIX_PATH=$CMAKE_PREFIX_PATH"
369+
fi
364370
cmake -B build -G Ninja \
365371
-DCMAKE_BUILD_TYPE=Debug \
372+
$CMAKE_EXTRA_ARGS \
366373
-DALLOW_BUILD_WITHOUT_NETWORK_SYSTEM=ON \
367374
-DUSE_THREAD_SYSTEM=OFF \
368375
-DUSE_MONITORING_SYSTEM=OFF \
@@ -393,12 +400,16 @@ jobs:
393400
DEPS=$(${{ matrix.check-cmd }} "$binary" 2>/dev/null || true)
394401
echo "$DEPS"
395402
396-
if echo "$DEPS" | grep -qi "mariadb\|mysql"; then
403+
# Skip the first line of otool output (binary name) to avoid
404+
# false positives from binary names like mysql_backend_test
405+
DEPS_LIBS=$(echo "$DEPS" | tail -n +2)
406+
407+
if echo "$DEPS_LIBS" | grep -qiE "libmariadb|libmysqlclient"; then
397408
FOUND_BINARY=true
398409
echo " -> libmariadb dependency detected"
399410
400411
# Verify it is a shared library reference (not static)
401-
if echo "$DEPS" | grep -qiE "libmariadb.*\.so|libmariadb.*\.dylib|libmysqlclient.*\.so|libmysqlclient.*\.dylib"; then
412+
if echo "$DEPS_LIBS" | grep -qiE "libmariadb.*\.so|libmariadb.*\.dylib|libmysqlclient.*\.so|libmysqlclient.*\.dylib"; then
402413
echo " -> PASS: dynamically linked (LGPL-2.1 compliant)"
403414
else
404415
echo " -> FAIL: linkage type unclear, manual review needed"

database/CMakeLists.txt

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,42 @@ if(USE_MYSQL)
420420
message(STATUS " libmariadb linking: ${_mariadb_type} (verify dynamic linkage in CI)")
421421
endif()
422422
else()
423-
message(WARNING "MariaDB Connector/C not found, disabling MySQL support")
424-
message(STATUS " libmariadb found: ${unofficial-libmariadb_FOUND}")
425-
set(USE_MYSQL OFF CACHE BOOL "MySQL support disabled due to missing libraries" FORCE)
423+
# Fallback: find system-installed libmariadb (Homebrew, apt, etc.)
424+
# Brew's mariadb-connector-c is keg-only — requires CMAKE_PREFIX_PATH
425+
find_library(MARIADB_LIBRARY NAMES mariadb mariadbclient
426+
HINTS
427+
/opt/homebrew/opt/mariadb-connector-c/lib
428+
/usr/lib/x86_64-linux-gnu
429+
)
430+
find_path(MARIADB_INCLUDE_DIR NAMES mysql.h mariadb/mysql.h
431+
HINTS
432+
/opt/homebrew/opt/mariadb-connector-c/include/mariadb
433+
/usr/include/mariadb
434+
)
435+
436+
if(MARIADB_LIBRARY AND MARIADB_INCLUDE_DIR)
437+
target_link_libraries(${PROJECT_NAME} PUBLIC ${MARIADB_LIBRARY})
438+
target_include_directories(${PROJECT_NAME} PUBLIC ${MARIADB_INCLUDE_DIR})
439+
target_compile_definitions(${PROJECT_NAME} PUBLIC USE_MYSQL)
440+
message(STATUS "MySQL support enabled (via system MariaDB Connector/C, LGPL-2.1)")
441+
message(STATUS " libmariadb library: ${MARIADB_LIBRARY}")
442+
message(STATUS " libmariadb include: ${MARIADB_INCLUDE_DIR}")
443+
444+
# LGPL-2.1 compliance: system-installed libraries are typically shared
445+
get_filename_component(_mariadb_ext "${MARIADB_LIBRARY}" EXT)
446+
if(_mariadb_ext STREQUAL ".a" OR _mariadb_ext STREQUAL ".lib")
447+
message(WARNING
448+
"libmariadb appears to be statically linked (${_mariadb_ext}). "
449+
"LGPL-2.1 compliance requires dynamic linking.")
450+
else()
451+
message(STATUS " libmariadb linking: dynamic (${_mariadb_ext}, LGPL-2.1 compliant)")
452+
endif()
453+
else()
454+
message(WARNING "MariaDB Connector/C not found, disabling MySQL support")
455+
message(STATUS " libmariadb found (vcpkg): ${unofficial-libmariadb_FOUND}")
456+
message(STATUS " libmariadb found (system): lib=${MARIADB_LIBRARY} inc=${MARIADB_INCLUDE_DIR}")
457+
set(USE_MYSQL OFF CACHE BOOL "MySQL support disabled due to missing libraries" FORCE)
458+
endif()
426459
endif()
427460
endif()
428461

0 commit comments

Comments
 (0)