Skip to content

Commit

Permalink
[struct_pack][breakchange][feat] support c++17 (#392)
Browse files Browse the repository at this point in the history
* [struct_pack] remove consteval

* [struct_pack] compatible likely/unlikely

* [struct_pack] don't include tuplet:tuple in cpp17

* [struct_pack] bench/test/examples support cpp17

* [struct_pack] remove spaceship operator for cpp17

* [struct_pack] remove auto in function parameters

* [struct_pack] use void_t/constexpr bool/static_assert to simulate concept when -std=c++17

* [struct_pack]  remove requires

* [struct_pack] remove std::remove_cvref_t

* [struct_pack] remove char8_t

* [struct_pack] remove std::same_as

* [struct_pack][breakchange] use uint64_t to instead struct_pack::serialize_config

* [struct_pack] remove unevaluate inline lambda

* [struct_pack] fix trivially_copyable_container

* [struct_pack] fix struct_pack_benchmark

* [struct_pack] remove default operator ==

* [struct_pack] fix string_literal

* [struct_pack] fix explicit template paramters in lamdba

* [struct_pack] move <bit> header file

* [struct_pack] fix msvc test failed

* [struct_pack] update doc & ci
  • Loading branch information
poor-circle authored Aug 2, 2023
1 parent 57ded70 commit 23d62e7
Show file tree
Hide file tree
Showing 37 changed files with 2,585 additions and 1,771 deletions.
43 changes: 40 additions & 3 deletions .github/workflows/ubuntu_clang.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ubuntu 22.04 (clang)
name: Ubuntu (clang)

on:
push:
Expand Down Expand Up @@ -81,7 +81,7 @@ jobs:
CXX=clang++ CC=clang
cmake -B ${{github.workspace}}/build -G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} -DBUILD_WITH_LIBCXX=${{matrix.libcxx}} -DENABLE_SSL=${{matrix.ssl}} \
-DUSE_CCACHE=${{env.ccache}} \
-DUSE_CCACHE=${{env.ccache}} -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++\
-DBUILD_CORO_HTTP=OFF -DBUILD_CORO_IO=OFF -DBUILD_CORO_RPC=OFF -DBUILD_EASYLOG=OFF -DBUILD_STRUCT_JSON=OFF -DBUILD_STRUCT_XML=OFF -DBUILD_STRUCT_YAML=OFF -DBUILD_UTIL=OFF
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{matrix.mode}}
Expand Down Expand Up @@ -121,12 +121,49 @@ jobs:
-DCMAKE_BUILD_TYPE=${{matrix.mode}} \
-DBUILD_WITH_LIBCXX=${{matrix.libcxx}} \
-DENABLE_IO_URING=${{matrix.io_uring}} \
-DUSE_CCACHE=${{env.ccache}} \
-DUSE_CCACHE=${{env.ccache}} -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++\
-DBUILD_STRUCT_JSON=OFF -DBUILD_STRUCT_XML=OFF -DBUILD_STRUCT_PACK=OFF -DBUILD_STRUCT_PB=OFF -DBUILD_STRUCT_YAML=OFF -DBUILD_UTIL=OFF
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{matrix.mode}}

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.mode}} -j 1 -V

ubuntu_clang10:
strategy:
matrix:
mode: [ Release, Debug ]

runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@master

- name: Install clang-6
run: sudo apt-get install clang-7 clang++-7

- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}-${{ matrix.mode}}

- name: Configure
run: |
CXX=clang++-7 CC=clang-7
cmake -B ${{github.workspace}}/build -G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} \
-DUSE_CCACHE=${{env.ccache}} -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ \
-DENABLE_CPP_20=OFF
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{matrix.mode}}

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.mode}} -j 1 -V
35 changes: 34 additions & 1 deletion .github/workflows/ubuntu_gcc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Ubuntu 22.04 (gcc)
name: Ubuntu (gcc)

on:
push:
Expand Down Expand Up @@ -126,3 +126,36 @@ jobs:
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.mode}} -j 1 -V

ubuntu_gcc9:
strategy:
matrix:
mode: [ Release, Debug ]
runs-on: ubuntu-20.04

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@master

- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}-${{ matrix.mode}}

- name: Configure
run: |
CXX=g++ CC=gcc
cmake -B ${{github.workspace}}/build -G Ninja \
-DCMAKE_BUILD_TYPE=${{matrix.mode}} \
-DUSE_CCACHE=${{env.ccache}} \
-DENABLE_CPP_20=OFF\
- name: Build
run: cmake --build ${{github.workspace}}/build --config ${{matrix.mode}}

- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{matrix.mode}} -j 1 -V
34 changes: 34 additions & 0 deletions .github/workflows/windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,37 @@ jobs:
- name: Test
working-directory: ${{github.workspace}}\build
run: ctest -C ${{matrix.mode}} -j 1 -V
windows_msvc_2019:
runs-on: windows-2019

strategy:
matrix:
mode: [ Release ] #[ Release, Debug ] #Debug not support ccache
#https://github.com/ccache/ccache/wiki/MS-Visual-Studio
#https://github.com/ccache/ccache/issues/1040
arch: [ amd64, x86 ] #[ amd64,x86 ]

steps:
- name: Checkout
uses: actions/checkout@v3
- name: Enable Developer Command Prompt
uses: ilammy/msvc-dev-cmd@v1.12.0
with:
arch: ${{ matrix.arch }}
- name: Install ninja-build tool
uses: seanmiddleditch/gha-setup-ninja@master
with:
version: 1.11.1
- name: latest ccache
run: choco install ccache
- name: ccache
uses: hendrikmuhs/ccache-action@v1.2
with:
key: ${{ github.job }}-${{ matrix.mode}}-arch-${{ matrix.arch}}
- name: Configure CMake
run: cmake -B ${{github.workspace}}\build -G Ninja -DCMAKE_BUILD_TYPE=${{ matrix.mode }} -DENABLE_SSL=${{matrix.ssl}} -DUSE_CCACHE=ON -DENABLE_CPP_20=OFF
- name: Build
run: cmake --build ${{github.workspace}}\build
- name: Test
working-directory: ${{github.workspace}}\build
run: ctest -C ${{matrix.mode}} -j 1 -V
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ include(cmake/install.cmake)
include(cmake/config.cmake)
# add project's source such as unit test, example & benchmark
include(cmake/subdir.cmake)
include(cmake/platform.cmake)

16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

[中文版](./website/docs/zh/guide/what_is_yalantinglibs.md)

yaLanTingLibs is a collection of C++20 libraries, now it contains struct_pack, struct_json, struct_xml, struct_yaml, struct_pb, easylog, coro_rpc, coro_http and async_simple, more and more cool libraries will be added into yaLanTingLibs(such as http.) in the future.
yaLanTingLibs is a collection of modern c++ util libraries, now it contains struct_pack, struct_json, struct_xml, struct_yaml, struct_pb, easylog, coro_rpc, coro_io, coro_http and async_simple, more and more cool libraries will be added into yaLanTingLibs in the future.

The target of yaLanTingLibs: provide very easy and high performance C++20 libraries for C++ developers, it can help to quickly build high performance applications.
The target of yaLanTingLibs: provide very easy and high performance modern C++ libraries for developers, it can help to quickly build high performance applications.

| OS (Compiler Version) | Status |
|------------------------------------------------|-----------------------------------------------------------------------------------------------------------|
Expand All @@ -25,12 +25,22 @@ The target of yaLanTingLibs: provide very easy and high performance C++20 librar
# Quick Start
## compiler requirements

make sure you have such compilers:
If your compiler don't support C++20, yalantinglibs will only compile the serialization libraries (struct_pack, struct_json, struct_xml, struct_yaml).
Make sure you have such compilers:

- g++9 above;
- clang++6 above (with stdlib = libc++-13/libstdc++-8 or later version);
- msvc 14.20 above;

Otherwise, yalantinglibs will compile all the libraries.
Make sure you have such compilers:

- g++10 above;
- clang++13 above (with stdlib = libc++-13/libstdc++-8 or later version);
- msvc 14.29 above;

You can also use cmake option `-DENABLE_CPP_20=ON` or `-DENABLE_CPP_20=OFF` to control it.

## Install & Compile

Yalantinglibs is a head-only library. You can just copy `./include/ylt` directory into your project. But we suggest you use cmake to install it.
Expand Down
25 changes: 20 additions & 5 deletions cmake/build.cmake
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
# Compile Standard
message(STATUS "-------------COMPILE Setting-------------")
set(CMAKE_CXX_STANDARD 20)

# CPP Standard
foreach(i ${CMAKE_CXX_COMPILE_FEATURES})
if (i STREQUAL cxx_std_20)
set(has_cxx_std_20 TRUE)
endif()
endforeach()
if (has_cxx_std_20)
option(ENABLE_CPP_20 "Enable CPP 20" ON)
else ()
option(ENABLE_CPP_20 "Enable CPP 20" OFF)
endif()
if (ENABLE_CPP_20)
set(CMAKE_CXX_STANDARD 20)
else()
set(CMAKE_CXX_STANDARD 17)
endif()
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "CXX Standard: ${CMAKE_CXX_STANDARD}")

# Build Type
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
message(STATUS "Build type: ${CMAKE_BUILD_TYPE}")

# libc++ or libstdc++&clang
option(BUILD_WITH_LIBCXX "Build with libc++" OFF)
message(STATUS "BUILD_WITH_LIBCXX: ${BUILD_WITH_LIBCXX}")
Expand Down Expand Up @@ -42,7 +55,9 @@ endif ()

# --------------------- GCC
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines")
if (ENABLE_CPP_20)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines")
endif()
#-ftree-slp-vectorize with coroutine cause link error. disable it util gcc fix.
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -fno-tree-slp-vectorize")
endif()
Expand Down
15 changes: 0 additions & 15 deletions cmake/platform.cmake

This file was deleted.

16 changes: 15 additions & 1 deletion cmake/subdir.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,23 @@ file(GLOB children src/*)
foreach(child ${children})
get_filename_component(subdir_name ${child} NAME)
string(TOUPPER ${subdir_name} subdir_name)
option(BUILD_${subdir_name} "BUILD_${subdir_name}" ON)
if (ENABLE_CPP_20)
option(BUILD_${subdir_name} "BUILD_${subdir_name}" ON)
else()
option(BUILD_${subdir_name} "BUILD_${subdir_name}" OFF)
endif()
endforeach()

if (NOT ENABLE_CPP_20)
Set(BUILD_STRUCT_PACK ON)
endif()

foreach(child ${children})
get_filename_component(subdir_name ${child} NAME)
string(TOUPPER ${subdir_name} subdir_name)
message(STATUS "BUILD_${subdir_name}: ${BUILD_${subdir_name}}")
endforeach()

foreach(child ${children})
get_filename_component(subdir_name ${child} NAME)
string(TOUPPER ${subdir_name} subdir_name)
Expand Down
Loading

0 comments on commit 23d62e7

Please sign in to comment.