This is an automated email from the ASF dual-hosted git repository. avamingli pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/cloudberry.git
commit a2e512e77f7e47f6826533b43a805d3e4cd3e5fa Author: Zhang Mingli <[email protected]> AuthorDate: Thu May 28 18:23:05 2026 +0800 macOS: PAX cmake portability Several gcc / GNU-ld specific bits in the PAX cmake setup break under Apple clang and Apple ld. Make them conditional on Linux. * CMakeLists.txt: gate -no-pie / -Wl,--allow-multiple-definition / -fno-access-control / -Wno-pmf-conversions (gcc-only) behind if(NOT APPLE). Replace gcc-only warning disables (-Wno-clobbered, -Wno-sized-deallocation, -Wno-parameter-name) with -Wno-unknown-warning-option on APPLE, plus a set of -Wno-error= demotions for clang-stricter diagnostics (inconsistent-missing-override, overloaded-virtual, sometimes-uninitialized, unused-private-field, format, mismatched-tags, pessimizing-move, unused-but-set-variable, deprecated-copy, unused-result). * Makefile: pass -DBUILD_GTEST=OFF to the inner cmake (googletest's own flags clash with clang). Drop SHLIB_LINK += -luuid on darwin (uuid_* is in libSystem). Move the ifneq to after the include of Makefile.global so PORTNAME is actually defined. Cope with cmake naming the artefact libpax.so on every platform now (see below). * src/cpp/CMakeLists.txt: skip the standalone libpaxformat target on macOS. It links to backend symbols (write_stderr, ...) directly and isn't needed to load PAX inside postgres. * pax.cmake: on APPLE, build pax as a MODULE (Mach-O bundle, what PG extensions are) instead of SHARED, and link with -Wl,-undefined,dynamic_lookup -Wl,-bundle_loader,<postgres>. This is the standard PG extension pattern; it guarantees that backend globals (e.g. process_shared_preload_libraries_in_progress) have one shared instance between postgres and pax.so. Also gate -luring on Linux; pull abseil deps via pkg-config on macOS (Homebrew's protobuf v22+ split them into separate libs); replace the Linux-only $ORIGIN INSTALL_RPATH and -Wl,--enable-new-dtags with @loader_path on macOS. * pax_format.cmake: same Linux-only treatment for -luuid / -luring and the abseil pkg-config. --- contrib/pax_storage/CMakeLists.txt | 24 ++++++-- contrib/pax_storage/Makefile | 21 ++++++- contrib/pax_storage/src/cpp/CMakeLists.txt | 10 +++- contrib/pax_storage/src/cpp/cmake/pax.cmake | 65 +++++++++++++++++++--- contrib/pax_storage/src/cpp/cmake/pax_format.cmake | 20 ++++++- 5 files changed, 122 insertions(+), 18 deletions(-) diff --git a/contrib/pax_storage/CMakeLists.txt b/contrib/pax_storage/CMakeLists.txt index e45eab560e6..ac25ee6cbad 100644 --- a/contrib/pax_storage/CMakeLists.txt +++ b/contrib/pax_storage/CMakeLists.txt @@ -24,8 +24,16 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Base CXX flags # Note: -Wpessimizing-move is enabled by default in GCC 9+ and will be caught by -Werror # No need to explicitly add -Werror=pessimizing-move (which breaks GCC 8.x compatibility) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-unused-function -Wno-error=ignored-qualifiers -Wno-error=array-bounds -Wuninitialized -Winit-self -Wstrict-aliasing -Wno-missing-field-initializers -Wno-unused-parameter -Wno-clobbered -Wno-sized-deallocation -g") -set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused-parameter -Wno-parameter-name") +# -Wno-clobbered / -Wno-sized-deallocation / -Wno-parameter-name are GCC-only. +# Clang on macOS errors out via -Werror,-Wunknown-warning-option, and is +# stricter on virtual-override / overloaded-virtual / sometimes-uninitialized. +if(APPLE) + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-unused-function -Wno-error=ignored-qualifiers -Wno-error=array-bounds -Wuninitialized -Winit-self -Wstrict-aliasing -Wno-missing-field-initializers -Wno-unused-parameter -Wno-unknown-warning-option -Wno-error=inconsistent-missing-override -Wno-error=overloaded-virtual -Wno-error=sometimes-uninitialized -Wno-error=unused-private-field -Wno-error=format -Wno-error=mismatched-tags -Wno-error=pessimizing-move -Wno-error=unu [...] + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused-parameter -Wno-unknown-warning-option") +else() + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror -Wno-unused-function -Wno-error=ignored-qualifiers -Wno-error=array-bounds -Wuninitialized -Winit-self -Wstrict-aliasing -Wno-missing-field-initializers -Wno-unused-parameter -Wno-clobbered -Wno-sized-deallocation -g") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wno-unused-parameter -Wno-parameter-name") +endif() option(USE_MANIFEST_API "Use manifest API" OFF) option(USE_PAX_CATALOG "Use manifest API, by pax impl" ON) @@ -76,8 +84,16 @@ if(BUILD_GBENCH) endif(BUILD_GBENCH) if (BUILD_GTEST) - SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -no-pie -fno-stack-protector -Wall -Wno-unused-function -Wno-unused-variable") - SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-access-control -fno-inline -Wno-pmf-conversions -Wl,--allow-multiple-definition -no-pie -fno-stack-protector") + if(APPLE) + # macOS clang/ld lacks several gcc/GNU-ld-only flags used below + # (-no-pie, -Wl,--allow-multiple-definition, -fno-access-control, + # -Wno-pmf-conversions). Use a clang-safe subset. + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -fno-stack-protector -Wall -Wno-unused-function -Wno-unused-variable") + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-inline -fno-stack-protector") + else() + SET(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -no-pie -fno-stack-protector -Wall -Wno-unused-function -Wno-unused-variable") + SET(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -fno-access-control -fno-inline -Wno-pmf-conversions -Wl,--allow-multiple-definition -no-pie -fno-stack-protector") + endif() endif(BUILD_GTEST) # Vec options diff --git a/contrib/pax_storage/Makefile b/contrib/pax_storage/Makefile index 9f4061db9d7..6e09fc14436 100644 --- a/contrib/pax_storage/Makefile +++ b/contrib/pax_storage/Makefile @@ -23,7 +23,6 @@ PG_CPPFLAGS = -I/usr/local/include PG_CXXFLAGS = -std=c++17 PGFILEDESC = "pax - PAX table access method" -SHLIB_LINK += -luuid PAX_REGRESS_DIR = src/test/regress PAX_ISOLATION2_DIR = src/test/isolation2 @@ -42,6 +41,12 @@ include $(top_srcdir)/contrib/contrib-global.mk PG_REGRESS = $(top_builddir)/src/test/regress/pg_regress endif +# Must come AFTER Makefile.global include so PORTNAME is defined. +# libuuid is shipped by libSystem on macOS (no separate -luuid needed). +ifneq ($(PORTNAME), darwin) +SHLIB_LINK += -luuid +endif + .PHONY: all all: build @@ -63,6 +68,15 @@ ifeq ($(USE_PAX_CATALOG),) endif .PHONY: install-data build +# googletest's own CMakeLists.txt sprinkles gcc-only warning flags +# (-Wno-clobbered, -Wno-sized-deallocation, -Wno-parameter-name) that +# Apple clang rejects with -Werror,-Wunknown-warning-option. Skip the +# gtest target on darwin so the rest of PAX still builds; Linux keeps +# gtest enabled so 'make pax-unit-test' works as before. +ifeq ($(PORTNAME), darwin) +PAX_GTEST_OPT := -DBUILD_GTEST=OFF +endif + build: $(SRC) $(CSRC) @echo "build pax, USE_MANIFEST_API=$(USE_MANIFEST_API) USE_PAX_CATALOG=$(USE_PAX_CATALOG)" @if [ ! -f build/Makefile ]; then \ @@ -70,9 +84,12 @@ build: $(SRC) $(CSRC) cd build && \ cmake -DCMAKE_INSTALL_PREFIX=$(DESTDIR)$(prefix) \ -DUSE_MANIFEST_API=$(USE_MANIFEST_API) \ - -DUSE_PAX_CATALOG=$(USE_PAX_CATALOG) .. ; \ + -DUSE_PAX_CATALOG=$(USE_PAX_CATALOG) \ + $(PAX_GTEST_OPT) \ + .. ; \ fi cd build && make -j8 +# CMake emits libpax.so on both platforms (Linux SHARED, macOS MODULE). @cp -f build/src/cpp/libpax.so pax.so pax-unit-test: diff --git a/contrib/pax_storage/src/cpp/CMakeLists.txt b/contrib/pax_storage/src/cpp/CMakeLists.txt index 87ff074e877..c49473e5d12 100644 --- a/contrib/pax_storage/src/cpp/CMakeLists.txt +++ b/contrib/pax_storage/src/cpp/CMakeLists.txt @@ -48,7 +48,13 @@ add_custom_target(generate_protobuf DEPENDS ${PROTO_SRCS} ${PROTO_HDRS}) link_directories($ENV{GPHOME}/lib) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -## build pax_format.so -include(pax_format) +## build pax_format.so — standalone reader lib used by external tools. +## On macOS it would need -undefined dynamic_lookup to resolve PG symbols +## (write_stderr, xlog_check_consistency_hook, ...). Skip for now; pax.so +## itself (the in-backend extension) still builds and is enough to run +## the demo cluster with `USING pax` tables. +if(NOT APPLE) + include(pax_format) +endif() ## build pax.so include(pax) diff --git a/contrib/pax_storage/src/cpp/cmake/pax.cmake b/contrib/pax_storage/src/cpp/cmake/pax.cmake index 83f79f3f002..0d8be852ddb 100644 --- a/contrib/pax_storage/src/cpp/cmake/pax.cmake +++ b/contrib/pax_storage/src/cpp/cmake/pax.cmake @@ -174,15 +174,49 @@ add_subdirectory(contrib/tabulate) set(pax_target_src ${PROTO_SRCS} ${pax_storage_src} ${pax_clustering_src} ${pax_exceptions_src} ${pax_access_src} ${pax_comm_src} ${pax_catalog_src} ${pax_vec_src}) set(pax_target_include ${pax_target_include} ${ZTSD_HEADER} ${CMAKE_CURRENT_SOURCE_DIR} ${CBDB_INCLUDE_DIR} contrib/tabulate/include) -set(pax_target_link_libs ${pax_target_link_libs} protobuf zstd z postgres uring) +set(pax_target_link_libs ${pax_target_link_libs} zstd z) +# On Linux, link against the libpostgres.so produced by the backend +# (shared-postgres-backend). On macOS we must NOT do this: pax.so is +# loaded by postgres via dlopen, and a separate libpostgres.so would +# give pax.so its own copy of backend globals (e.g. +# process_shared_preload_libraries_in_progress). Instead, use the +# standard PG extension pattern: resolve symbols at load time against +# the postgres binary itself via -bundle_loader. +if(NOT APPLE) + list(APPEND pax_target_link_libs postgres) +endif() +# protobuf v22+ split its abseil deps into separate libs. On macOS the +# Homebrew protobuf is built this way and the link fails for abseil +# log_internal symbols unless we pull them via pkg-config. +if(APPLE) + find_package(PkgConfig REQUIRED) + pkg_check_modules(PB_PC REQUIRED protobuf) + set(pax_target_include ${pax_target_include} ${PB_PC_INCLUDE_DIRS}) + list(APPEND pax_target_link_directories ${PB_PC_LIBRARY_DIRS}) + list(APPEND pax_target_link_libs ${PB_PC_LIBRARIES}) +else() + list(APPEND pax_target_link_libs protobuf) +endif() +# liburing is Linux-only; PAX falls back to pread-based SyncFastIO elsewhere. +if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + list(APPEND pax_target_link_libs uring) +endif() if (PAX_USE_LZ4) list(APPEND pax_target_link_libs lz4) endif() set(pax_target_link_directories ${PROJECT_SOURCE_DIR}/../../src/backend/) set(pax_target_dependencies generate_protobuf create_sql_script) -add_library(pax SHARED ${pax_target_src}) -set_target_properties(pax PROPERTIES OUTPUT_NAME pax) +# On macOS, build pax as a MODULE (bundle) so that -bundle_loader is +# accepted and undefined PG symbols resolve at load time against the +# postgres binary (one shared copy of backend globals). +if(APPLE) + add_library(pax MODULE ${pax_target_src}) + set_target_properties(pax PROPERTIES OUTPUT_NAME pax SUFFIX ".so") +else() + add_library(pax SHARED ${pax_target_src}) + set_target_properties(pax PROPERTIES OUTPUT_NAME pax) +endif() if(USE_MANIFEST_API AND NOT USE_PAX_CATALOG) set(pax_target_link_libs ${pax_target_link_libs} yyjson) @@ -209,12 +243,25 @@ endif(VEC_BUILD) target_include_directories(pax PUBLIC ${pax_target_include}) target_link_directories(pax PUBLIC ${pax_target_link_directories}) target_link_libraries(pax PRIVATE ${pax_target_link_libs}) -set_target_properties(pax PROPERTIES - BUILD_RPATH_USE_ORIGIN ON - BUILD_WITH_INSTALL_RPATH ON - INSTALL_RPATH "$ORIGIN:$ORIGIN/.." - LINK_FLAGS "-Wl,--enable-new-dtags" -) +if(APPLE) + # macOS uses @loader_path / LC_RPATH; GNU-ld --enable-new-dtags and + # $ORIGIN aren't supported. We must NOT link against libpostgres.so — + # instead let undefined PG symbols resolve at load time against the + # postgres binary. That keeps a single instance of each backend global + # shared between postgres and pax.so. + set_target_properties(pax PROPERTIES + BUILD_WITH_INSTALL_RPATH ON + INSTALL_RPATH "@loader_path;@loader_path/.." + LINK_FLAGS "-Wl,-undefined,dynamic_lookup -Wl,-bundle_loader,${PROJECT_SOURCE_DIR}/../../src/backend/postgres" + ) +else() + set_target_properties(pax PROPERTIES + BUILD_RPATH_USE_ORIGIN ON + BUILD_WITH_INSTALL_RPATH ON + INSTALL_RPATH "$ORIGIN:$ORIGIN/.." + LINK_FLAGS "-Wl,--enable-new-dtags" + ) +endif() add_dependencies(pax ${pax_target_dependencies}) add_custom_command(TARGET pax POST_BUILD diff --git a/contrib/pax_storage/src/cpp/cmake/pax_format.cmake b/contrib/pax_storage/src/cpp/cmake/pax_format.cmake index 8d28e793d27..1c06dacf9d4 100644 --- a/contrib/pax_storage/src/cpp/cmake/pax_format.cmake +++ b/contrib/pax_storage/src/cpp/cmake/pax_format.cmake @@ -109,11 +109,29 @@ set(pax_vec_src ${pax_vec_src} endif() set(pax_target_include ${ZTSD_HEADER} ${CMAKE_CURRENT_SOURCE_DIR} ${CBDB_INCLUDE_DIR} contrib/tabulate/include) -set(pax_target_link_libs uuid protobuf zstd z uring) +set(pax_target_link_libs zstd z) +# protobuf v22+ on macOS splits its abseil deps into separate libs; +# pull them in via pkg-config. +if(APPLE) + find_package(PkgConfig REQUIRED) + pkg_check_modules(PB_PC REQUIRED protobuf) + set(pax_target_include ${pax_target_include} ${PB_PC_INCLUDE_DIRS}) + list(APPEND pax_target_link_libs ${PB_PC_LIBRARIES}) +else() + list(APPEND pax_target_link_libs protobuf) +endif() +# liburing is Linux-only (kernel io_uring iface). macOS provides uuid_* +# functions in libSystem, so -luuid is also Linux-only. +if (CMAKE_SYSTEM_NAME STREQUAL "Linux") + list(APPEND pax_target_link_libs uuid uring) +endif() if (PAX_USE_LZ4) list(APPEND pax_target_link_libs lz4) endif() set(pax_target_link_directories ${PROJECT_SOURCE_DIR}/../../src/backend/) +if(APPLE) + list(APPEND pax_target_link_directories ${PB_PC_LIBRARY_DIRS}) +endif() # vec build if (VEC_BUILD) --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
