Skip to content

Commit

Permalink
Require built LibScyllaDB/LibCassandra (removed from source building)
Browse files Browse the repository at this point in the history
Signed-off-by: Dusan Malusev <[email protected]>
  • Loading branch information
CodeLieutenant committed Jun 11, 2024
1 parent 7686fd7 commit 40033a6
Show file tree
Hide file tree
Showing 12 changed files with 1,549 additions and 675 deletions.
81 changes: 46 additions & 35 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
cmake_minimum_required(VERSION 3.24)
project(php-ext-scylladb LANGUAGES C CXX)
add_library(ext_scylladb SHARED)
cmake_policy(SET CMP0079 NEW)

# if build type is not set, default to debug
if (NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
if(NOT CMAKE_BUILD_TYPE OR CMAKE_BUILD_TYPE STREQUAL "")
set(CMAKE_BUILD_TYPE "Debug")
endif ()
endif()

include(GNUInstallDirs)
include(CheckSymbolExists)
Expand Down Expand Up @@ -33,34 +34,45 @@ option(PHP_SCYLLADB_ENABLE_COVERAGE "Enable coverage" OFF)
option(PHP_SCYLLADB_OPTIMISE_FOR_CURRENT_MACHINE "Optimise for current machine" OFF)

# PHP Options

set(CUSTOM_PHP_CONFIG "" CACHE STRING "Custom PHP config path")
set(PHP_VERSION_FOR_PHP_CONFIG "8.3" CACHE STRING "PHP version")

option(PHP_DEBUG_FOR_PHP_CONFIG "Debug or Release" ON)
option(PHP_THREAD_SAFE_FOR_PHP_CONFIG "ZTS(zts) or NTS(nts)" OFF)

option(PHP_SCYLLADB_LIBUV_STATIC "Statically link libuv" OFF)
option(PHP_SCYLLADB_LIBUV_FROM_SRC "Build LibUV from Source" OFF)
if(CMAKE_HOST_APPLE)
option(PHP_SCYLLADB_LIBUV_STATIC "Statically link libuv" ON)
else()
option(PHP_SCYLLADB_LIBUV_STATIC "Statically link libuv" OFF)
endif()

option(PHP_SCYLLADB_LIBUV_FROM_SRC "Build LibUV from Source" ON)

option(PHP_SCYLLADB_LIBSCYLLADB_STATIC "Statically link LibScyllaDB" OFF)
option(PHP_SCYLLADB_LIBSCYLLADB_FROM_SRC "Build LibScyllaDB from Source" OFF)
if(CMAKE_HOST_APPLE)
option(PHP_SCYLLADB_LIBSCYLLADB_STATIC "Statically link LibScyllaDB" ON)
else()
option(PHP_SCYLLADB_LIBSCYLLADB_STATIC "Statically link LibScyllaDB" OFF)
endif()

option(PHP_SCYLLADB_USE_LIBCASSANDRA "Use DataStax LibCassandra instead of LibScyllaDB" OFF)
option(PHP_SCYLLADB_LIBCASSANDRA_STATIC "Statically link LibCassandra" OFF)
option(PHP_SCYLLADB_LIBCASSANDRA_FROM_SRC "Build LibCassandra from Source" OFF)

if(CMAKE_HOST_APPLE)
option(PHP_SCYLLADB_LIBCASSANDRA_STATIC "Statically link LibCassandra" ON)
else()
option(PHP_SCYLLADB_LIBCASSANDRA_STATIC "Statically link LibCassandra" OFF)
endif()

find_package(PHPConfig REQUIRED)
find_package(PHP REQUIRED)
find_package(Sanitizers REQUIRED)
find_package(LibUV REQUIRED)
find_package(Libuv REQUIRED)
find_package(LibGMP REQUIRED)

if (PHP_SCYLLADB_USE_LIBCASSANDRA)
if(PHP_SCYLLADB_USE_LIBCASSANDRA)
find_package(CassandraDriver REQUIRED)
else ()
else()
find_package(ScyllaDBDriver REQUIRED)
endif ()
endif()

add_subdirectory(ZendCPP)
add_subdirectory(util)
Expand All @@ -83,22 +95,21 @@ target_sources(ext_scylladb PUBLIC FILE_SET headers TYPE HEADERS FILES "${HEADER
target_sources(ext_scylladb PRIVATE php_driver.cpp)

target_link_libraries(
ext_scylladb PRIVATE
Zend
ext_scylladb::src
ext_scylladb::utils
ext_scylladb::type
ext_scylladb::datetime
ext_scylladb::database
ext_scylladb::numbers
ext_scylladb::ssl_options
ext_scylladb::exceptions
ext_scylladb::cluster::builder
ext_scylladb::retry_policy
ext_scylladb::timestamp_generator
ext_scylladb PRIVATE
Zend
ext_scylladb::src
ext_scylladb::utils
ext_scylladb::type
ext_scylladb::datetime
ext_scylladb::database
ext_scylladb::numbers
ext_scylladb::ssl_options
ext_scylladb::exceptions
ext_scylladb::cluster::builder
ext_scylladb::retry_policy
ext_scylladb::timestamp_generator
)


check_include_file("dlfcn.h" HAVE_DLFCN_H)
check_include_file("stdio.h" HAVE_STDIO_H)
check_include_file("stdint.h" HAVE_STDINT_H)
Expand All @@ -112,17 +123,17 @@ check_include_file("unistd.h" HAVE_UNISTD_H)
set(HAVE_STRINGS_H 0)

configure_file(
config.in
config.h
USE_SOURCE_PERMISSIONS
NEWLINE_STYLE UNIX
config.in
config.h
USE_SOURCE_PERMISSIONS
NEWLINE_STYLE UNIX
)

configure_file(
version.h.in
version.h
USE_SOURCE_PERMISSIONS
NEWLINE_STYLE UNIX
version.h.in
version.h
USE_SOURCE_PERMISSIONS
NEWLINE_STYLE UNIX
)

target_compile_definitions(ext_scylladb PRIVATE -DCOMPILE_DL_CASSANDRA -DHAVE_CONFIG_H)
Expand Down
8 changes: 0 additions & 8 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"PHP_SCYLLADB_USE_LIBCASSANDRA": "OFF",
"PHP_SCYLLADB_LIBSCYLLADB_STATIC": "OFF",
"PHP_SCYLLADB_LIBSCYLLADB_FROM_SRC": "OFF",
"SANITIZE_UNDEFINED": "OFF",
"SANITIZE_ADDRESS": "OFF"
}
Expand All @@ -61,8 +59,6 @@
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"PHP_SCYLLADB_USE_LIBCASSANDRA": "ON",
"SANITIZE_UNDEFINED": "OFF",
"PHP_SCYLLADB_LIBCASSANDRA_STATIC": "OFF",
"PHP_SCYLLADB_LIBCASSANDRA_FROM_SRC": "OFF",
"SANITIZE_ADDRESS": "OFF"
}
},
Expand All @@ -77,8 +73,6 @@
"CMAKE_BUILD_TYPE": "RelWithInfo",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"PHP_SCYLLADB_ENABLE_SANITIZERS": "OFF",
"PHP_SCYLLADB_LIBSCYLLADB_STATIC": "OFF",
"PHP_SCYLLADB_LIBSCYLLADB_FROM_SRC": "OFF",
"SANITIZE_UNDEFINED": "OFF",
"SANITIZE_ADDRESS": "OFF"
}
Expand All @@ -94,8 +88,6 @@
"CMAKE_BUILD_TYPE": "RelWithInfo",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"PHP_SCYLLADB_USE_LIBCASSANDRA": "ON",
"PHP_SCYLLADB_LIBCASSANDRA_STATIC": "OFF",
"PHP_SCYLLADB_LIBCASSANDRA_FROM_SRC": "OFF",
"PHP_SCYLLADB_ENABLE_SANITIZERS": "OFF",
"SANITIZE_UNDEFINED": "OFF",
"SANITIZE_ADDRESS": "OFF"
Expand Down
72 changes: 9 additions & 63 deletions cmake/FindCassandraDriver.cmake
Original file line number Diff line number Diff line change
@@ -1,66 +1,12 @@
if (PHP_SCYLLADB_LIBCASSANDRA_FROM_SRC)
if (PHP_SCYLLADB_LIBCASSANDRA_STATIC)
set(CASS_BUILD_STATIC ON)
set(CASS_BUILD_SHARED OFF)
else ()
set(CASS_BUILD_STATIC OFF)
set(CASS_BUILD_SHARED ON)
endif ()
find_package(PkgConfig REQUIRED)

if (PHP_SCYLLADB_LIBUV_FROM_SRC)
CPMAddPackage(
NAME libcassandra
GITHUB_REPOSITORY datastax/cpp-driver
OPTIONS
"CASS_CPP_STANDARD 17"
"CASS_BUILD_STATIC ${CASS_BUILD_STATIC}"
"CASS_BUILD_SHARED ${CASS_BUILD_SHARED}"
"CASS_USE_STD_ATOMIC ON"
"CASS_USE_TIMERFD ON"
"CASS_USE_LIBSSH2 ON"
"CASS_USE_ZLIB ON"
"CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -fPIC"
"CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fPIC -Wno-error=redundant-move"
"LIBUV_LIBRARY ${LIBUV_LIBRARY}"
"LIBUV_INCLUDE_DIR ${libuv_SOURCE_DIR}/include"
)
else ()
CPMAddPackage(
NAME libcassandra
GITHUB_REPOSITORY datastax/cpp-driver
OPTIONS
"CASS_CPP_STANDARD 17"
"CASS_BUILD_STATIC ${CASS_BUILD_STATIC}"
"CASS_BUILD_SHARED ${CASS_BUILD_SHARED}"
"CASS_USE_STD_ATOMIC ON"
"CASS_USE_TIMERFD ON"
"CASS_USE_LIBSSH2 ON"
"CASS_USE_ZLIB ON"
"CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -fPIC"
"CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fPIC -Wno-error=redundant-move"
)
endif ()

if (PHP_SCYLLADB_LIBCASSANDRA_STATIC)
target_link_libraries(ext_scylladb PRIVATE cassandra_static)
target_compile_definitions(ext_scylladb PRIVATE -DSCYLLADB_STATIC)
else ()
target_link_libraries(ext_scylladb PRIVATE "libcassandra.so")
endif ()

target_include_directories(ext_scylladb PUBLIC ${libcassandra_SOURCE_DIR}/include)
set(CASSANDRA_H ${libcassandra_SOURCE_DIR}/include)
if (PHP_SCYLLADB_LIBCASSANDRA_STATIC)
pkg_check_modules(LIBCASSANDRA REQUIRED IMPORTED_TARGET cassandra_static)
else ()
find_package(PkgConfig REQUIRED)

if (PHP_SCYLLADB_LIBCASSANDRA_STATIC)
pkg_check_modules(LIBCASSANDRA REQUIRED IMPORTED_TARGET cassandra_static)
else ()
pkg_check_modules(LIBCASSANDRA REQUIRED IMPORTED_TARGET cassandra)
endif ()

target_link_libraries(ext_scylladb PRIVATE ${LIBCASSANDRA_LIBRARIES})
target_link_directories(ext_scylladb PRIVATE ${LIBCASSANDRA_LIBRARY_DIRS})
target_include_directories(ext_scylladb PUBLIC ${LIBCASSANDRA_INCLUDE_DIRS})
set(CASSANDRA_H ${LIBCASSANDRA_INCLUDE_DIRS})
pkg_check_modules(LIBCASSANDRA REQUIRED IMPORTED_TARGET cassandra)
endif ()

target_link_libraries(ext_scylladb PRIVATE ${LIBCASSANDRA_LIBRARIES})
target_link_directories(ext_scylladb PRIVATE ${LIBCASSANDRA_LIBRARY_DIRS})
target_include_directories(ext_scylladb PUBLIC ${LIBCASSANDRA_INCLUDE_DIRS})
set(CASSANDRA_H ${LIBCASSANDRA_INCLUDE_DIRS})
9 changes: 3 additions & 6 deletions cmake/FindLibUV.cmake → cmake/FindLibuv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ if (PHP_SCYLLADB_LIBUV_FROM_SRC)

CPMAddPackage(
NAME libuv
VERSION 1.44.2
URL https://github.com/libuv/libuv/tarball/v1.44.2
URL_HASH MD5=3e22e24d53aab67252907dfa004a6b53
VERSION 1.48.0
URL https://github.com/libuv/libuv/tarball/v1.48.0
OPTIONS
"BUILD_TESTING OFF"
"BUILD_BENCHMARKS OFF"
Expand All @@ -25,24 +24,22 @@ if (PHP_SCYLLADB_LIBUV_FROM_SRC)
else ()
set(LIBUV_LIBRARY "${libuv_BINARY_DIR}/libuv.so")
endif ()
set(LIBUV_LIBRARY_DIRS "${libuv_BINARY_DIR}")

if (PHP_SCYLLADB_LIBUV_STATIC)
target_compile_definitions(ext_scylladb PRIVATE -DUV_STATIC)
target_link_libraries(ext_scylladb PRIVATE uv_a)
else ()
target_link_libraries(ext_scylladb PRIVATE uv)
endif ()
else ()
find_package(PkgConfig REQUIRED)

if (PHP_SCYLLADB_LIBUV_STATIC)
target_compile_definitions(ext_scylladb PRIVATE -DUV_STATIC)
pkg_check_modules(LIBUV REQUIRED IMPORTED_TARGET libuv-static)
else ()
pkg_check_modules(LIBUV REQUIRED IMPORTED_TARGET libuv)
endif ()

message(STATUS "LibUV ${LIBUV_INCLUDE_DIRS}")
target_link_libraries(ext_scylladb PRIVATE ${LIBUV_LIBRARIES})
target_link_directories(ext_scylladb PRIVATE ${LIBUV_LIBRARY_DIRS})
target_include_directories(ext_scylladb PUBLIC ${LIBUV_INCLUDE_DIRS})
Expand Down
76 changes: 9 additions & 67 deletions cmake/FindScyllaDBDriver.cmake
Original file line number Diff line number Diff line change
@@ -1,70 +1,12 @@
find_package(PkgConfig REQUIRED)

if (PHP_SCYLLADB_LIBSCYLLADB_FROM_SRC)
if (PHP_SCYLLADB_LIBSCYLLADB_STATIC)
set(CASS_BUILD_STATIC ON)
set(CASS_BUILD_SHARED OFF)
else ()
set(CASS_BUILD_STATIC OFF)
set(CASS_BUILD_SHARED ON)
endif ()

if (PHP_SCYLLADB_LIBUV_FROM_SRC)
CPMAddPackage(
NAME libscylladb
GITHUB_REPOSITORY "scylladb/cpp-driver"
GIT_TAG master
OPTIONS
"CASS_CPP_STANDARD 17"
"CASS_BUILD_STATIC ${CASS_BUILD_STATIC}"
"CASS_BUILD_SHARED ${CASS_BUILD_SHARED}"
"CASS_USE_STD_ATOMIC ON"
"CASS_USE_TIMERFD ON"
"CASS_USE_LIBSSH2 ON"
"CASS_USE_ZLIB OFF"
"CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -fPIC"
"CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fPIC -Wno-error=redundant-move"
"LIBUV_LIBRARY ${LIBUV_LIBRARY}"
"LIBUV_INCLUDE_DIR ${libuv_SOURCE_DIR}/include"
)
else ()
CPMAddPackage(
NAME libscylladb
GITHUB_REPOSITORY "scylladb/cpp-driver"
GIT_TAG master
OPTIONS
"CASS_CPP_STANDARD 17"
"CASS_BUILD_STATIC ${CASS_BUILD_STATIC}"
"CASS_BUILD_SHARED ${CASS_BUILD_SHARED}"
"CASS_USE_STD_ATOMIC ON"
"CASS_USE_TIMERFD ON"
"CASS_USE_LIBSSH2 ON"
"CASS_USE_ZLIB OFF"
"CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -fPIC"
"CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -fPIC -Wno-error=redundant-move"
)
endif ()

if (PHP_SCYLLADB_LIBSCYLLADB_STATIC)
target_link_libraries(ext_scylladb PRIVATE cassandra_static)
target_compile_definitions(ext_scylladb PRIVATE -DSCYLLADB_STATIC)
else ()
target_link_libraries(ext_scylladb PRIVATE "libscylla-cpp-driver.so")
endif ()

target_include_directories(ext_scylladb PUBLIC ${libscylladb_SOURCE_DIR}/include)
set(CASSANDRA_H ${libscylladb_SOURCE_DIR}/include)
if (PHP_SCYLLADB_LIBSCYLLADB_STATIC)
pkg_check_modules(LIBSCYLLADB REQUIRED IMPORTED_TARGET scylla-cpp-driver_static)
else ()
find_package(PkgConfig REQUIRED)

if (PHP_SCYLLADB_LIBSCYLLADB_STATIC)
pkg_check_modules(LIBSCYLLADB REQUIRED IMPORTED_TARGET scylla-cpp-driver_static)
else ()
pkg_check_modules(LIBSCYLLADB REQUIRED IMPORTED_TARGET scylla-cpp-driver)
endif ()

message(STATUS "SCYLLA ${LIBSCYLLADB_INCLUDE_DIRS}")
target_include_directories(ext_scylladb PUBLIC "${LIBSCYLLADB_INCLUDE_DIRS}")
target_link_libraries(ext_scylladb PRIVATE "${LIBSCYLLADB_LIBRARIES}")
target_link_directories(ext_scylladb PRIVATE "${LIBSCYLLADB_LIBRARY_DIRS}")
set(CASSANDRA_H ${LIBSCYLLADB_INCLUDE_DIRS})
pkg_check_modules(LIBSCYLLADB REQUIRED IMPORTED_TARGET scylla-cpp-driver)
endif ()

target_include_directories(ext_scylladb PUBLIC "${LIBSCYLLADB_INCLUDE_DIRS}")
target_link_libraries(ext_scylladb PRIVATE "${LIBSCYLLADB_LIBRARIES}")
target_link_directories(ext_scylladb PRIVATE "${LIBSCYLLADB_LIBRARY_DIRS}")
set(CASSANDRA_H ${LIBSCYLLADB_INCLUDE_DIRS})
1 change: 0 additions & 1 deletion cmake/ScyllaDBPHPLibrary.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ include(CheckCXXCompilerFlag)
include(CheckCCompilerFlag)

function(scylladb_php_library target enable_sanitizers native_arch lto)
message(STATUS, "CASSANDRA_H ${CASSANDRA_H}")
target_include_directories(
${target}
PUBLIC
Expand Down
6 changes: 2 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,12 @@ RUN git clone --depth 1 https://github.com/scylladb/cpp-driver.git scylladb-driv
&& cd build \
&& cmake -DCASS_CPP_STANDARD=17 -DCASS_BUILD_STATIC=ON -DCASS_BUILD_SHARED=ON -DCASS_USE_STD_ATOMIC=ON -DCASS_USE_TIMERFD=ON -DCASS_USE_LIBSSH2=ON -DCASS_USE_ZLIB=ON CMAKE_C_FLAGS="-fPIC" -DCMAKE_CXX_FLAGS="-fPIC -Wno-error=redundant-move" -DCMAKE_BUILD_TYPE="RelWithInfo" -G Ninja .. \
&& ninja install \
&& cd ../.. \
&& rm -rf scylladb-driver
&& cd ../..

RUN git clone --depth 1 https://github.com/datastax/cpp-driver.git cassandra-driver \
&& cd cassandra-driver \
&& mkdir build \
&& cd build \
&& cmake -DCASS_CPP_STANDARD=17 -DCASS_BUILD_STATIC=ON -DCASS_BUILD_SHARED=ON -DCASS_USE_STD_ATOMIC=ON -DCASS_USE_TIMERFD=ON -DCASS_USE_LIBSSH2=ON -DCASS_USE_ZLIB=ON CMAKE_C_FLAGS="-fPIC" -DCMAKE_CXX_FLAGS="-fPIC -Wno-error=redundant-move" -DCMAKE_BUILD_TYPE="RelWithInfo" -G Ninja .. \
&& ninja install \
&& cd ../.. \
&& rm -rf cassandra-driver
&& cd ../..
Loading

0 comments on commit 40033a6

Please sign in to comment.