From df71b382ca75f6c9eb418da6d8adf714c85ce1f8 Mon Sep 17 00:00:00 2001 From: Dusan Malusev Date: Wed, 19 Jun 2024 14:19:12 +0200 Subject: [PATCH] Fixing issue with undefined symbol 'php_stat' -> External C Linking Error Signed-off-by: Dusan Malusev --- CMakeLists.txt | 103 ++++++++++++++++++++++-------------- scripts/compile-scylladb.sh | 14 +++++ scripts/scyladb-driver | 1 + src/SSLOptions/Builder.cpp | 34 ++++++------ 4 files changed, 94 insertions(+), 58 deletions(-) create mode 100755 scripts/compile-scylladb.sh create mode 160000 scripts/scyladb-driver diff --git a/CMakeLists.txt b/CMakeLists.txt index c85b95ff2..2fdbe780a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,12 +1,37 @@ cmake_minimum_required(VERSION 3.24) + +if (POLICY CMP0074) + cmake_policy(SET CMP0074 NEW) +endif () + +if (POLICY CMP0054) + cmake_policy(SET CMP0054 NEW) +endif () + +if (POLICY CMP0079) + cmake_policy(SET CMP0079 NEW) +endif () + +if (POLICY CMP0108) + cmake_policy(SET CMP0108 NEW) +endif () + +if (POLICY CMP0109) + cmake_policy(SET CMP0109 NEW) +endif () + +if (POLICY CMP0128) + cmake_policy(SET CMP0128 NEW) +endif () + + 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) @@ -18,13 +43,13 @@ include(cmake/ScyllaDBPHPLibrary.cmake) set(PHP_SCYLLADB_VERSION_MAJOR 1) set(PHP_SCYLLADB_VERSION_MINOR 3) -set(PHP_SCYLLADB_VERSION_PATCH 11) +set(PHP_SCYLLADB_VERSION_PATCH 12) set(PHP_SCYLLADB_STABILITY "devel") set(PHP_SCYLLADB_VERSION_FULL "${PHP_SCYLLADB_VERSION_MAJOR}.${PHP_SCYLLADB_VERSION_MINOR}.${PHP_SCYLLADB_VERSION_PATCH}-${PHP_SCYLLADB_STABILITY}") set(PHP_SCYLLADB_VERSION "${PHP_SCYLLADB_VERSION_MAJOR}.${PHP_SCYLLADB_VERSION_MINOR}.${PHP_SCYLLADB_VERSION_PATCH}-dev") -set(CMAKE_C_STANDARD 23) -set(CMAKE_CXX_STANDARD 23) +set(CMAKE_C_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake" "${PROJECT_SOURCE_DIR}/third-party/sanitizers-cmake/cmake") @@ -40,27 +65,27 @@ 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) -if(CMAKE_HOST_APPLE) +if (CMAKE_HOST_APPLE) option(PHP_SCYLLADB_LIBUV_STATIC "Statically link libuv" ON) -else() +else () option(PHP_SCYLLADB_LIBUV_STATIC "Statically link libuv" OFF) -endif() +endif () option(PHP_SCYLLADB_LIBUV_FROM_SRC "Build LibUV from Source" ON) -if(CMAKE_HOST_APPLE) +if (CMAKE_HOST_APPLE) option(PHP_SCYLLADB_LIBSCYLLADB_STATIC "Statically link LibScyllaDB" ON) -else() +else () option(PHP_SCYLLADB_LIBSCYLLADB_STATIC "Statically link LibScyllaDB" OFF) -endif() +endif () option(PHP_SCYLLADB_USE_LIBCASSANDRA "Use DataStax LibCassandra instead of LibScyllaDB" OFF) -if(CMAKE_HOST_APPLE) +if (CMAKE_HOST_APPLE) option(PHP_SCYLLADB_LIBCASSANDRA_STATIC "Statically link LibCassandra" ON) -else() +else () option(PHP_SCYLLADB_LIBCASSANDRA_STATIC "Statically link LibCassandra" OFF) -endif() +endif () find_package(PHPConfig REQUIRED) find_package(PHP REQUIRED) @@ -68,11 +93,11 @@ find_package(Sanitizers 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) @@ -95,19 +120,19 @@ 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) @@ -123,17 +148,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) diff --git a/scripts/compile-scylladb.sh b/scripts/compile-scylladb.sh new file mode 100755 index 000000000..19385b9d9 --- /dev/null +++ b/scripts/compile-scylladb.sh @@ -0,0 +1,14 @@ +git clone --depth 1 https://github.com/scylladb/cpp-driver.git scyladb-driver + +pushd scyladb-driver + +mkdir build + +pushd 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 + +popd +popd diff --git a/scripts/scyladb-driver b/scripts/scyladb-driver new file mode 160000 index 000000000..fa0f27069 --- /dev/null +++ b/scripts/scyladb-driver @@ -0,0 +1 @@ +Subproject commit fa0f27069a625057984d1fa58f434ea99b86c83f diff --git a/src/SSLOptions/Builder.cpp b/src/SSLOptions/Builder.cpp index 159ee6c9c..44e8de1a2 100644 --- a/src/SSLOptions/Builder.cpp +++ b/src/SSLOptions/Builder.cpp @@ -15,7 +15,6 @@ */ #include -#include #include #include @@ -23,13 +22,16 @@ #include -static std::expected file_get_contents(const zend_string *path) { +BEGIN_EXTERN_C() +#include + +static zend_result file_get_contents(const zend_string *path, zend_string** out_val) { php_stream *stream = php_stream_open_wrapper(ZSTR_VAL(path), "rb", USE_PATH | REPORT_ERRORS, NULL); if (!stream) { zend_throw_exception_ex(php_driver_runtime_exception_ce, 0, "The path '%s' doesn't exist or is not readable", ZSTR_VAL(path)); - return std::unexpected(FAILURE); + return FAILURE; } zend_string *str = php_stream_copy_to_mem(stream, PHP_STREAM_COPY_ALL, 0); @@ -37,14 +39,13 @@ static std::expected file_get_contents(const zend_st if (!str) { zend_throw_exception_ex(php_driver_runtime_exception_ce, 0, "Failed to allocate enough memory"); - return std::unexpected(FAILURE); + return FAILURE; } - return str; -} + *out_val = str; -BEGIN_EXTERN_C() -#include + return SUCCESS; +} #include "Builder_arginfo.h" @@ -64,13 +65,11 @@ ZEND_METHOD(Cassandra_SSLOptions_Builder, build) { if (builder->trusted_certs) { for (size_t i = 0; i < builder->trusted_certs_cnt; i++) { - auto result = file_get_contents(builder->trusted_certs[i]); - - if (result.error() == FAILURE) { + zend_string* str; + if (file_get_contents(builder->trusted_certs[i], &str) == FAILURE) { return; } - zend_string *str = result.value(); const CassError rc = cass_ssl_add_trusted_cert_n(ssl->ssl, ZSTR_VAL(str), ZSTR_LEN(str)); zend_string_release(str); @@ -82,13 +81,11 @@ ZEND_METHOD(Cassandra_SSLOptions_Builder, build) { } if (builder->client_cert) { - auto result = file_get_contents(builder->client_cert); - - if (result.error() == FAILURE) { + zend_string *str = nullptr; + if (file_get_contents(builder->client_cert, &str) == FAILURE) { return; } - zend_string *str = result.value(); const CassError rc = cass_ssl_set_cert_n(ssl->ssl, ZSTR_VAL(str), ZSTR_LEN(str)); zend_string_release(str); if (rc != CASS_OK) { @@ -98,13 +95,12 @@ ZEND_METHOD(Cassandra_SSLOptions_Builder, build) { } if (builder->private_key) { - auto result = file_get_contents(builder->private_key); + zend_string *str = nullptr; - if (result.error() == FAILURE) { + if (file_get_contents(builder->private_key, &str) == FAILURE) { return; } - zend_string *str = result.value(); const CassError rc = cass_ssl_set_cert_n(ssl->ssl, ZSTR_VAL(str), ZSTR_LEN(str)); zend_string_release(str); if (rc != CASS_OK) {