From dada60888fd67f9c7bb6d1ddf962ef2707fecaeb Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Sat, 26 Apr 2025 21:19:23 +0100 Subject: [PATCH 01/14] build: char_traits build fix --- Release/include/cpprest/char_traits.h | 74 +++++++++++++++++++++++++++ Release/include/cpprest/streams.h | 1 + 2 files changed, 75 insertions(+) create mode 100644 Release/include/cpprest/char_traits.h diff --git a/Release/include/cpprest/char_traits.h b/Release/include/cpprest/char_traits.h new file mode 100644 index 0000000000..1e7d172bb0 --- /dev/null +++ b/Release/include/cpprest/char_traits.h @@ -0,0 +1,74 @@ +#include +#include +#include + +namespace std +{ +template<> +struct char_traits +{ + using char_type = uint8_t; + using int_type = unsigned int; + using off_type = std::streamoff; + using pos_type = std::streampos; + using state_type = std::mbstate_t; + + static void assign(char_type& c1, const char_type& c2) noexcept { c1 = c2; } + + static bool eq(char_type c1, char_type c2) noexcept { return c1 == c2; } + + static bool lt(char_type c1, char_type c2) noexcept { return c1 < c2; } + + static int compare(const char_type* s1, const char_type* s2, std::size_t n) noexcept + { + return std::memcmp(s1, s2, n); + } + + static std::size_t length(const char_type* s) noexcept + { + const char_type* p = s; + while (*p != 0) + ++p; + return p - s; + } + + static const char_type* find(const char_type* s, std::size_t n, const char_type& a) noexcept + { + for (std::size_t i = 0; i < n; ++i) + { + if (eq(s[i], a)) + { + return s + i; + } + } + + return nullptr; + } + + static char_type* move(char_type* s1, const char_type* s2, std::size_t n) noexcept + { + return static_cast(std::memmove(s1, s2, n)); + } + + static char_type* copy(char_type* s1, const char_type* s2, std::size_t n) noexcept + { + return static_cast(std::memcpy(s1, s2, n)); + } + + static char_type* assign(char_type* s, std::size_t n, char_type a) noexcept + { + std::fill_n(s, n, a); + return s; + } + + static int_type not_eof(int_type c) noexcept { return c == eof() ? ~eof() : c; } + + static char_type to_char_type(int_type c) noexcept { return static_cast(c); } + + static int_type to_int_type(char_type c) noexcept { return static_cast(c); } + + static bool eq_int_type(int_type c1, int_type c2) noexcept { return c1 == c2; } + + static int_type eof() noexcept { return static_cast(-1); } +}; +} // namespace std diff --git a/Release/include/cpprest/streams.h b/Release/include/cpprest/streams.h index b6c3864028..e505c841ef 100644 --- a/Release/include/cpprest/streams.h +++ b/Release/include/cpprest/streams.h @@ -15,6 +15,7 @@ #ifndef CASA_STREAMS_H #define CASA_STREAMS_H +#include "char_traits.h" #include "cpprest/astreambuf.h" #include #include From 0445cf3701be3c6a22cb779bb0f6b9732d701587 Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Sat, 26 Apr 2025 21:21:48 +0100 Subject: [PATCH 02/14] chore: ignore cmake projects --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 3a3fea4411..3b0af1d3e9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# CMake project files +cmake-build-debug/ +cmake-build-release/ # Visual Studio files *.o *.d From 92e8a80fa5b5e020c195cbdf7f62880235cd8aa0 Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Wed, 21 May 2025 15:47:42 +0100 Subject: [PATCH 03/14] ci: add build-test-all workflow --- .github/workflows/build-test-all.yml | 106 +++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 .github/workflows/build-test-all.yml diff --git a/.github/workflows/build-test-all.yml b/.github/workflows/build-test-all.yml new file mode 100644 index 0000000000..c3c94488e2 --- /dev/null +++ b/.github/workflows/build-test-all.yml @@ -0,0 +1,106 @@ +# This starter workflow is for a CMake project running on multiple platforms. There is a different starter workflow if you just want a single platform. +# See: https://github.com/actions/starter-workflows/blob/main/ci/cmake-single-platform.yml +name: CMake on multiple platforms + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + runs-on: ${{ matrix.os }} + + strategy: + # Set fail-fast to false to ensure that feedback is delivered for all matrix combinations. Consider changing this to true when your workflow is stable. + fail-fast: false + + # Set up a matrix to run the following 3 configurations: + # 1. + # 2. + # 3. + # + # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. + matrix: + #os: [ubuntu-latest, windows-latest] + os: [ubuntu-latest] + build_type: [Debug] + #c_compiler: [gcc, clang, cl] + c_compiler: [clang] +# arch: [x64] + include: +# - os: windows-latest +# c_compiler: clang +# cpp_compiler: clang++ + # - os: ubuntu-latest + # c_compiler: gcc + # cpp_compiler: g++ + - os: ubuntu-latest + c_compiler: clang + cpp_compiler: clang++ + # exclude: + # - os: windows-latest + # c_compiler: gcc + # - os: windows-latest + # c_compiler: clang + # - os: ubuntu-latest + # c_compiler: cl + # # excluded until building for multiple platforms + # - os: windows-latest + # c_compiler: cl + + steps: + - uses: actions/checkout@v4 + + - name: Set reusable strings + # Turn repeated input strings (such as the build output directory) into step outputs. These step outputs can be used throughout the workflow file. + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + +# to use a specific version of cmake? +# - name: Setup cmake +# uses: jwlawson/actions-setup-cmake@v2 +# with: +# cmake-version: '3.16.x' + + - name: Use cmake + run: cmake --version + + - name: Configure CMake + # Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make. + # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -S ${{ github.workspace }} + -G Ninja + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} +# -DCMAKE_SYSTEM_NAME=Linux +# -DCMAKE_SYSTEM_PROCESSOR=x86_64 +# -DARCHITECTURE=${{ matrix.arch }} + + - name: Build + # Build your program with the given configuration. Note that --config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + continue-on-error: true + + - name: Archive production artifacts + uses: actions/upload-artifact@v4 + with: + name: extra-logs + path: | + ./**/*.log + retention-days: 1 + + #- name: Show log + # run: cat /home/runner/work/blackcat/blackcat/build/decimal_for_cpp-prefix/src/decimal_for_cpp-stamp/decimal_for_cpp-configure-Debug.log + + # - name: Test + # working-directory: ${{ steps.strings.outputs.build-output-dir }} + # # Execute tests defined by the CMake configuration. Note that --build-config is needed because the default Windows generator is a multi-config generator (Visual Studio generator). + # # See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail + # run: ctest --build-config ${{ matrix.build_type }} From 577740fd76474d2aed40830a85e53f517c414ecd Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Wed, 21 May 2025 16:04:38 +0100 Subject: [PATCH 04/14] build: add superbuild cmakelists.txt --- superbuild/CMakeLists.txt | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 superbuild/CMakeLists.txt diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt new file mode 100644 index 0000000000..cbf4e66837 --- /dev/null +++ b/superbuild/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.30.5) +project(cpprestsdk-root NONE) + +include(ExternalProject) + +ExternalProject_Add(boost + GIT_REPOSITORY https://github.com/boostorg/boost.git + GIT_TAG boost-1.87.0 + CMAKE_ARGS + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/install + LOG_DOWNLOAD ON + LOG_CONFIGURE ON + LOG_BUILD ON + LOG_INSTALL ON +) + +ExternalProject_Add(cpprestsdk + GIT_REPOSITORY https://github.com/codeavour/cpprestsdk.git + GIT_TAG HEAD + DEPENDS boost + CMAKE_ARGS + -DBUILD_TESTS=OFF # turned off as it generates build errors + -DWERROR=OFF # turned off as there are warnings +# -DCMAKE_CXX_STANDARD=11 + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/install + -DCMAKE_CXX_FLAGS=BOOST_ASIO_NO_DEPRECATED=0 + -DBoost_USE_STATIC_LIBS=ON +# -DBOOST_ASIO_NO_DEPRECATED=OFF # Linux version of cpprestsdk indireclty relies on boost's deprecated IO service + LOG_DOWNLOAD ON + LOG_CONFIGURE ON + LOG_BUILD ON + LOG_INSTALL ON +) \ No newline at end of file From 96361f830affc2ca55d0a73079ce03f69857cb24 Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Wed, 21 May 2025 16:05:08 +0100 Subject: [PATCH 05/14] ci: run from superbuild/cmakelists.txt --- .github/workflows/build-test-all.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-all.yml b/.github/workflows/build-test-all.yml index c3c94488e2..e645852d47 100644 --- a/.github/workflows/build-test-all.yml +++ b/.github/workflows/build-test-all.yml @@ -74,7 +74,7 @@ jobs: # See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type run: > cmake -B ${{ steps.strings.outputs.build-output-dir }} - -S ${{ github.workspace }} + -S ${{ github.workspace }}/superbuild -G Ninja -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} From c1ab00517ce09ac83de9f977a5c34b4eac406edc Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Wed, 21 May 2025 16:12:31 +0100 Subject: [PATCH 06/14] ci: add macos-latest platform --- .github/workflows/build-test-all.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build-test-all.yml b/.github/workflows/build-test-all.yml index e645852d47..2fe39e859c 100644 --- a/.github/workflows/build-test-all.yml +++ b/.github/workflows/build-test-all.yml @@ -23,8 +23,8 @@ jobs: # # To add more build types (Release, Debug, RelWithDebInfo, etc.) customize the build_type list. matrix: - #os: [ubuntu-latest, windows-latest] - os: [ubuntu-latest] + #os: [ubuntu-latest, windows-latest, macos-latest] + os: [macos-latest] build_type: [Debug] #c_compiler: [gcc, clang, cl] c_compiler: [clang] From 40062e2f5b01717b31f097623bfc83e8205a909b Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Wed, 21 May 2025 16:23:58 +0100 Subject: [PATCH 07/14] build: no more specifying CMAKE_CXX_FLAGS --- superbuild/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index cbf4e66837..ed8629695b 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -25,7 +25,7 @@ ExternalProject_Add(cpprestsdk # -DCMAKE_CXX_STANDARD=11 -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/install - -DCMAKE_CXX_FLAGS=BOOST_ASIO_NO_DEPRECATED=0 +# -DCMAKE_CXX_FLAGS=BOOST_ASIO_NO_DEPRECATED=0 -DBoost_USE_STATIC_LIBS=ON # -DBOOST_ASIO_NO_DEPRECATED=OFF # Linux version of cpprestsdk indireclty relies on boost's deprecated IO service LOG_DOWNLOAD ON From 5b82f27aa081ac4d9858b41da9453c9fb7686d26 Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Wed, 21 May 2025 16:25:23 +0100 Subject: [PATCH 08/14] ci: fix --- .github/workflows/build-test-all.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-test-all.yml b/.github/workflows/build-test-all.yml index 2fe39e859c..1e7b2f6cd7 100644 --- a/.github/workflows/build-test-all.yml +++ b/.github/workflows/build-test-all.yml @@ -36,7 +36,7 @@ jobs: # - os: ubuntu-latest # c_compiler: gcc # cpp_compiler: g++ - - os: ubuntu-latest + - os: macos-latest c_compiler: clang cpp_compiler: clang++ # exclude: From 9fc2855ed76c4f4a3ef3d0088f69b8fa5879f5c3 Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Wed, 21 May 2025 16:37:54 +0100 Subject: [PATCH 09/14] build: add openssl external project --- superbuild/CMakeLists.txt | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index ed8629695b..96fd669543 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -3,6 +3,18 @@ project(cpprestsdk-root NONE) include(ExternalProject) +ExternalProject_Add(openssl + GIT_REPOSITORY https://github.com/openssl/openssl.git + GIT_TAG openssl-3.5.0 + CMAKE_ARGS + -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} + -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/install + LOG_DOWNLOAD ON + LOG_CONFIGURE ON + LOG_BUILD ON + LOG_INSTALL ON +) + ExternalProject_Add(boost GIT_REPOSITORY https://github.com/boostorg/boost.git GIT_TAG boost-1.87.0 @@ -18,7 +30,7 @@ ExternalProject_Add(boost ExternalProject_Add(cpprestsdk GIT_REPOSITORY https://github.com/codeavour/cpprestsdk.git GIT_TAG HEAD - DEPENDS boost + DEPENDS openssl boost CMAKE_ARGS -DBUILD_TESTS=OFF # turned off as it generates build errors -DWERROR=OFF # turned off as there are warnings From dfd5315dc3310e75b73c40d0e640351a1a15f7f9 Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Thu, 5 Jun 2025 11:16:09 +0100 Subject: [PATCH 10/14] build: typo --- superbuild/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superbuild/CMakeLists.txt b/superbuild/CMakeLists.txt index 96fd669543..21ed6292d2 100644 --- a/superbuild/CMakeLists.txt +++ b/superbuild/CMakeLists.txt @@ -39,7 +39,7 @@ ExternalProject_Add(cpprestsdk -DCMAKE_INSTALL_PREFIX=${CMAKE_BINARY_DIR}/install # -DCMAKE_CXX_FLAGS=BOOST_ASIO_NO_DEPRECATED=0 -DBoost_USE_STATIC_LIBS=ON -# -DBOOST_ASIO_NO_DEPRECATED=OFF # Linux version of cpprestsdk indireclty relies on boost's deprecated IO service +# -DBOOST_ASIO_NO_DEPRECATED=OFF # Linux version of cpprestsdk indirectly relies on boost's deprecated IO service LOG_DOWNLOAD ON LOG_CONFIGURE ON LOG_BUILD ON From 3d3125239c2e4b1d7363e0acb1cb215507ce89c8 Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Thu, 5 Jun 2025 11:20:17 +0100 Subject: [PATCH 11/14] refactor: stopped leaking boost's header --- Release/include/cpprest/http_client.h | 34 +++++++++++-------------- Release/src/http/client/http_client.cpp | 31 ++++++++++++++++++++++ 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/Release/include/cpprest/http_client.h b/Release/include/cpprest/http_client.h index fb7c6067ab..0dfa27cfc9 100644 --- a/Release/include/cpprest/http_client.h +++ b/Release/include/cpprest/http_client.h @@ -15,6 +15,19 @@ #ifndef CASA_HTTP_CLIENT_H #define CASA_HTTP_CLIENT_H +#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO) +namespace boost +{ +namespace asio +{ +namespace ssl +{ +class context; +} +} +} +#endif + #if defined(__cplusplus_winrt) #if !defined(__WRL_NO_DEFAULT_LIB__) #define __WRL_NO_DEFAULT_LIB__ @@ -60,17 +73,6 @@ typedef void* native_handle; #include "cpprest/oauth2.h" -#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO) -#if defined(__clang__) -#pragma clang diagnostic push -#pragma clang diagnostic ignored "-Wconversion" -#endif -#include "boost/asio/ssl.hpp" -#if defined(__clang__) -#pragma clang diagnostic pop -#endif -#endif - /// The web namespace contains functionality common to multiple protocols like HTTP and WebSockets. namespace web { @@ -368,18 +370,12 @@ class http_client_config /// /// A user callback allowing for customization of the ssl context at construction /// time. - void set_ssl_context_callback(const std::function& callback) - { - m_ssl_context_callback = callback; - } + void set_ssl_context_callback(const std::function& callback); /// /// Gets the user's callback to allow for customization of the ssl context. /// - const std::function& get_ssl_context_callback() const - { - return m_ssl_context_callback; - } + const std::function& get_ssl_context_callback() const; /// /// Gets the TLS extension server name indication (SNI) status. diff --git a/Release/src/http/client/http_client.cpp b/Release/src/http/client/http_client.cpp index 09e3eed15a..116e1e7d3c 100644 --- a/Release/src/http/client/http_client.cpp +++ b/Release/src/http/client/http_client.cpp @@ -17,12 +17,43 @@ #include "http_client_impl.h" +#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO) +#if defined(__clang__) +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wconversion" +#endif +#include "boost/asio/ssl.hpp" +#if defined(__clang__) +#pragma clang diagnostic pop +#endif +#endif + namespace web { namespace http { namespace client { +#if !defined(_WIN32) && !defined(__cplusplus_winrt) || defined(CPPREST_FORCE_HTTP_CLIENT_ASIO) +/// +/// Sets a callback to enable custom setting of the ssl context, at construction time. +/// +/// A user callback allowing for customization of the ssl context at construction +/// time. +void http_client_config::set_ssl_context_callback(const std::function& callback) +{ + m_ssl_context_callback = callback; +} + +/// +/// Gets the user's callback to allow for customization of the ssl context. +/// +const std::function& http_client_config::get_ssl_context_callback() const +{ + return m_ssl_context_callback; +} +#endif + // Helper function to check to make sure the uri is valid. static void verify_uri(const uri& uri) { From 580a07f6ed3557a1b59c3a4fe2c4794f49ca0f55 Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Fri, 6 Jun 2025 17:15:08 +0100 Subject: [PATCH 12/14] build: exposed option to allow building static libs --- Release/CMakeLists.txt | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Release/CMakeLists.txt b/Release/CMakeLists.txt index 14e43cedcd..9b0426482f 100644 --- a/Release/CMakeLists.txt +++ b/Release/CMakeLists.txt @@ -22,12 +22,9 @@ set(CPPREST_EXCLUDE_BROTLI ON CACHE BOOL "Exclude Brotli compression functionali set(CPPREST_EXPORT_DIR cmake/cpprestsdk CACHE STRING "Directory to install CMake config files.") set(CPPREST_INSTALL_HEADERS ON CACHE BOOL "Install header files.") set(CPPREST_INSTALL ON CACHE BOOL "Add install commands.") +set(CPPREST_BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries.") -if(IOS OR ANDROID) - set(BUILD_SHARED_LIBS OFF CACHE BOOL "Build shared libraries") -else() - set(BUILD_SHARED_LIBS ON CACHE BOOL "Build shared libraries") -endif() +set(BUILD_SHARED_LIBS ${CPPREST_BUILD_SHARED_LIBS}) if(IOS OR ANDROID OR WINDOWS_STORE OR WINDOWS_PHONE) set(BUILD_TESTS OFF CACHE BOOL "Build tests.") From 3000b261822e59c220707883028b963b882ccb99 Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Fri, 6 Jun 2025 17:17:42 +0100 Subject: [PATCH 13/14] chore: ignore CLion's files --- .gitignore | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.gitignore b/.gitignore index 3b0af1d3e9..0a61549320 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,10 @@ # CMake project files cmake-build-debug/ cmake-build-release/ +# CLion # +################# +/.idea/* +!/.idea/runConfigurations # Visual Studio files *.o *.d From 1985b00054089b768696d9ca00745d9b88149bd0 Mon Sep 17 00:00:00 2001 From: Ricardo Padrela Date: Fri, 6 Jun 2025 17:18:36 +0100 Subject: [PATCH 14/14] chore: ignore install directory --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 0a61549320..c1c224e1e1 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ +# CMake's installation directory +install/ # CMake project files cmake-build-debug/ cmake-build-release/