From 65806bf29479ebaba7fa087583afc9f8f274f5fb Mon Sep 17 00:00:00 2001 From: Fedor Osetrov <33493672+fdr400@users.noreply.github.com> Date: Mon, 6 Jan 2025 13:55:43 +0300 Subject: [PATCH] feat CI: consistent names and cache system for all OS, use gold for g++ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------------------ Note: by creating a PR or an issue you automatically agree to the CLA. See [CONTRIBUTING.md](https://github.com/userver-framework/userver/blob/develop/CONTRIBUTING.md). Feel free to remove this note, the agreement holds. Tests: протестировано CI Pull Request resolved: #820 Co-authored-by: fdr400 commit_hash:50991c262fd479cefad3b2a5f7ee88bdb0fd45c6 --- .github/workflows/alpine.yml | 71 +++++++++++++++++---- .github/workflows/ci.yml | 98 ++++++++++++++++++++--------- .github/workflows/docker.yaml | 49 ++++++++++----- .github/workflows/macos.yml | 46 ++++++++++++-- cmake/SetupBrotli.cmake | 3 + cmake/UserverSetupEnvironment.cmake | 14 +++-- scripts/docs/en/deps/macos.md | 1 + 7 files changed, 215 insertions(+), 67 deletions(-) diff --git a/.github/workflows/alpine.yml b/.github/workflows/alpine.yml index dbec6d97a913..7594ee2e9661 100644 --- a/.github/workflows/alpine.yml +++ b/.github/workflows/alpine.yml @@ -1,4 +1,4 @@ -name: Alpine Linux +name: Alpine 'on': pull_request: @@ -13,13 +13,16 @@ env: ASAN_OPTIONS: detect_odr_violation=2 CXX: clang++-18 CC: clang-18 + CCACHE_DIR: /home/runner/.cache/ccache + CCACHE_NOHASHDIR: true + CPM_SOURCE_CACHE: /home/runner/.cache/CPM jobs: posix: strategy: fail-fast: false - name: Build only + name: ubuntu-24.04 (build-only) runs-on: ubuntu-24.04 steps: @@ -27,15 +30,36 @@ jobs: with: fetch-depth: 0 + - name: Restore cached directories + id: restore-cache + uses: actions/cache/restore@v4 + with: + path: | + ${{env.CCACHE_DIR}} + ${{env.CPM_SOURCE_CACHE}} + key: 'alpine-cache-dir ${{github.ref}}' + restore-keys: | + alpine-cache-dir ${{github.ref}} + alpine-cache-dir + + - name: Setup host cache dirs + run: | + mkdir -p ${{env.CCACHE_DIR}} + mkdir -p ${{env.CPM_SOURCE_CACHE}} + - name: Setup latest Alpine Linux uses: jirutka/setup-alpine@v1 + with: + volumes: | + ${{env.CCACHE_DIR}}:${{env.CCACHE_DIR}} + ${{env.CPM_SOURCE_CACHE}}:${{env.CPM_SOURCE_CACHE}} - name: Install dependencies shell: alpine.sh --root {0} run: | pwd cat /etc/alpine-release - apk add lld + apk add lld ccache git apk add $(cat scripts/docs/en/deps/alpine.md) - name: Install test dependencies @@ -45,16 +69,29 @@ jobs: redis \ rabbitmq-server \ + - name: Setup caches + shell: alpine.sh --root {0} + run: | + echo "Cached CPM packages:" + du -h -d 1 ${{env.CPM_SOURCE_CACHE}} + for f in $(find ${{env.CPM_SOURCE_CACHE}} -name "cmake.lock"); + do + repo=$(ls -d $(dirname $f)/*/); + echo "Repository: $repo"; + git config --global --add safe.directory $repo; + done + + ccache -M 2.0GB + ccache -s -v - name: Run cmake - shell: alpine.sh {0} + shell: alpine.sh --root {0} run: | pwd - mkdir build_debug - cd build_debug CMAKE_PROGRAM_PATH=/usr/lib/llvm17/bin/ \ - cmake \ + cmake -S . -B build_debug \ -DCMAKE_BUILD_TYPE=Debug \ + -DUSERVER_USE_LD=lld \ -DUSERVER_NO_WERROR=OFF \ -DUSERVER_BUILD_ALL_COMPONENTS=1 \ -DUSERVER_BUILD_SAMPLES=1 \ @@ -69,11 +106,23 @@ jobs: -DUSERVER_FORCE_DOWNLOAD_ABSEIL=1 \ -DUSERVER_FORCE_DOWNLOAD_PROTOBUF=1 \ -DUSERVER_FORCE_DOWNLOAD_GRPC=1 \ - -DUSERVER_USE_LD=lld \ - .. - name: Compile + shell: alpine.sh --root {0} + run: | + cmake --build build_debug -j$(nproc) + + - name: Save cached directories + uses: actions/cache/save@v4 + with: + path: | + ${{env.CCACHE_DIR}} + ${{env.CPM_SOURCE_CACHE}} + key: ${{ steps.restore-cache.outputs.cache-primary-key }} + + - name: Show cache stats shell: alpine.sh {0} run: | - cd build_debug - cmake --build . -j$(nproc) + du -h -d 1 ${{env.CCACHE_DIR}} + du -h -d 1 ${{env.CPM_SOURCE_CACHE}} + ccache -s -v diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 68b73ce12412..db898ebf6dde 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: CI +name: Ubuntu 'on': pull_request: @@ -11,6 +11,9 @@ name: CI env: UBSAN_OPTIONS: print_stacktrace=1 ASAN_OPTIONS: detect_odr_violation=2 + CCACHE_DIR: /home/runner/.cache/ccache + CCACHE_NOHASHDIR: true + CPM_SOURCE_CACHE: /home/runner/.cache/CPM jobs: posix: @@ -34,8 +37,8 @@ jobs: -DUSERVER_NAMESPACE_END="}}" os: ubuntu-24.04 info: clang-18 + debug + sanitize addr+ub + id: ubuntu24_clang18_debug_sanitize-addr-ub tests-flags: '' - ccache-dir: ~/.cache/ccache - cmake-flags: >- -GNinja @@ -53,12 +56,13 @@ jobs: -DUSERVER_NAMESPACE_END="}}" os: ubuntu-22.04 info: clang-14 + debug + sanitize addr+ub + id: ubuntu22_clang14_debug_sanitize-addr-ub tests-flags: '' - ccache-dir: ~/.cache/ccache - cmake-flags: >- -GNinja -DCMAKE_BUILD_TYPE=Release + -DUSERVER_USE_LD=gold -DUSERVER_BUILD_ALL_COMPONENTS=1 -DUSERVER_BUILD_SAMPLES=1 -DUSERVER_BUILD_TESTS=1 @@ -69,8 +73,8 @@ jobs: -DUSERVER_DOWNLOAD_PACKAGE_ABSEIL=0 os: ubuntu-20.04 info: g++-9 + release + id: ubuntu20_gcc9_release tests-flags: '--gtest_filter=-HttpClient.RedirectHeaders:HttpClient.TestUseIPv4v6' - ccache-dir: ~/.ccache # GCC-8 - testing minimal required compiler - cmake-flags: >- @@ -78,6 +82,7 @@ jobs: -DCMAKE_CXX_COMPILER=g++-8 -DCMAKE_C_COMPILER=gcc-8 -DCMAKE_BUILD_TYPE=Debug + -DUSERVER_USE_LD=gold -DUSERVER_BUILD_ALL_COMPONENTS=1 -DUSERVER_BUILD_SAMPLES=1 -DUSERVER_BUILD_TESTS=1 @@ -88,8 +93,8 @@ jobs: -DUSERVER_DOWNLOAD_PACKAGE_ABSEIL=0 os: ubuntu-20.04 info: g++-8 + debug + id: ubuntu20_gcc8_debug tests-flags: '--gtest_filter=-HttpClient.RedirectHeaders:HttpClient.TestUseIPv4v6' - ccache-dir: ~/.ccache name: '${{matrix.os}}: ${{matrix.info}}' runs-on: ${{matrix.os}} @@ -97,14 +102,17 @@ jobs: steps: - uses: actions/checkout@v4 - - name: Reuse ccache directory - uses: actions/cache@v4 + - name: Restore cached directories + id: restore-cache + uses: actions/cache/restore@v4 with: - path: '${{matrix.ccache-dir}}' - key: '${{matrix.os}} ${{matrix.info}} ccache-dir ${{github.ref}} run-${{github.run_number}}' + path: | + ${{env.CCACHE_DIR}} + ${{env.CPM_SOURCE_CACHE}} + key: 'ubuntu-cache-dir ${{matrix.id}} ${{github.ref}}' restore-keys: | - ${{matrix.os}} ${{matrix.info}} ccache-dir ${{github.ref}} run-' - ${{matrix.os}} ${{matrix.info}} ccache- + ubuntu-cache-dir ${{matrix.id}} ${{github.ref}} + ubuntu-cache-dir ${{matrix.id}} - name: Setup ramdrive for testsuites run: | @@ -146,18 +154,10 @@ jobs: wget https://apt.llvm.org/llvm.sh chmod +x llvm.sh sudo ./llvm.sh 14 - sudo apt install clang-format-14 + sudo apt install -y clang-format-14 sudo ln -sf /usr/bin/clang-format-14 /usr/bin/clang-format clang-format --version - - name: Install grpc, protobuf and abseil - if: matrix.os == 'ubuntu-20.04' - run: | - git clone --recursive -b v1.45.0 https://github.com/grpc/grpc new_grpc - cmake -S./new_grpc -B./new_grpc/build -DABSL_PROPAGATE_CXX_STD=ON -DABSL_ENABLE_INSTALL=ON - cmake --build new_grpc/build -- -j$(nproc) - sudo cmake --install new_grpc/build - - name: Add missing repositories run: | sudo apt update @@ -192,9 +192,37 @@ jobs: - name: Install common deps run: | sudo apt update - sudo apt purge libpq5 libpq-dev postgresql-* + sudo apt purge -y libpq5 libpq-dev postgresql-* sudo apt install --allow-downgrades -y clickhouse-common-static redis-server postgresql $(cat scripts/docs/en/deps/${{matrix.os}}.md | tr '\n' ' ') + - name: Install ccache + if: matrix.os == 'ubuntu-20.04' + run: | + sudo apt remove --purge -y ccache + git clone --depth 1 -b v4.10.2 https://github.com/ccache/ccache.git + cd ccache + cmake -S . -B build -GNinja -DENABLE_TESTING=OFF -DSTATIC_LINK=ON -DCMAKE_BUILD_TYPE=Release + cmake --build build -j$(nproc) + sudo cmake --install build + + - name: Setup ccache + run: | + ccache -M 2.0GB + ccache -s -v + + - name: Install grpc, protobuf and abseil + if: matrix.os == 'ubuntu-20.04' + run: | + sudo apt install -y ninja-build + git clone --recursive --depth 1 -b v1.45.0 https://github.com/grpc/grpc new_grpc + GRPC_BUILD_ENABLE_CCACHE=true \ + cmake -GNinja -S./new_grpc -B./new_grpc/build \ + -DABSL_PROPAGATE_CXX_STD=ON -DABSL_ENABLE_INSTALL=ON + cmake --build new_grpc/build -j$(nproc) + sudo cmake --install new_grpc/build + rm -rf new_grpc + ccache -s -v + - name: Install g++-8 if: matrix.info == 'g++-8 + debug' run: | @@ -208,16 +236,9 @@ jobs: run: | sudo apt install -y gdb python3-pytest - - name: Setup ccache - run: | - ccache -M 2.0GB - ccache -s - - name: Run cmake run: | - mkdir build_debug - cd build_debug - cmake ${{matrix.cmake-flags}} .. + cmake -S . -B build_debug ${{matrix.cmake-flags}} - name: Run clang-tidy if: matrix.info == 'clang-14 + debug + sanitize addr+ub' @@ -242,6 +263,21 @@ jobs: cd build_debug cmake --build . -j $(nproc) + - name: Save cached directories + uses: actions/cache/save@v4 + with: + path: | + ${{env.CCACHE_DIR}} + ${{env.CPM_SOURCE_CACHE}} + key: ${{ steps.restore-cache.outputs.cache-primary-key }} + + - name: Show cache stats + run: | + du -h -d 1 ${{env.CCACHE_DIR}} + du -h -d 1 ${{env.CPM_SOURCE_CACHE}} + ccache -s -v + + - name: Run tests (universal) run: | echo "UBSAN_OPTIONS=${UBSAN_OPTIONS} ASAN_OPTIONS=${ASAN_OPTIONS}" @@ -290,7 +326,7 @@ jobs: # libbson unnecessarily overaligns structures and GCC-9 does not support overaligned new if: matrix.info != 'g++-9 + release' run: | - sudo apt install mongodb-mongosh + sudo apt install -y mongodb-mongosh cd build_debug mkdir mongo || : cd mongo @@ -311,7 +347,7 @@ jobs: # MySQL benchmarks do not work on new Ubuntu if: matrix.os != 'ubuntu-24.04' run: | - sudo apt install mariadb-server + sudo apt install -y mariadb-server cd build_debug mkdir mysql || : cd mysql diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml index cd1c4260c747..9ddbb8ef53b9 100644 --- a/.github/workflows/docker.yaml +++ b/.github/workflows/docker.yaml @@ -1,4 +1,4 @@ -name: Docker build +name: Docker 'on': pull_request: @@ -16,6 +16,8 @@ jobs: include: - cmake-flags: >- -DCMAKE_CXX_STANDARD=17 + -DCPM_SOURCE_CACHE=~/.cache/CPM + -DUSERVER_USE_LD=gold -DUSERVER_NO_WERROR=0 -DUSERVER_BUILD_SAMPLES=1 -DUSERVER_BUILD_TESTS=1 @@ -29,6 +31,7 @@ jobs: -DCMAKE_C_COMPILER=clang-16 -DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_CXX_STANDARD=17 + -DCPM_SOURCE_CACHE=~/.cache/CPM -DUSERVER_NO_WERROR=0 -DUSERVER_BUILD_ALL_COMPONENTS=1 -DUSERVER_BUILD_SAMPLES=1 @@ -41,6 +44,8 @@ jobs: -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_CXX_STANDARD=17 + -DCPM_SOURCE_CACHE=~/.cache/CPM + -DUSERVER_USE_LD=gold -DUSERVER_NO_WERROR=0 -DUSERVER_BUILD_ALL_COMPONENTS=1 -DUSERVER_BUILD_SAMPLES=1 @@ -53,6 +58,7 @@ jobs: -DCMAKE_C_COMPILER=clang-16 -DCMAKE_CXX_COMPILER=clang++-16 -DCMAKE_CXX_STANDARD=20 + -DCPM_SOURCE_CACHE=~/.cache/CPM -DUSERVER_BUILD_ALL_COMPONENTS=1 -DUSERVER_BUILD_SAMPLES=1 -DUSERVER_BUILD_TESTS=1 @@ -64,6 +70,8 @@ jobs: -DCMAKE_C_COMPILER=gcc-11 -DCMAKE_CXX_COMPILER=g++-11 -DCMAKE_CXX_STANDARD=20 + -DCPM_SOURCE_CACHE=~/.cache/CPM + -DUSERVER_USE_LD=gold -DUSERVER_NO_WERROR=0 -DUSERVER_BUILD_ALL_COMPONENTS=1 -DUSERVER_BUILD_SAMPLES=1 @@ -82,15 +90,17 @@ jobs: run: | sudo apt install -y docker-compose - - name: Reuse ccache directory - uses: actions/cache@v4 + - name: Restore cached directories + id: restore-cache + uses: actions/cache/restore@v4 with: - path: .ccache - key: 'ccache-dir-${{ matrix.id }}_${{github.ref}}_run-${{github.run_number}}' + path: | + .ccache + .cache/CPM + key: 'docker-cache-dir ${{matrix.id}} ${{github.ref}}' restore-keys: | - ccache-dir-${{ matrix.id }}_${{github.ref}}_run- - ccache-dir-${{ matrix.id }}_ - ccache- + docker-cache-dir ${{matrix.id}} ${{github.ref}} + docker-cache-dir ${{matrix.id}} - name: Free disk space run: | @@ -102,25 +112,35 @@ jobs: - name: Setup ccache run: docker-compose -f .github/docker-compose.yml run --rm ${{ matrix.image - }} bash -c 'ccache -M 2.0GB && ccache -s' + }} bash -c 'ccache -M 2.0GB && ccache -s -v' - name: CMake run: >- docker-compose -f .github/docker-compose.yml - run --rm ${{ matrix.image}} bash -c - 'cmake -DUSERVER_GOOGLE_COMMON_PROTOS=/app/api-common-protos + run --rm ${{ matrix.image }} bash -c + 'cd /userver && cmake -DUSERVER_GOOGLE_COMMON_PROTOS=/app/api-common-protos ${{ matrix.cmake-flags }} -B./build -S./' - name: Build run: >- docker-compose -f .github/docker-compose.yml - run --rm ${{ matrix.image}} bash -c - 'cd /userver/build && make -j $(nproc)' + run --rm ${{ matrix.image }} bash -c + 'cd /userver && cmake --build build -j $(nproc)' + + - name: Save cached directories + uses: actions/cache/save@v4 + with: + path: | + .ccache + .cache/CPM + key: ${{ steps.restore-cache.outputs.cache-primary-key }} - name: Run ydb + if: matrix.id == 'ubuntu_clang_cxx20' run: docker-compose -f .github/docker-compose.yml run -d --rm run-ydb - name: Watch ydb + if: matrix.id == 'ubuntu_clang_cxx20' run: >- docker-compose -f .github/docker-compose.yml run --rm ${{ matrix.image}} bash -c @@ -131,4 +151,5 @@ jobs: run: >- docker-compose -f .github/docker-compose.yml run --rm ${{ matrix.image}} bash -c - 'cd /userver/build && ulimit -n 4096 && GTEST_FILTER="${{ matrix.gtest-filter }}" ctest -V' + 'cd /userver/build && ulimit -n 4096 && GTEST_FILTER="${{ matrix.gtest-filter + }}" ctest -V' diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml index 9229d5e5d767..7233eed5dc81 100644 --- a/.github/workflows/macos.yml +++ b/.github/workflows/macos.yml @@ -1,4 +1,4 @@ -name: CI +name: MacOS 'on': pull_request: @@ -8,10 +8,19 @@ name: CI - develop - feature/** +env: + CCACHE_DIR: /Users/runner/Library/Caches/ccache + CCACHE_NOHASHDIR: true + CPM_SOURCE_CACHE: /Users/runner/Library/Caches/CPM + jobs: macos: - name: MacOS (build only) + strategy: + fail-fast: false + + name: macos-latest (build only) runs-on: macos-latest + env: CMAKE_FLAGS: >- -GNinja @@ -31,8 +40,18 @@ jobs: steps: - uses: actions/checkout@v4 + + - name: Restore cached directories + id: restore-cache + uses: actions/cache/restore@v4 with: - fetch-depth: 0 + path: | + ${{env.CCACHE_DIR}} + ${{env.CPM_SOURCE_CACHE}} + key: 'macos-cache-dir ${{github.ref}}' + restore-keys: | + macos-cache-dir ${{github.ref}} + macos-cache-dir - name: Install brew packages run: | @@ -43,9 +62,12 @@ jobs: brew install python@3.11 brew install lld - brew link postgresql@16 + brew link postgresql@16 # postgresql is keg-only - brew upgrade + - name: Setup ccache + run: | + ccache -M 2.0GB + ccache -s -v - name: Run cmake run: | @@ -54,3 +76,17 @@ jobs: - name: Compile run: | cmake --build build_debug -j$(nproc) -- -k 1 + + - name: Save cached directories + uses: actions/cache/save@v4 + with: + path: | + ${{env.CCACHE_DIR}} + ${{env.CPM_SOURCE_CACHE}} + key: ${{ steps.restore-cache.outputs.cache-primary-key }} + + - name: Show cache stats + run: | + du -h -d 1 ${{env.CCACHE_DIR}} + du -h -d 1 ${{env.CPM_SOURCE_CACHE}} + ccache -s -v diff --git a/cmake/SetupBrotli.cmake b/cmake/SetupBrotli.cmake index 317b5545ebf8..e3715af7c50c 100644 --- a/cmake/SetupBrotli.cmake +++ b/cmake/SetupBrotli.cmake @@ -25,6 +25,9 @@ CPMAddPackage( NAME Brotli VERSION ${USERVER_BROTLI_VERSION} GITHUB_REPOSITORY google/brotli + OPTIONS + "BROTLI_DISABLE_TESTS TRUE" + "BUILD_SHARED_LIBS OFF" ) set(Brotli_FOUND TRUE) diff --git a/cmake/UserverSetupEnvironment.cmake b/cmake/UserverSetupEnvironment.cmake index 31a933aea220..0c3f8d276171 100644 --- a/cmake/UserverSetupEnvironment.cmake +++ b/cmake/UserverSetupEnvironment.cmake @@ -69,8 +69,14 @@ function(_userver_setup_environment_impl) find_program(CCACHE_EXECUTABLE ccache) if (CCACHE_EXECUTABLE) message(STATUS "ccache: enabled") - set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}" PARENT_SCOPE) - set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}" PARENT_SCOPE) + if (CMAKE_VERSION VERSION_GREATER_EQUAL 3.17) + message(STATUS "Setting compiler launcher: ${CCACHE_EXECUTABLE}") + set(CMAKE_C_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}" PARENT_SCOPE) + set(CMAKE_CXX_COMPILER_LAUNCHER "${CCACHE_EXECUTABLE}" PARENT_SCOPE) + else() + message(STATUS "Setting rule launch compile: ${CCACHE_EXECUTABLE}") + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE "${CCACHE_EXECUTABLE}") + endif() else() message(STATUS "ccache: enabled, but not found") endif() @@ -78,10 +84,6 @@ function(_userver_setup_environment_impl) message(STATUS "ccache: disabled") endif() - if(CMAKE_SYSTEM_NAME MATCHES "Darwin" AND NOT USERVER_CONAN) - set(Boost_NO_BOOST_CMAKE ON PARENT_SCOPE) - endif() - # Build type specific if (CMAKE_BUILD_TYPE MATCHES "Debug" OR CMAKE_BUILD_TYPE MATCHES "Test") add_compile_definitions(_GLIBCXX_ASSERTIONS) diff --git a/scripts/docs/en/deps/macos.md b/scripts/docs/en/deps/macos.md index 5a2a6b2b01da..76b83406ffe5 100644 --- a/scripts/docs/en/deps/macos.md +++ b/scripts/docs/en/deps/macos.md @@ -1,5 +1,6 @@ ccache cmake +cryptopp cyrus-sasl git google-benchmark