Skip to content

Commit

Permalink
Merge pull request he4rt#101 from he4rt/fix/undefined-php-stat-symbol
Browse files Browse the repository at this point in the history
Fixing issue with undefined symbol 'php_stat' -> External C Linking E…
  • Loading branch information
CodeLieutenant authored Jun 19, 2024
2 parents 3cc13a1 + df71b38 commit bfe1bbf
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 58 deletions.
103 changes: 64 additions & 39 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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")

Expand All @@ -40,39 +65,39 @@ 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)
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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions scripts/compile-scylladb.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions scripts/scyladb-driver
Submodule scyladb-driver added at fa0f27
34 changes: 15 additions & 19 deletions src/SSLOptions/Builder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,36 +15,37 @@
*/

#include <SSLOptions/SSLOptions.h>
#include <expected>
#include <utility>

#include <php_driver.h>
#include <php.h>
#include <php_driver_types.h>


static std::expected<zend_string *, zend_result> file_get_contents(const zend_string *path) {
BEGIN_EXTERN_C()
#include <ext/standard/php_filestat.h>

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);
php_stream_close(stream);

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 <ext/standard/php_filestat.h>
return SUCCESS;
}

#include "Builder_arginfo.h"

Expand All @@ -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);

Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit bfe1bbf

Please sign in to comment.