From 81e336f177496e23f6fbbebf2bc3c9f2ba89fab0 Mon Sep 17 00:00:00 2001 From: Mohammad Nejati Date: Sun, 4 Jan 2026 15:02:39 +0000 Subject: [PATCH] C++20 is the minimum --- .drone.star | 6 +- .github/workflows/ci.yml | 325 +++++------------- CMakeLists.txt | 2 +- build/Jamfile | 6 +- doc/modules/ROOT/pages/index.adoc | 7 +- example/client/CMakeLists.txt | 2 +- example/client/burl/CMakeLists.txt | 6 - example/client/burl/Jamfile | 1 - example/client/jsonrpc/CMakeLists.txt | 30 +- example/client/jsonrpc/Jamfile | 13 +- example/client/jsonrpc/cpp11.cpp | 277 --------------- .../client/jsonrpc/{cpp20.cpp => main.cpp} | 0 meta/explicit-failures-markup.xml | 13 +- 13 files changed, 94 insertions(+), 594 deletions(-) delete mode 100644 example/client/jsonrpc/cpp11.cpp rename example/client/jsonrpc/{cpp20.cpp => main.cpp} (100%) diff --git a/.drone.star b/.drone.star index cae42f51..81d36457 100644 --- a/.drone.star +++ b/.drone.star @@ -14,8 +14,8 @@ def main(ctx): return generate( # Compilers [ - 'gcc >=5.0', - 'clang >=3.9', + 'gcc >=10.0', + 'clang >=10.0', 'msvc >=14.1', 'arm64-gcc latest', 's390x-gcc latest', @@ -27,7 +27,7 @@ def main(ctx): 'x86-msvc latest' ], # Standards - '>=11', + '>=20', packages=['zlib1g', 'zlib1g-dev', 'libbrotli-dev']) # from https://github.com/cppalliance/ci-automation diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a4f12931..a85b42df 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -62,33 +62,33 @@ jobs: - compiler: "msvc" version: "14.42" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" runs-on: "windows-2022" b2-toolset: "msvc-14.4" generator: "Visual Studio 17 2022" is-latest: true - name: "MSVC 14.42: C++17-20" + name: "MSVC 14.42: C++20" shared: false build-type: "Release" build-cmake: true - compiler: "msvc" version: "14.34" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" runs-on: "windows-2022" b2-toolset: "msvc-14.3" generator: "Visual Studio 17 2022" is-latest: true - name: "MSVC 14.34: C++17-20" + name: "MSVC 14.34: C++20" shared: true build-type: "Release" build-cmake: true - compiler: "msvc" version: "14.34" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" runs-on: "windows-2022" b2-toolset: "msvc-14.3" @@ -101,13 +101,13 @@ jobs: - compiler: "msvc" version: "14.34" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" runs-on: "windows-2022" b2-toolset: "msvc-14.3" generator: "Visual Studio 17 2022" is-latest: true - name: "MSVC 14.34: C++17-20" + name: "MSVC 14.34: C++20" shared: true build-type: "Release" build-cmake: true @@ -220,7 +220,7 @@ jobs: - compiler: "gcc" version: "15" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-15" cc: "gcc-15" @@ -228,14 +228,14 @@ jobs: container: "ubuntu:25.04" b2-toolset: "gcc" is-latest: true - name: "GCC 15: C++17-20" + name: "GCC 15: C++20" shared: false build-type: "Release" build-cmake: true - compiler: "gcc" version: "15" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-15" cc: "gcc-15" @@ -243,14 +243,14 @@ jobs: container: "ubuntu:25.04" b2-toolset: "gcc" is-latest: true - name: "GCC 15: C++17-20 (no zlib)" + name: "GCC 15: C++20 (no zlib)" shared: true build-type: "Release" build-cmake: true - compiler: "gcc" version: "15" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-15" cc: "gcc-15" @@ -258,7 +258,7 @@ jobs: container: "ubuntu:25.04" b2-toolset: "gcc" is-latest: true - name: "GCC 15: C++17-20 (x86)" + name: "GCC 15: C++20 (x86)" shared: false x86: true build-type: "Release" @@ -266,7 +266,7 @@ jobs: - compiler: "gcc" version: "15" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-15" cc: "gcc-15" @@ -274,14 +274,14 @@ jobs: container: "ubuntu:25.04" b2-toolset: "gcc" is-latest: true - name: "GCC 15: C++17-20" + name: "GCC 15: C++20" shared: true build-type: "Release" build-cmake: true - compiler: "gcc" version: "15" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-15" cc: "gcc-15" @@ -289,7 +289,7 @@ jobs: container: "ubuntu:25.04" b2-toolset: "gcc" is-latest: true - name: "GCC 15: C++17-20 (x86)" + name: "GCC 15: C++20 (x86)" shared: false x86: true build-type: "Release" @@ -298,7 +298,7 @@ jobs: - compiler: "gcc" version: "15" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-15" cc: "gcc-15" @@ -306,14 +306,14 @@ jobs: container: "ubuntu:25.04" b2-toolset: "gcc" is-latest: true - name: "GCC 15: C++17-20 (asan)" + name: "GCC 15: C++20 (asan)" shared: true asan: true build-type: "RelWithDebInfo" - compiler: "gcc" version: "15" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-15" cc: "gcc-15" @@ -321,7 +321,7 @@ jobs: container: "ubuntu:25.04" b2-toolset: "gcc" is-latest: true - name: "GCC 15: C++17-20 (asan, x86)" + name: "GCC 15: C++20 (asan, x86)" shared: false asan: true x86: true @@ -330,7 +330,7 @@ jobs: - compiler: "gcc" version: "15" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-15" cc: "gcc-15" @@ -338,14 +338,14 @@ jobs: container: "ubuntu:25.04" b2-toolset: "gcc" is-latest: true - name: "GCC 15: C++17-20 (ubsan)" + name: "GCC 15: C++20 (ubsan)" shared: false ubsan: true build-type: "RelWithDebInfo" - compiler: "gcc" version: "15" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-15" cc: "gcc-15" @@ -353,7 +353,7 @@ jobs: container: "ubuntu:25.04" b2-toolset: "gcc" is-latest: true - name: "GCC 15: C++17-20 (ubsan, x86)" + name: "GCC 15: C++20 (ubsan, x86)" shared: false ubsan: true x86: true @@ -362,38 +362,38 @@ jobs: - compiler: "gcc" version: "14" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-14" cc: "gcc-14" runs-on: "ubuntu-24.04" b2-toolset: "gcc" - name: "GCC 14: C++17-20" + name: "GCC 14: C++20" shared: true build-type: "Release" - compiler: "gcc" version: "13" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-13" cc: "gcc-13" runs-on: "ubuntu-24.04" b2-toolset: "gcc" - name: "GCC 13: C++17-20" + name: "GCC 13: C++20" shared: true build-type: "Release" - compiler: "gcc" version: "13" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-13" cc: "gcc-13" runs-on: "ubuntu-24.04" b2-toolset: "gcc" is-latest: true - name: "GCC 13: C++17-20 (coverage)" + name: "GCC 13: C++20 (coverage)" shared: false coverage: true build-type: "Debug" @@ -403,106 +403,27 @@ jobs: - compiler: "gcc" version: "12" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-12" cc: "gcc-12" runs-on: "ubuntu-latest" container: "ubuntu:22.04" b2-toolset: "gcc" - name: "GCC 12: C++17-20" + name: "GCC 12: C++20" shared: true build-type: "Release" - compiler: "gcc" version: "11" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "g++-11" cc: "gcc-11" runs-on: "ubuntu-latest" container: "ubuntu:22.04" b2-toolset: "gcc" - name: "GCC 11: C++17-20" - shared: false - build-type: "Release" - - - compiler: "gcc" - version: "10" - cxxstd: "14,17" - latest-cxxstd: "17" - cxx: "g++-10" - cc: "gcc-10" - runs-on: "ubuntu-latest" - container: "ubuntu:20.04" - b2-toolset: "gcc" - name: "GCC 10: C++14-17" - shared: true - build-type: "Release" - - - compiler: "gcc" - version: "9" - cxxstd: "14,17" - latest-cxxstd: "17" - cxx: "g++-9" - cc: "gcc-9" - runs-on: "ubuntu-latest" - container: "ubuntu:20.04" - b2-toolset: "gcc" - name: "GCC 9: C++14-17" - shared: false - build-type: "Release" - - - compiler: "gcc" - version: "8" - cxxstd: "14,17" - latest-cxxstd: "17" - cxx: "g++-8" - cc: "gcc-8" - runs-on: "ubuntu-latest" - container: "ubuntu:20.04" - b2-toolset: "gcc" - name: "GCC 8: C++14-17" - shared: true - build-type: "Release" - - - compiler: "gcc" - version: "7" - cxxstd: "14,17" - latest-cxxstd: "17" - cxx: "g++-7" - cc: "gcc-7" - runs-on: "ubuntu-latest" - container: "ubuntu:20.04" - b2-toolset: "gcc" - name: "GCC 7: C++14-17" - shared: false - build-type: "Release" - - - compiler: "gcc" - version: "6" - cxxstd: "11,14" - latest-cxxstd: "14" - cxx: "g++-6" - cc: "gcc-6" - runs-on: "ubuntu-latest" - container: "ubuntu:18.04" - b2-toolset: "gcc" - name: "GCC 6: C++11-14" - shared: true - build-type: "Release" - - - compiler: "gcc" - version: "5" - cxxstd: "11" - latest-cxxstd: "11" - cxx: "g++-5" - cc: "gcc-5" - runs-on: "ubuntu-latest" - container: "ubuntu:18.04" - b2-toolset: "gcc" - is-earliest: true - name: "GCC 5: C++11" + name: "GCC 11: C++20" shared: false build-type: "Release" @@ -557,7 +478,7 @@ jobs: - compiler: "clang" version: "20" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "clang++-20" cc: "clang-20" @@ -565,14 +486,14 @@ jobs: container: "ubuntu:24.04" b2-toolset: "clang" is-latest: true - name: "Clang 20: C++17-20 (asan)" + name: "Clang 20: C++20 (asan)" shared: false asan: true build-type: "RelWithDebInfo" - compiler: "clang" version: "20" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "clang++-20" cc: "clang-20" @@ -580,7 +501,7 @@ jobs: container: "ubuntu:24.04" b2-toolset: "clang" is-latest: true - name: "Clang 20: C++17-20 (asan, x86)" + name: "Clang 20: C++20 (asan, x86)" shared: true asan: true x86: true @@ -645,31 +566,31 @@ jobs: - compiler: "clang" version: "17" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "clang++-17" cc: "clang-17" runs-on: "ubuntu-24.04" b2-toolset: "clang" - name: "Clang 17: C++17-20" + name: "Clang 17: C++20" shared: false build-type: "Release" - compiler: "clang" version: "16" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "clang++-16" cc: "clang-16" runs-on: "ubuntu-24.04" b2-toolset: "clang" - name: "Clang 16: C++17-20" + name: "Clang 16: C++20" shared: true build-type: "Release" - compiler: "clang" version: "15" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "clang++-15" cc: "clang-15" @@ -682,7 +603,7 @@ jobs: - compiler: "clang" version: "14" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "clang++-14" cc: "clang-14" @@ -695,148 +616,56 @@ jobs: - compiler: "clang" version: "13" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "clang++-13" cc: "clang-13" runs-on: "ubuntu-latest" container: "ubuntu:22.04" b2-toolset: "clang" - name: "Clang 13: C++17-20" + name: "Clang 13: C++20" shared: false build-type: "Release" - compiler: "clang" version: "12" - cxxstd: "17,20" + cxxstd: "20" latest-cxxstd: "20" cxx: "clang++-12" cc: "clang-12" runs-on: "ubuntu-latest" container: "ubuntu:22.04" b2-toolset: "clang" - name: "Clang 12: C++17-20" + name: "Clang 12: C++20" shared: true build-type: "Release" - compiler: "clang" version: "11" - cxxstd: "14,17" - latest-cxxstd: "17" + cxxstd: "20" + latest-cxxstd: "20" cxx: "clang++-11" cc: "clang-11" runs-on: "ubuntu-latest" container: "ubuntu:22.04" b2-toolset: "clang" - name: "Clang 11: C++14-17" + name: "Clang 11: C++20" shared: false build-type: "Release" - compiler: "clang" version: "10" - cxxstd: "14,17" - latest-cxxstd: "17" + cxxstd: "20" + latest-cxxstd: "20" cxx: "clang++-10" cc: "clang-10" runs-on: "ubuntu-latest" container: "ubuntu:20.04" b2-toolset: "clang" - name: "Clang 10: C++14-17" - shared: true - build-type: "Release" - - - compiler: "clang" - version: "9" - cxxstd: "14,17" - latest-cxxstd: "17" - cxx: "clang++-9" - cc: "clang-9" - runs-on: "ubuntu-latest" - container: "ubuntu:20.04" - b2-toolset: "clang" - name: "Clang 9: C++14-17" - shared: false - build-type: "Release" - - - compiler: "clang" - version: "8" - cxxstd: "14,17" - latest-cxxstd: "17" - cxx: "clang++-8" - cc: "clang-8" - runs-on: "ubuntu-latest" - container: "ubuntu:20.04" - b2-toolset: "clang" - name: "Clang 8: C++14-17" - shared: true - build-type: "Release" - - - compiler: "clang" - version: "7" - cxxstd: "14,17" - latest-cxxstd: "17" - cxx: "clang++-7" - cc: "clang-7" - runs-on: "ubuntu-latest" - container: "ubuntu:20.04" - b2-toolset: "clang" - name: "Clang 7: C++14-17" - shared: false - build-type: "Release" - - - compiler: "clang" - version: "6" - cxxstd: "14,17" - latest-cxxstd: "17" - cxx: "clang++-6.0" - cc: "clang-6.0" - runs-on: "ubuntu-latest" - container: "ubuntu:20.04" - b2-toolset: "clang" - name: "Clang 6: C++14-17" - shared: true - build-type: "Release" - - - compiler: "clang" - version: "5" - cxxstd: "11,14" - latest-cxxstd: "14" - cxx: "clang++-5.0" - cc: "clang-5.0" - runs-on: "ubuntu-latest" - container: "ubuntu:18.04" - b2-toolset: "clang" - name: "Clang 5: C++11-14" - shared: false - build-type: "Release" - - - compiler: "clang" - version: "4" - cxxstd: "11,14" - latest-cxxstd: "14" - cxx: "clang++-4.0" - cc: "clang-4.0" - runs-on: "ubuntu-latest" - container: "ubuntu:18.04" - b2-toolset: "clang" - name: "Clang 4: C++11-14" + name: "Clang 10: C++20" shared: true build-type: "Release" - - compiler: "clang" - version: "3.9" - cxxstd: "11" - latest-cxxstd: "11" - cxx: "clang++-3.9" - cc: "clang-3.9" - runs-on: "ubuntu-latest" - container: "ubuntu:18.04" - b2-toolset: "clang" - is-earliest: true - name: "Clang 3.9: C++11" - shared: false - build-type: "Release" - name: ${{ matrix.name }} runs-on: ${{ fromJSON(needs.runner-selection.outputs.labelmatrix)[matrix.runs-on] }} container: @@ -1101,28 +930,28 @@ jobs: ref-source-dir: boost-root/libs/beast2/test/cmake_test toolchain: ${{ (startsWith(matrix.runs-on, 'windows') && steps.patch-user-config.outputs.toolchain) || '' }} - - name: Root Project CMake Workflow - uses: alandefreitas/cpp-actions/cmake-workflow@v1.9.0 - if: ${{ matrix.build-cmake || matrix.is-earliest }} - with: - source-dir: boost-root/libs/${{ steps.patch.outputs.module }} - build-dir: __build_root_test__ - run-tests: true - generator: ${{ matrix.generator }} - generator-toolset: ${{ matrix.generator-toolset }} - build-type: ${{ matrix.build-type }} - install: false - cxxstd: ${{ matrix.latest-cxxstd }} - cc: ${{ steps.setup-cpp.outputs.cc || matrix.cc }} - ccflags: ${{ matrix.ccflags }} - cxx: ${{ steps.setup-cpp.outputs.cxx || matrix.cxx }} - cxxflags: ${{ matrix.cxxflags }} - shared: ${{ matrix.shared }} - cmake-version: '>=3.20' - package: false - package-artifact: false - ref-source-dir: boost-root - toolchain: ${{ (startsWith(matrix.runs-on, 'windows') && steps.patch-user-config.outputs.toolchain) || '' }} + # - name: Root Project CMake Workflow + # uses: alandefreitas/cpp-actions/cmake-workflow@v1.9.0 + # if: ${{ matrix.build-cmake || matrix.is-earliest }} + # with: + # source-dir: boost-root/libs/${{ steps.patch.outputs.module }} + # build-dir: __build_root_test__ + # run-tests: true + # generator: ${{ matrix.generator }} + # generator-toolset: ${{ matrix.generator-toolset }} + # build-type: ${{ matrix.build-type }} + # install: false + # cxxstd: ${{ matrix.latest-cxxstd }} + # cc: ${{ steps.setup-cpp.outputs.cc || matrix.cc }} + # ccflags: ${{ matrix.ccflags }} + # cxx: ${{ steps.setup-cpp.outputs.cxx || matrix.cxx }} + # cxxflags: ${{ matrix.cxxflags }} + # shared: ${{ matrix.shared }} + # cmake-version: '>=3.20' + # package: false + # package-artifact: false + # ref-source-dir: boost-root + # toolchain: ${{ (startsWith(matrix.runs-on, 'windows') && steps.patch-user-config.outputs.toolchain) || '' }} - name: FlameGraph uses: alandefreitas/cpp-actions/flamegraph@v1.9.0 diff --git a/CMakeLists.txt b/CMakeLists.txt index f73fe086..e1162fc2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,7 +151,7 @@ source_group(TREE ${CMAKE_CURRENT_SOURCE_DIR}/src PREFIX "src" FILES ${BOOST_BEA function(boost_beast2_setup_properties target) - target_compile_features(${target} PUBLIC cxx_constexpr) + target_compile_features(${target} PUBLIC cxx_std_20) target_include_directories(${target} PUBLIC "${PROJECT_SOURCE_DIR}/include" PRIVATE "${PROJECT_SOURCE_DIR}") diff --git a/build/Jamfile b/build/Jamfile index e2870fba..af54ac18 100644 --- a/build/Jamfile +++ b/build/Jamfile @@ -11,11 +11,7 @@ import config : requires ; constant c11-requires : [ requires - cxx11_constexpr - cxx11_decltype - cxx11_hdr_tuple - cxx11_template_aliases - cxx11_variadic_templates + cxx20_hdr_coroutine ] ; diff --git a/doc/modules/ROOT/pages/index.adoc b/doc/modules/ROOT/pages/index.adoc index 1c7dc9e7..8181191a 100644 --- a/doc/modules/ROOT/pages/index.adoc +++ b/doc/modules/ROOT/pages/index.adoc @@ -14,13 +14,12 @@ This is a portable C++ library which implements the HTTP/1 protocol using Boost.HTTP.Proto and Boost.Asio. The library is distinguished by these provided features: -* Require only C++11 * Works without exceptions * Fast compilation, few templates == Requirements -* Requires Boost and a compiler supporting at least C++11 +* Requires Boost and a compiler supporting at least C++20 * Link to a static or dynamically linked version of this library * Supports `-fno-exceptions`, detected automatically @@ -28,8 +27,8 @@ provided features: Boost.Buffers has been tested with the following compilers: -* gcc: 5 to 14 (except 8.0.1) -* clang: 3.9, 4 to 18 +* gcc: 10 to 15 +* clang: 11 to 20 * msvc: 14.1 to 14.42 == Quality Assurance diff --git a/example/client/CMakeLists.txt b/example/client/CMakeLists.txt index 7bf9965f..6ec818ed 100644 --- a/example/client/CMakeLists.txt +++ b/example/client/CMakeLists.txt @@ -12,7 +12,7 @@ find_package(OpenSSL) add_subdirectory(visit) if (OPENSSL_FOUND) - add_subdirectory(burl) + # add_subdirectory(burl) add_subdirectory(get) add_subdirectory(jsonrpc) endif () diff --git a/example/client/burl/CMakeLists.txt b/example/client/burl/CMakeLists.txt index f31650dd..921ecea6 100644 --- a/example/client/burl/CMakeLists.txt +++ b/example/client/burl/CMakeLists.txt @@ -7,10 +7,6 @@ # Official repository: https://github.com/cppalliance/beast2 # -if(NOT cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES) - return() -endif() - file(GLOB_RECURSE PFILES CONFIGURE_DEPENDS *.cpp *.hpp CMakeLists.txt Jamfile) @@ -27,8 +23,6 @@ set_property(TARGET beast2_example_client_burl find_package(OpenSSL REQUIRED) -target_compile_features(beast2_example_client_burl PUBLIC cxx_std_20) - target_link_libraries(beast2_example_client_burl Boost::beast2 Boost::url diff --git a/example/client/burl/Jamfile b/example/client/burl/Jamfile index b342c0ee..666382f1 100644 --- a/example/client/burl/Jamfile +++ b/example/client/burl/Jamfile @@ -20,7 +20,6 @@ lib user32 ; project : requirements [ requires - cxx20_hdr_concepts cxx20_hdr_format ] /boost/beast2//boost_beast2 diff --git a/example/client/jsonrpc/CMakeLists.txt b/example/client/jsonrpc/CMakeLists.txt index 462095f5..998f4895 100644 --- a/example/client/jsonrpc/CMakeLists.txt +++ b/example/client/jsonrpc/CMakeLists.txt @@ -7,10 +7,6 @@ # Official repository: https://github.com/cppalliance/beast2 # -if(NOT cxx_std_20 IN_LIST CMAKE_CXX_COMPILE_FEATURES) - return() -endif() - file(GLOB_RECURSE PFILES CONFIGURE_DEPENDS *.cpp *.hpp CMakeLists.txt Jamfile) @@ -41,31 +37,15 @@ if (WIN32) target_link_libraries(beast2_example_client_jsonrpc_lib PUBLIC crypt32) endif() -# CPP11 Example -add_executable(beast2_example_client_jsonrpc_cpp11 cpp11.cpp eth_methods.hpp Jamfile) -set_property(TARGET beast2_example_client_jsonrpc_cpp11 - PROPERTY FOLDER "examples") -target_link_libraries(beast2_example_client_jsonrpc_cpp11 - PRIVATE - beast2_example_client_jsonrpc_lib) -if (TARGET Boost::capy_zlib) - target_link_libraries(beast2_example_client_jsonrpc_cpp11 PRIVATE Boost::capy_zlib) -endif() -if (TARGET Boost::capy_brotli) - target_link_libraries(beast2_example_client_jsonrpc_cpp11 PRIVATE Boost::capy_brotli) -endif() - -# CPP20 Example -add_executable(beast2_example_client_jsonrpc_cpp20 cpp20.cpp eth_methods.hpp Jamfile) -set_property(TARGET beast2_example_client_jsonrpc_cpp20 +add_executable(beast2_example_client_jsonrpc main.cpp eth_methods.hpp Jamfile) +set_property(TARGET beast2_example_client_jsonrpc PROPERTY FOLDER "examples") -target_compile_features(beast2_example_client_jsonrpc_cpp20 PUBLIC cxx_std_20) -target_link_libraries(beast2_example_client_jsonrpc_cpp20 +target_link_libraries(beast2_example_client_jsonrpc PRIVATE beast2_example_client_jsonrpc_lib) if (TARGET Boost::capy_zlib) - target_link_libraries(beast2_example_client_jsonrpc_cpp20 PRIVATE Boost::capy_zlib) + target_link_libraries(beast2_example_client_jsonrpc PRIVATE Boost::capy_zlib) endif() if (TARGET Boost::capy_brotli) - target_link_libraries(beast2_example_client_jsonrpc_cpp20 PRIVATE Boost::capy_brotli) + target_link_libraries(beast2_example_client_jsonrpc PRIVATE Boost::capy_brotli) endif() diff --git a/example/client/jsonrpc/Jamfile b/example/client/jsonrpc/Jamfile index 8cf688b9..e828aa44 100644 --- a/example/client/jsonrpc/Jamfile +++ b/example/client/jsonrpc/Jamfile @@ -33,16 +33,7 @@ project . ; -exe cpp11 : - cpp11.cpp +exe jsonrpc_example : + main.cpp [ glob jsonrpc/*.cpp ] ; - -exe cpp20 : - cpp20.cpp - [ glob jsonrpc/*.cpp ] - : requirements - [ requires - cxx20_hdr_coroutine - ] - ; diff --git a/example/client/jsonrpc/cpp11.cpp b/example/client/jsonrpc/cpp11.cpp deleted file mode 100644 index 8bfa32bb..00000000 --- a/example/client/jsonrpc/cpp11.cpp +++ /dev/null @@ -1,277 +0,0 @@ -// -// Copyright (c) 2025 Mohammad Nejati -// -// Distributed under the Boost Software License, Version 1.0. (See accompanying -// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -// -// Official repository: https://github.com/cppalliance/beast2 -// - -#include "jsonrpc/client.hpp" - -#include "eth_methods.hpp" - -#include -#include -#include -#include - -#include -#include - -using namespace boost; -using namespace std::placeholders; - -// Bring Ethereum methods into scope -using namespace eth_methods; - -class session -{ - jsonrpc::client client_; - -public: - session( - asio::io_context& ioc, - asio::ssl::context& ssl_ctx, - capy::polystore& ctx) - : client_( - urls::url("https://ethereum.publicnode.com"), - ctx, - ioc.get_executor(), - ssl_ctx) - { - } - - void - run() - { - // Set the user agent - client_.http_fields().set( - http_proto::field::user_agent, "Boost.Http.Io"); - - // Connect to the endpoint - client_.async_connect( - std::bind(&session::on_connect, this, _1)); - } - -private: - void - on_connect(system::error_code ec) - { - if(ec) - return fail(ec, "connect"); - - // Get Ethereum node client software and version - client_.async_call( - web3_clientVersion, - std::bind(&session::on_clientVersion, this, _1, _2)); - } - - void - on_clientVersion( - jsonrpc::error error, json::string version) - { - if(error.code()) - return fail(error); - - std::cout - << "web3 client: " - << version << '\n'; - - // Get the latest block number - client_.async_call( - eth_blockNumber, - std::bind(&session::on_blockNumber, this, _1, _2)); - } - - void - on_blockNumber( - jsonrpc::error error, json::string block_num) - { - if(error.code()) - return fail(error); - - std::cout - << "Block height: " - << block_num << '\n'; - - // Get block details - client_.async_call( - eth_getBlockByNumber, - { block_num, false }, - std::bind(&session::on_getBlockByNumber, this, _1, _2)); - } - - void - on_getBlockByNumber( - jsonrpc::error error, json::object block) - { - if(error.code()) - return fail(error); - - std::cout<< "Block hash: " << block["hash"] << '\n'; - std::cout<< "Block size: " << block["size"] << " Bytes\n"; - std::cout<< "Timestamp: " << block["timestamp"] << '\n'; - std::cout<< "Transactions: " << block["transactions"].as_array().size() << '\n'; - - // Get account balance - client_.async_call( - eth_getBalance, - { - "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae", - block["number"] - }, - std::bind(&session::on_getBalance, this, _1, _2)); - } - - void - on_getBalance( - jsonrpc::error error, json::string balance) - { - if(error.code()) - return fail(error); - - std::cout - << "Balance: " - << balance << '\n'; - - // Estimate gas for a transfer - client_.async_call( - eth_estimateGas, - { - json::object - { - { "from", "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae" }, - { "to", "0x281055afc982d96fab65b3a49cac8b878184cb16" }, - { "value", "0x2386F26FC10000" } // 0.01 ETH in wei - } - }, - std::bind(&session::on_estimateGas, this, _1, _2)); - } - - void - on_estimateGas( - jsonrpc::error error, json::string gas_estimate) - { - if(error.code()) - return fail(error); - - std::cout - << "Gas estimate: " - << gas_estimate << '\n'; - - // Get the current gas price - client_.async_call( - eth_gasPrice, - std::bind(&session::on_gasPrice, this, _1, _2)); - } - - void - on_gasPrice( - jsonrpc::error error, json::string gas_price) - { - if(error.code()) - return fail(error); - - std::cout - << "Gas price: " - << gas_price << '\n'; - - // Gracefully close the stream - client_.async_shutdown( - std::bind(&session::on_shutdown, this, _1)); - } - - void - on_shutdown(system::error_code ec) - { - if(ec && ec != asio::ssl::error::stream_truncated) - return fail(ec, "shutdown"); - } - - static - void - fail(system::error_code ec, const char* operation) - { - std::cerr - << operation << ": " - << ec.message() << "\n"; - } - - static - void - fail(const jsonrpc::error& error) - { - if(!error.info().empty()) - std::cerr << error.info() << " "; - std::cerr << error.code().what() << "\n"; - } -}; - -/* -Sample output: - -web3 client: "erigon/3.0.4/linux-amd64/go1.23.9" -Block height: "0x161a027" -Block hash: "0xe35f0fb6199e295ff7ba864b034fbbcf3f722b089cf5fe18181f5a83352b2645" -Block size: "0x1604d" Bytes -Timestamp: "0x68a47207" -Transactions: 201 -Balance: "0x2647cc23d6974bdb8179" -Gas estimate: "0x5208" -Gas price: "0x1c9ad53b" -*/ - -int -main(int, char*[]) -{ - try - { - // The io_context is required for all I/O - asio::io_context ioc; - - // The SSL context is required, and holds certificates - asio::ssl::context ssl_ctx(asio::ssl::context::tls_client); - - // holds optional deflate and - // required configuration services - capy::polystore capy_ctx; - - // Install parser service - { - http_proto::response_parser::config cfg; - cfg.min_buffer = 64 * 1024; - #ifdef BOOST_CAPY_HAS_BROTLI - cfg.apply_brotli_decoder = true; - capy::brotli::install_decode_service(capy_ctx); - #endif - #ifdef BOOST_CAPY_HAS_ZLIB - cfg.apply_deflate_decoder = true; - cfg.apply_gzip_decoder = true; - capy::zlib::install_inflate_service(capy_ctx); - #endif - http_proto::install_parser_service(capy_ctx, cfg); - } - - // Install serializer service with default configuration - http_proto::install_serializer_service(capy_ctx, {}); - - // Root certificates used for verification - ssl_ctx.set_default_verify_paths(); - - // Verify the remote server's certificate - ssl_ctx.set_verify_mode(asio::ssl::verify_peer); - - session s(ioc, ssl_ctx, capy_ctx); - s.run(); - - ioc.run(); - - return EXIT_SUCCESS; - } - catch(const std::exception& e) - { - std::cerr << "Error: " << e.what() << std::endl; - return EXIT_FAILURE; - } -} diff --git a/example/client/jsonrpc/cpp20.cpp b/example/client/jsonrpc/main.cpp similarity index 100% rename from example/client/jsonrpc/cpp20.cpp rename to example/client/jsonrpc/main.cpp diff --git a/meta/explicit-failures-markup.xml b/meta/explicit-failures-markup.xml index bc7abccb..5422b7cd 100644 --- a/meta/explicit-failures-markup.xml +++ b/meta/explicit-failures-markup.xml @@ -3,18 +3,7 @@ - - - - - - - - - - - - C++11 is the minimum requirement. + C++20 is the minimum requirement.