Skip to content

Fixed build problems with latest Boost library versions [DEX-431] #1322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 33 additions & 5 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ project(hazelcast-cpp-client
DESCRIPTION "Hazelcast C++ Client"
LANGUAGES CXX)

# Set the C++ standard
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# Generate the Reference_Manual.md file using the latest project version.
Expand Down Expand Up @@ -89,9 +87,29 @@ find_package(Threads REQUIRED)

# find Boost
if (WIN32)
find_package(Boost 1.73 REQUIRED COMPONENTS thread chrono)
find_package(Boost 1.73 CONFIG REQUIRED COMPONENTS thread chrono)
else()
find_package(Boost 1.71 REQUIRED COMPONENTS thread chrono)
find_package(Boost 1.71 CONFIG REQUIRED COMPONENTS thread chrono)
endif()

if (Boost_FOUND)
message(STATUS "Boost version: ${Boost_VERSION}")
message(STATUS "Boost include directory: ${Boost_INCLUDE_DIRS}")
message(STATUS "Boost libraries: ${Boost_LIBRARIES}")

# Check Boost version and set C++ standard accordingly
# Our library can not use a lower C++ standard than the one required by Boost.
if (Boost_VERSION VERSION_LESS 1.70)
set(CMAKE_CXX_STANDARD 11)
elseif (Boost_VERSION VERSION_LESS 1.77)
set(CMAKE_CXX_STANDARD 14)
else()
set(CMAKE_CXX_STANDARD 17) # Boost.JSON, Boost.Process, etc.
endif()

message(STATUS "Required C++ standard: ${CMAKE_CXX_STANDARD}")
else()
message(FATAL_ERROR "Boost not found!")
endif()

# find OpenSSL if building WITH_OPENSSL
Expand All @@ -104,6 +122,14 @@ if (WITH_OPENSSL)
endif ()

find_package(OpenSSL REQUIRED)

if (OpenSSL_FOUND)
message(STATUS "OpenSSL version: ${OpenSSL_VERSION}")
message(STATUS "OpenSSL include directory: ${OPENSSL_INCLUDE_DIR}")
message(STATUS "OpenSSL libraries: ${OPENSSL_LIBRARIES}")
else()
message(FATAL_ERROR "OpenSSL not found!")
endif()
endif ()

# add the library target
Expand Down Expand Up @@ -248,7 +274,9 @@ install(

if (BUILD_TESTS)
add_subdirectory(hazelcast/test)
endif ()
else()
message(STATUS "BUILD_TESTS is disabled.")
endif()

if (BUILD_EXAMPLES)
add_subdirectory(examples)
Expand Down
27 changes: 24 additions & 3 deletions Reference_Manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ Please see [getting started](https://github.com/microsoft/vcpkg#getting-started)
If you use Linux or Mac:

```sh
git clone https://github.com/microsoft/vcpkg --branch 2025.02.14
git clone https://github.com/microsoft/vcpkg
./vcpkg/bootstrap-vcpkg.sh
./vcpkg/vcpkg install "hazelcast-cpp-client[openssl]" --recurse
```

If you use Windows:

```bat
git clone https://github.com/microsoft/vcpkg --branch 2025.02.14
git clone https://github.com/microsoft/vcpkg
.\vcpkg\bootstrap-vcpkg.bat
.\vcpkg\vcpkg install "hazelcast-cpp-client[openssl]:x64-windows" --recurse
```
Expand Down Expand Up @@ -242,7 +242,7 @@ This generates the `conanbuildinfo.cmake` file to be included in your CMakeLists
### 1.1.3. Install From Source Code Using CMake
#### 1.1.3.1. Requirements
1. Linux, macOS or Windows
2. A compiler that supports C++11
2. A compiler that supports C++11 or above: The project detects the minimum C++ standard supported by the Boost library and uses the same language level for compilation.
3. [CMake](https://cmake.org) 3.10 or above
4. [Boost](https://www.boost.org) 1.71 or above. Minimum boost version is upgraded to 1.73 for Windows due to [this](https://github.com/chriskohlhoff/asio/issues/431) bug.
5. [OpenSSL](https://www.openssl.org) (optional)
Expand Down Expand Up @@ -347,6 +347,27 @@ For example:
g++ -DHZ_BUILD_WITH_SSL -DBOOST_CHRONO_DYN_LINK -DBOOST_CHRONO_NO_LIB -DBOOST_THREAD_DYN_LINK -DBOOST_THREAD_NO_LIB -DBOOST_THREAD_VERSION=5 -I/var/git/hazelcast-cpp-client/build/include -std=gnu++11 -c main.cpp
```

##### 1.1.3.5.2. Building the hazelcast-cpp-client library with vcpkg toolchain
If you want to build the `hazelcast-cpp-client` library with vcpkg toolchain, you can use the following command:
```sh
cmake -B build -DCMAKE_TOOLCHAIN_FILE=<path to vcpkg folder>/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Release
```

if you want to build the project with tests and examples enabled, then you can use the following command:
```sh
cmake -b build \
-DBUILD_TESTS=ON \
-DBUILD_EXAMPLES=ON \
-DWITH_OPENSSL=ON \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DCMAKE_TOOLCHAIN_FILE=<path to vcpkg folder>/scripts/buildsystems/vcpkg.cmake \
-DVCPKG_MANIFEST_FEATURES='build-tests' \

cmake --build build
```


## 1.2. Starting a Hazelcast Cluster

The Hazelcast C++ client requires a working Hazelcast cluster to run. This cluster handles storage and manipulation of the user data. Clients are a way to connect to the Hazelcast cluster and access such data.
Expand Down
29 changes: 25 additions & 4 deletions Reference_Manual.md.in
Original file line number Diff line number Diff line change
Expand Up @@ -199,15 +199,15 @@ Please see [getting started](https://github.com/microsoft/vcpkg#getting-started)
If you use Linux or Mac:

```sh
git clone https://github.com/microsoft/vcpkg --branch 2025.02.14
git clone https://github.com/microsoft/vcpkg
./vcpkg/bootstrap-vcpkg.sh
./vcpkg/vcpkg install "hazelcast-cpp-client[openssl]" --recurse
```

If you use Windows:

```bat
git clone https://github.com/microsoft/vcpkg --branch 2025.02.14
git clone https://github.com/microsoft/vcpkg
.\vcpkg\bootstrap-vcpkg.bat
.\vcpkg\vcpkg install "hazelcast-cpp-client[openssl]:x64-windows" --recurse
```
Expand Down Expand Up @@ -242,9 +242,9 @@ This generates the `conanbuildinfo.cmake` file to be included in your CMakeLists
### 1.1.3. Install From Source Code Using CMake
#### 1.1.3.1. Requirements
1. Linux, macOS or Windows
2. A compiler that supports C++11
2. A compiler that supports C++11 or above: The project detects the minimum C++ standard supported by the Boost library and uses the same language level for compilation.
3. [CMake](https://cmake.org) 3.10 or above
4. [Boost](https://www.boost.org) 1.71 or above. Minimum boost version is upgraded to 1.73 for Windows due to [this](https://github.com/chriskohlhoff/asio/issues/431) bug.
4. [Boost](https://www.boost.org) 1.73 or above.
5. [OpenSSL](https://www.openssl.org) (optional)

#### 1.1.3.2. Downloading Source Code
Expand Down Expand Up @@ -347,6 +347,27 @@ For example:
g++ -DHZ_BUILD_WITH_SSL -DBOOST_CHRONO_DYN_LINK -DBOOST_CHRONO_NO_LIB -DBOOST_THREAD_DYN_LINK -DBOOST_THREAD_NO_LIB -DBOOST_THREAD_VERSION=5 -I/var/git/hazelcast-cpp-client/build/include -std=gnu++11 -c main.cpp
```

##### 1.1.3.5.2. Building the hazelcast-cpp-client library with vcpkg toolchain
If you want to build the `hazelcast-cpp-client` library with vcpkg toolchain, you can use the following command:
```sh
cmake -B build -DCMAKE_TOOLCHAIN_FILE=<path to vcpkg folder>/scripts/buildsystems/vcpkg.cmake
cmake --build build --config Release
```

if you want to build the project with tests and examples enabled, then you can use the following command:
```sh
cmake -b build \
-DBUILD_TESTS=ON \
-DBUILD_EXAMPLES=ON \
-DWITH_OPENSSL=ON \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DCMAKE_TOOLCHAIN_FILE=<path to vcpkg folder>/scripts/buildsystems/vcpkg.cmake \
-DVCPKG_MANIFEST_FEATURES='build-tests' \

cmake --build build
```


## 1.2. Starting a Hazelcast Cluster

The Hazelcast C++ client requires a working Hazelcast cluster to run. This cluster handles storage and manipulation of the user data. Clients are a way to connect to the Hazelcast cluster and access such data.
Expand Down
3 changes: 0 additions & 3 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ project (hazelcast-cpp-client-examples
DESCRIPTION "Hazelcast C++ Client Code Examples"
LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if (NOT TARGET hazelcast-cpp-client)
message(STATUS "hazelcast-cpp-client is not a valid target, using find_package to find it.")
find_package(hazelcast-cpp-client REQUIRED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,9 @@ class HAZELCAST_API ClientConnectionManagerImpl
std::unique_ptr<internal::socket::SocketFactory> socket_factory_;
HeartbeatManager heartbeat_;
std::thread io_thread_;
std::unique_ptr<boost::asio::io_context::work> io_guard_;
std::unique_ptr<
boost::asio::executor_work_guard<boost::asio::io_context::executor_type>>
io_guard_;
const bool async_start_;
const config::client_connection_strategy_config::reconnect_mode
reconnect_mode_;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,7 @@ class DefaultNearCache : public NearCache<KS, V>
{
expiration_cancelled_.store(true);
if (expiration_timer_) {
boost::system::error_code ignored;
expiration_timer_->cancel(ignored);
expiration_timer_->cancel();
}
near_cache_record_store_->destroy();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BaseSocket : public hazelcast::client::socket
const std::shared_ptr<connection::Connection> connection) override
{
boost::asio::steady_timer connectTimer(io_);
connectTimer.expires_from_now(connect_timeout_);
connectTimer.expires_after(connect_timeout_);
connectTimer.async_wait([=](const boost::system::error_code& ec) {
if (ec == boost::asio::error::operation_aborted) {
return;
Expand Down Expand Up @@ -117,7 +117,7 @@ class BaseSocket : public hazelcast::client::socket
{
check_connection(connection, invocation);
auto message = invocation->get_client_message();
socket_strand_.post([connection, invocation, message, this]() mutable {
boost::asio::post(socket_strand_, [connection, invocation, message, this]() mutable {
if (!check_connection(connection, invocation)) {
return;
}
Expand Down
22 changes: 13 additions & 9 deletions hazelcast/include/hazelcast/client/protocol/ClientMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
namespace hazelcast {
namespace util {
class ByteBuffer;

template<class T>
struct is_trivial_or_uuid : std::is_trivial<T> {};
template<>
struct is_trivial_or_uuid<boost::uuids::uuid> : std::true_type {};
}

namespace cp {
Expand Down Expand Up @@ -594,7 +599,7 @@ class HAZELCAST_API ClientMessage
std::is_same<std::pair<typename T::value_type::first_type,
typename T::value_type::second_type>,
typename T::value_type>::value &&
std::is_trivial<typename T::value_type::first_type>::value &&
hazelcast::util::is_trivial_or_uuid<typename T::value_type::first_type>::value &&
std::is_trivial<typename T::value_type::second_type>::value,
T>::type
get()
Expand Down Expand Up @@ -625,7 +630,7 @@ class HAZELCAST_API ClientMessage
std::is_same<std::pair<typename T::value_type::first_type,
typename T::value_type::second_type>,
typename T::value_type>::value &&
std::is_trivial<typename T::value_type::first_type>::value &&
hazelcast::util::is_trivial_or_uuid<typename T::value_type::first_type>::value &&
!std::is_trivial<typename T::value_type::second_type>::value,
T>::type
get()
Expand Down Expand Up @@ -1246,12 +1251,11 @@ class HAZELCAST_API ClientMessage
set(nil);
if (!nil) {
boost::endian::endian_reverse_inplace<int64_t>(
*reinterpret_cast<int64_t*>(uuid.data));
*reinterpret_cast<int64_t*>(&uuid.data[0]));
boost::endian::endian_reverse_inplace<int64_t>(
*reinterpret_cast<int64_t*>(uuid.data +
util::Bits::LONG_SIZE_IN_BYTES));
*reinterpret_cast<int64_t*>(&uuid.data[util::Bits::LONG_SIZE_IN_BYTES]));
std::memcpy(wr_ptr(sizeof(boost::uuids::uuid)),
uuid.data,
&uuid.data[0],
sizeof(boost::uuids::uuid));
} else {
wr_ptr(sizeof(boost::uuids::uuid));
Expand Down Expand Up @@ -1525,13 +1529,13 @@ class HAZELCAST_API ClientMessage
boost::uuids::uuid get_uuid()
{
boost::uuids::uuid u;
memcpy(&u.data,
memcpy(&u.data[0],
rd_ptr(sizeof(boost::uuids::uuid)),
sizeof(boost::uuids::uuid));
boost::endian::endian_reverse_inplace<int64_t>(
*reinterpret_cast<int64_t*>(u.data));
*reinterpret_cast<int64_t*>(&u.data[0]));
boost::endian::endian_reverse_inplace<int64_t>(
*reinterpret_cast<int64_t*>(u.data + util::Bits::LONG_SIZE_IN_BYTES));
*reinterpret_cast<int64_t*>(&u.data[util::Bits::LONG_SIZE_IN_BYTES]));
return u;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,27 +91,27 @@ class HAZELCAST_API flake_id_generator_impl : public ProxyImpl
int32_t get_batch_size() const;

class IdIterator
: public std::iterator<std::input_iterator_tag, int64_t>
{
public:
IdIterator();
using iterator_category = std::input_iterator_tag;
using value_type = int64_t;
using difference_type = std::ptrdiff_t;
using pointer = int64_t*;
using reference = int64_t&;

IdIterator();
IdIterator(int64_t base2, int64_t increment, int32_t remaining);

IdIterator& operator++();

bool operator==(const IdIterator& rhs) const;

bool operator!=(const IdIterator& rhs) const;

const int64_t& operator*() { return base2_; }

private:
int64_t base2_;
const int64_t increment_;
int32_t remaining_;
};

IdIterator iterator();

static IdIterator& end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,11 @@ class data_input
{
check_available(util::Bits::UUID_SIZE_IN_BYTES);
boost::uuids::uuid u;
std::memcpy(&u.data, &buffer_[pos_], util::Bits::UUID_SIZE_IN_BYTES);
std::memcpy(&u.data[0], &buffer_[pos_], util::Bits::UUID_SIZE_IN_BYTES);
pos_ += util::Bits::UUID_SIZE_IN_BYTES;
if (byte_order_ == boost::endian::order::little) {
boost::endian::endian_reverse_inplace<int64_t>(
*reinterpret_cast<int64_t*>(u.data));
*reinterpret_cast<int64_t*>(&u.data[0]));
boost::endian::endian_reverse_inplace<int64_t>(
*reinterpret_cast<int64_t*>(
&u.data[util::Bits::LONG_SIZE_IN_BYTES]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ class HAZELCAST_API ClientExecutionServiceImpl
std::shared_ptr<boost::asio::steady_timer> timer)
{
if (delay.count() > 0) {
timer->expires_from_now(delay);
timer->expires_after(delay);
} else {
timer->expires_from_now(period);
timer->expires_after(period);
}

timer->async_wait([=](boost::system::error_code ec) {
Expand Down
17 changes: 1 addition & 16 deletions hazelcast/include/hazelcast/client/spi/impl/ClientInvocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,22 +210,7 @@ class HAZELCAST_API ClientInvocation
const std::string& name,
int partition = UNASSIGNED_PARTITION,
const std::shared_ptr<connection::Connection>& conn = nullptr,
boost::uuids::uuid uuid = { 0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0,
0x0 });
boost::uuids::uuid uuid = {});

void invoke_on_selection();

Expand Down
2 changes: 1 addition & 1 deletion hazelcast/include/hazelcast/util/SyncHttpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HAZELCAST_API SyncHttpClient
private:
std::string server_;
std::string uri_path_;
boost::asio::io_service io_service_;
boost::asio::io_context io_service_;
boost::asio::ip::tcp::socket socket_;
boost::asio::streambuf response_;
std::istream response_stream_;
Expand Down
2 changes: 1 addition & 1 deletion hazelcast/include/hazelcast/util/SyncHttpsClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class HAZELCAST_API SyncHttpsClient
std::chrono::steady_clock::duration timeout_;
std::string secret_removal_;

boost::asio::io_service io_service_;
boost::asio::io_context io_service_;
boost::asio::ip::tcp::resolver resolver_;

boost::asio::ssl::context ssl_context_;
Expand Down
Loading
Loading