From 38d5537be1e991a8b630881912682a06fdfaab79 Mon Sep 17 00:00:00 2001 From: levalup Date: Mon, 1 Jul 2024 19:13:18 +0800 Subject: [PATCH] update test workflows and related codes. --- .github/workflows/build-gcc.yml | 62 ++++++++++++++ .github/workflows/build-macos.yml | 61 ++++++++++++++ .github/workflows/build-mingw.yml | 74 ++++++++++++++++ .github/workflows/build.yml | 125 +++++++++------------------- .github/workflows/single-header.yml | 62 ++++++++++++++ README.md | 9 ++ include/uvcxx.h | 22 +++++ include/uvcxx/os.h | 4 +- tests/attch.cpp | 6 +- tests/bufs.cpp | 4 +- tests/callback.cpp | 4 +- tests/close_handle.cpp | 3 +- tests/move-base-1.cpp | 3 +- tests/move-base-2.cpp | 3 +- tests/move-base-3/struct.h | 3 +- tests/mutex.cpp | 6 +- tests/promise.cpp | 3 +- tests/ref.cpp | 7 +- tests/strings.cpp | 3 +- tests/tuple_value.cpp | 3 +- 20 files changed, 345 insertions(+), 122 deletions(-) create mode 100644 .github/workflows/build-gcc.yml create mode 100644 .github/workflows/build-macos.yml create mode 100644 .github/workflows/build-mingw.yml create mode 100644 .github/workflows/single-header.yml diff --git a/.github/workflows/build-gcc.yml b/.github/workflows/build-gcc.yml new file mode 100644 index 0000000..4d3a51c --- /dev/null +++ b/.github/workflows/build-gcc.yml @@ -0,0 +1,62 @@ +name: Build Multi-GCC + +on: + push: + branches: + - master + - develop + + pull_request: + branches: + - master + - develop + +jobs: + build-gcc: + if: >- + ! contains(toJSON(github.event.commits.*.message), '[skip ci]') && + ! contains(toJSON(github.event.commits.*.message), '[skip github]') + + runs-on: ubuntu-latest + + strategy: + fail-fast: false + + matrix: + gcc_version: ['latest', '12', '11', '10', '9', '8', '7', '6', '5', '4.8.5'] + build_type: [Release] + + name: "In Container GCC ${{matrix.gcc_version}} ${{matrix.build_type}}" + + container: + image: gcc:${{matrix.gcc_version}} + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: friendlyanon/fetch-core-count@v1 + id: cores + + - name: Set output + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure + run: >- + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build + run: >- + cmake --build ${{ steps.strings.outputs.build-output-dir }} + --config ${{ matrix.build_type }} + -- -j ${{steps.cores.outputs.count}} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: ctest --output-on-failure --build-config ${{ matrix.build_type }} diff --git a/.github/workflows/build-macos.yml b/.github/workflows/build-macos.yml new file mode 100644 index 0000000..fd17e6d --- /dev/null +++ b/.github/workflows/build-macos.yml @@ -0,0 +1,61 @@ +name: Build MacOS + +on: + push: + branches: + - master + - develop + + pull_request: + branches: + - master + - develop + +jobs: + build-macos: + if: >- + ! contains(toJSON(github.event.commits.*.message), '[skip ci]') && + ! contains(toJSON(github.event.commits.*.message), '[skip github]') + + runs-on: ${{matrix.os}} + + strategy: + matrix: + os: [ 'macos-14.5' ] + xcode: [ '15.4' ] + build_type: [ Release ] + + env: + DEVELOPER_DIR: /Applications/Xcode_${{matrix.xcode}}.app/Contents/Developer + + name: "On ${{matrix.os}} Xcode ${{matrix.xcode}} ${{matrix.build_type}}" + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: friendlyanon/fetch-core-count@v1 + id: cores + + - name: Set output + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure + run: >- + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build + run: >- + cmake --build ${{ steps.strings.outputs.build-output-dir }} + --config ${{ matrix.build_type }} + -- -j ${{steps.cores.outputs.count}} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: ctest --output-on-failure --build-config ${{ matrix.build_type }} diff --git a/.github/workflows/build-mingw.yml b/.github/workflows/build-mingw.yml new file mode 100644 index 0000000..d4cd5c8 --- /dev/null +++ b/.github/workflows/build-mingw.yml @@ -0,0 +1,74 @@ +name: Build MinGW + +on: + push: + branches: + - master + - develop + + pull_request: + branches: + - master + - develop + +jobs: + build-mingw: + if: >- + ! contains(toJSON(github.event.commits.*.message), '[skip ci]') && + ! contains(toJSON(github.event.commits.*.message), '[skip github]') + + runs-on: ${{matrix.os}} + + defaults: + run: + shell: msys2 {0} + + strategy: + fail-fast: false + + matrix: + os: [ windows-latest ] + build_type: [ Release ] + config: + - msystem: "MINGW64" + install: >- + git mingw-w64-x86_64-cmake + mingw-w64-x86_64-gcc mingw-w64-x86_64-g++ + mingw-w64-x86_64-ninja + + name: "On ${{matrix.os}} ${{matrix.config.msystem}} ${{matrix.build_type}}" + + env: + CMAKE_GENERATOR: 'Ninja' + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: msys2/setup-msys2@v2 + with: + update: true + msystem: ${{matrix.config.msystem}} + install: ${{matrix.config.install}} + + - name: Set output + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Configure + run: >- + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build + run: >- + cmake --build ${{ steps.strings.outputs.build-output-dir }} + --config ${{ matrix.build_type }} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: ctest --output-on-failure --build-config ${{ matrix.build_type }} diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bccd9d0..a8d8581 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -4,138 +4,91 @@ name: Build on: push: - branches: [ "master" ] - tags: - - 'r*' + branches: + - master + - develop + pull_request: - branches: [ "master" ] + branches: + - master + - develop jobs: build: + if: >- + ! contains(toJSON(github.event.commits.*.message), '[skip ci]') && + ! contains(toJSON(github.event.commits.*.message), '[skip github]') + 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 4 configurations: - # 1. - # 2. - # 3. - # 4. + # 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] - c_compiler: [gcc, clang, cl] build_type: [Release] + c_compiler: [gcc, clang, cl] include: + - os: windows-latest + c_compiler: cl + cpp_compiler: cl - os: ubuntu-latest c_compiler: gcc cpp_compiler: g++ - cmake_generator: '' - os: ubuntu-latest c_compiler: clang cpp_compiler: clang++ - cmake_generator: '' - - os: windows-latest - c_compiler: cl - cpp_compiler: cl - cmake_generator: '' + exclude: - os: windows-latest c_compiler: gcc - cpp_compiler: g++ - cmake_generator: 'MinGW Makefiles' - exclude: - os: windows-latest c_compiler: clang - os: ubuntu-latest c_compiler: cl - steps: - - uses: actions/checkout@v4 - with: - submodules: recursive - - - 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" - - - name: Install MinGW (Windows) - if: matrix.os == 'windows-latest' && matrix.cmake_generator == 'MinGW Makefiles' - run: | - choco install mingw --force -y - echo "C:\tools\mingw64\bin" >> $GITHUB_PATH - - - 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 - if: matrix.cmake_generator == '' - run: > - cmake -B ${{ steps.strings.outputs.build-output-dir }} - -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} - -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -S ${{ github.workspace }} - - - name: Configure CMake With Generator - if: matrix.cmake_generator != '' - run: > - cmake -B ${{ steps.strings.outputs.build-output-dir }} - -G "${{ matrix.cmake_generator }}" - -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} - -S ${{ github.workspace }} - - - 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 }} - - - 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 }} - - build-gcc: - runs-on: ubuntu-latest - - strategy: - fail-fast: false - - matrix: - gcc_version: [9, 10, 11, 12] - build_type: [Release] + name: "On ${{matrix.os}} ${{matrix.c_compiler}} ${{matrix.build_type}}" steps: - uses: actions/checkout@v4 with: submodules: recursive - - name: Set reusable strings + - uses: friendlyanon/fetch-core-count@v1 + id: cores + + - name: Set output + # 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" - - name: Install GCC ${{ matrix.gcc_version }} - run: | - sudo apt-get update - sudo apt-get install -y gcc-${{ matrix.gcc_version }} g++-${{ matrix.gcc_version }} - - - name: Configure CMake + - name: Configure + # 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 }} - -DCMAKE_CXX_COMPILER=g++-${{ matrix.gcc_version }} - -DCMAKE_C_COMPILER=gcc-${{ matrix.gcc_version }} + -DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }} + -DCMAKE_C_COMPILER=${{ matrix.c_compiler }} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -S ${{ github.workspace }} - name: Build - run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} + # 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 }} + -- -j ${{steps.cores.outputs.count}} - name: Test working-directory: ${{ steps.strings.outputs.build-output-dir }} - run: ctest --build-config ${{ matrix.build_type }} + # 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 --output-on-failure --build-config ${{ matrix.build_type }} diff --git a/.github/workflows/single-header.yml b/.github/workflows/single-header.yml new file mode 100644 index 0000000..15ac7fa --- /dev/null +++ b/.github/workflows/single-header.yml @@ -0,0 +1,62 @@ +name: Single Header + +on: + push: + branches: + - master + - develop + + pull_request: + branches: + - master + - develop + +jobs: + single-header: + if: >- + ! contains(toJSON(github.event.commits.*.message), '[skip ci]') && + ! contains(toJSON(github.event.commits.*.message), '[skip github]') + + runs-on: ${{matrix.os}} + + strategy: + fail-fast: false + + matrix: + os: [ubuntu-latest] + build_type: [Release] + + name: "Generate Single Header ${{matrix.build_type}}" + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + + - uses: friendlyanon/fetch-core-count@v1 + id: cores + + - name: Set output + id: strings + shell: bash + run: | + echo "build-output-dir=${{ github.workspace }}/build" >> "$GITHUB_OUTPUT" + + - name: Generate single header + run: python3 scripts/merge.py include/uvcxx.h + + - name: Configure + run: > + cmake -B ${{ steps.strings.outputs.build-output-dir }} + -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} + -S ${{ github.workspace }} + + - name: Build + run: >- + cmake --build ${{ steps.strings.outputs.build-output-dir }} + --config ${{ matrix.build_type }} + -- -j ${{steps.cores.outputs.count}} + + - name: Test + working-directory: ${{ steps.strings.outputs.build-output-dir }} + run: ctest --output-on-failure --build-config ${{ matrix.build_type }} diff --git a/README.md b/README.md index c2849bb..2ba8670 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,15 @@ [![Build](https://github.com/levalup/libuvcxx/actions/workflows/build.yml/badge.svg)]( https://github.com/levalup/libuvcxx/actions/workflows/build.yml) +[![Build Multi-GCC](https://github.com/levalup/libuvcxx/actions/workflows/build-gcc.yml/badge.svg)]( + https://github.com/levalup/libuvcxx/actions/workflows/build-gcc.yml) +[![Build MacOS](https://github.com/levalup/libuvcxx/actions/workflows/build-macos.yml/badge.svg)]( + https://github.com/levalup/libuvcxx/actions/workflows/build-macos.yml) +[![Build MinGW](https://github.com/levalup/libuvcxx/actions/workflows/build-mingw.yml/badge.svg)]( + https://github.com/levalup/libuvcxx/actions/workflows/build-mingw.yml) +[![Single Header](https://github.com/levalup/libuvcxx/actions/workflows/single-header.yml/badge.svg)]( + https://github.com/levalup/libuvcxx/actions/workflows/single-header.yml) + [![Release](https://github.com/levalup/libuvcxx/actions/workflows/release.yml/badge.svg)]( https://github.com/levalup/libuvcxx/actions/workflows/release.yml) diff --git a/include/uvcxx.h b/include/uvcxx.h index 738e099..68a4c7b 100644 --- a/include/uvcxx.h +++ b/include/uvcxx.h @@ -6,6 +6,28 @@ #ifndef LIBUVCXX_UVCXX_H #define LIBUVCXX_UVCXX_H +#include "uvcxx/utils/apply.h" +#include "uvcxx/utils/assert.h" +#include "uvcxx/utils/callback.h" +#include "uvcxx/utils/defer.h" +#include "uvcxx/utils/detach.h" +#include "uvcxx/utils/pencil_box.h" +#include "uvcxx/utils/platform.h" +#include "uvcxx/utils/promise.h" +#include "uvcxx/utils/queue.h" +#include "uvcxx/utils/standard.h" +#include "uvcxx/utils/tuple.h" + +#include "uvcxx/cxx/buffer.h" +#include "uvcxx/cxx/except.h" +#include "uvcxx/cxx/ref.h" +#include "uvcxx/cxx/string.h" +#include "uvcxx/cxx/to_string.h" +#include "uvcxx/cxx/version.h" +#include "uvcxx/cxx/wrapper.h" + +#include "uvcxx/inner/base.h" + #include "uvcxx/async.h" #include "uvcxx/barrier.h" #include "uvcxx/buf.h" diff --git a/include/uvcxx/os.h b/include/uvcxx/os.h index f8e26d0..f6b8bf2 100644 --- a/include/uvcxx/os.h +++ b/include/uvcxx/os.h @@ -247,11 +247,11 @@ namespace uv { }); } - int setenv(uvcxx::string name, uvcxx::string value) { + inline int setenv(uvcxx::string name, uvcxx::string value) { UVCXX_PROXY(uv_os_setenv(name, value), "can not setenv['", name.c_str, "']='", value.c_str, "'"); } - int unsetenv(uvcxx::string name) { + inline int unsetenv(uvcxx::string name) { UVCXX_PROXY(uv_os_unsetenv(name), "can not unsetenv['", name.c_str, "']"); } diff --git a/tests/attch.cpp b/tests/attch.cpp index c190aea..06b3d6f 100644 --- a/tests/attch.cpp +++ b/tests/attch.cpp @@ -3,9 +3,7 @@ // L.eval: Let programmer get rid of only work jobs. // -#include "uvcxx/idle.h" -#include "uvcxx/cxx/to_string.h" -#include "uvcxx/utils/assert.h" +#include "uvcxx.h" int loop_handle_count(uv::loop_t &loop) { int count = 0; @@ -90,4 +88,4 @@ int main() { uvcxx_assert(loop_handle_count(loop) == 1); return 0; -} \ No newline at end of file +} diff --git a/tests/bufs.cpp b/tests/bufs.cpp index 15d22d4..e151580 100644 --- a/tests/bufs.cpp +++ b/tests/bufs.cpp @@ -5,9 +5,7 @@ #include -#include "uvcxx/cxx/buffer.h" -#include "uvcxx/utils/assert.h" -#include "uvcxx/buf.h" +#include "uvcxx.h" void init_buffer(void *data, size_t size) { int c = 0; diff --git a/tests/callback.cpp b/tests/callback.cpp index 49609a9..3728ff6 100644 --- a/tests/callback.cpp +++ b/tests/callback.cpp @@ -9,9 +9,7 @@ #include -#include "uvcxx/utils/assert.h" -#include "uvcxx/utils/callback.h" - +#include "uvcxx.h" class Copyable { public: diff --git a/tests/close_handle.cpp b/tests/close_handle.cpp index 2ef74f0..3d1e88b 100644 --- a/tests/close_handle.cpp +++ b/tests/close_handle.cpp @@ -3,8 +3,7 @@ // L.eval: Let programmer get rid of only work jobs. // -#include "uvcxx/idle.h" -#include "uvcxx/utils/assert.h" +#include "uvcxx.h" int main() { int v = 0; diff --git a/tests/move-base-1.cpp b/tests/move-base-1.cpp index 4041c6c..69cbc38 100644 --- a/tests/move-base-1.cpp +++ b/tests/move-base-1.cpp @@ -5,8 +5,7 @@ #include -#include "uvcxx/inner//base.h" -#include "uvcxx/utils/assert.h" +#include "uvcxx.h" static int count = 0; static int copy = 0; diff --git a/tests/move-base-2.cpp b/tests/move-base-2.cpp index be7c3bc..4e502bc 100644 --- a/tests/move-base-2.cpp +++ b/tests/move-base-2.cpp @@ -5,8 +5,7 @@ #include -#include "uvcxx/inner/base.h" -#include "uvcxx/utils/assert.h" +#include "uvcxx.h" static int count = 0; static int copy = 0; diff --git a/tests/move-base-3/struct.h b/tests/move-base-3/struct.h index 51a3d15..63f8866 100644 --- a/tests/move-base-3/struct.h +++ b/tests/move-base-3/struct.h @@ -8,8 +8,7 @@ #include -#include "uvcxx/inner/base.h" -#include "uvcxx/utils/assert.h" +#include "uvcxx.h" struct V { static int count; diff --git a/tests/mutex.cpp b/tests/mutex.cpp index 5740392..03359f7 100644 --- a/tests/mutex.cpp +++ b/tests/mutex.cpp @@ -5,11 +5,7 @@ #include -#include "uvcxx/mutex.h" -#include "uvcxx/thread.h" -#include "uvcxx/utilities.h" - -#include "uvcxx/utils/assert.h" +#include "uvcxx.h" int main() { uv::mutex_t mutex = nullptr; diff --git a/tests/promise.cpp b/tests/promise.cpp index 5a4ad3a..2a04f9e 100644 --- a/tests/promise.cpp +++ b/tests/promise.cpp @@ -7,8 +7,7 @@ #pragma warning(disable: 4702) #endif -#include "uvcxx/utils/assert.h" -#include "uvcxx/utils/promise.h" +#include "uvcxx.h" class Copyable { diff --git a/tests/ref.cpp b/tests/ref.cpp index 0bae68e..32b0029 100644 --- a/tests/ref.cpp +++ b/tests/ref.cpp @@ -3,10 +3,7 @@ // L.eval: Let programmer get rid of only work jobs. // -#include "uvcxx/idle.h" -#include "uvcxx/cxx/ref.h" -#include "uvcxx/cxx/to_string.h" -#include "uvcxx/utils/assert.h" +#include "uvcxx.h" int main() { uv::loop_t loop; @@ -37,4 +34,4 @@ int main() { uvcxx_assert(before == 1 && after == 0 && idle_times == 0); return 0; -} \ No newline at end of file +} diff --git a/tests/strings.cpp b/tests/strings.cpp index 703d92b..cce6998 100644 --- a/tests/strings.cpp +++ b/tests/strings.cpp @@ -5,8 +5,7 @@ #include -#include "uvcxx/cxx/string.h" -#include "uvcxx/utils/assert.h" +#include "uvcxx.h" std::string fs(uvcxx::string s) { std::cout << "|" << s.c_str << "|" << std::endl; diff --git a/tests/tuple_value.cpp b/tests/tuple_value.cpp index 164da97..59b3c7e 100644 --- a/tests/tuple_value.cpp +++ b/tests/tuple_value.cpp @@ -5,8 +5,7 @@ #include -#include "uvcxx/utils/tuple.h" -#include "uvcxx/utils/assert.h" +#include "uvcxx.h" class Moveable { public: