From 686a7312e0d881a478bc8fe85e3bf0287de465c3 Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Mon, 17 Jun 2024 15:45:11 +0100 Subject: [PATCH] cmake [KILL 3-STATE]: Switch `WITH_CCACHE` to boolean `WITH_CCACHE` is an opportunistic option now and its default is `ON`. --- .github/workflows/ci.yml | 26 ------------------- .github/workflows/cmake.yml | 25 ------------------ CMakeLists.txt | 10 +++----- cmake/ccache.cmake | 25 ++++++++++++++++++ cmake/optional.cmake | 51 ------------------------------------- 5 files changed, 28 insertions(+), 109 deletions(-) create mode 100644 cmake/ccache.cmake delete mode 100644 cmake/optional.cmake diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5342fa890f860..fc3edae23af14 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -133,7 +133,6 @@ jobs: if: github.repository != 'bitcoin-core/gui' || github.event_name == 'pull_request' env: - CCACHE_MAXSIZE: '200M' PYTHONUTF8: 1 TEST_RUNNER_TIMEOUT_FACTOR: 40 @@ -163,10 +162,6 @@ jobs: py -3 --version Write-Host "PowerShell version $($PSVersionTable.PSVersion.ToString())" - - name: Install Ccache - run: | - choco install --yes --no-progress ccache - - name: Using vcpkg with MSBuild run: | Set-Location "$env:VCPKG_INSTALLATION_ROOT" @@ -197,32 +192,11 @@ jobs: path: ~/AppData/Local/vcpkg/archives key: ${{ github.job }}-vcpkg-binary-${{ hashFiles('cmake_version', 'msbuild_version', 'toolset_version', 'vcpkg.json') }} - - name: Restore Ccache cache - id: ccache-cache - uses: actions/cache/restore@v4 - with: - path: ~/AppData/Local/ccache - key: ${{ github.job }}-ccache- - - name: Build working-directory: build run: | - ccache --zero-stats cmake --build . -j $env:NUMBER_OF_PROCESSORS --config Release - - name: Ccache stats - run: | - ccache --version | head -n 1 - ccache --show-stats --verbose - - - name: Save Ccache cache - uses: actions/cache/save@v4 - if: github.event_name != 'pull_request' && steps.ccache-cache.outputs.cache-hit != 'true' - with: - path: ~/AppData/Local/ccache - # https://github.com/actions/cache/blob/main/tips-and-workarounds.md#update-a-cache - key: ${{ github.job }}-ccache-${{ github.run_id }} - - name: Run test suite working-directory: build run: | diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index ab4cb379ea647..4541bcd2f9194 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -456,10 +456,6 @@ jobs: path: ~/AppData/Local/vcpkg/archives key: ${{ matrix.conf.triplet }}-vcpkg-binary-${{ hashFiles('cmake_version', 'msbuild_version', 'toolset_version', 'vcpkg.json') }} - - name: Install Ccache - run: | - choco install --yes --no-progress ccache - - name: Generate build system run: | cmake -B build --preset ${{ matrix.conf.preset }} -DCMAKE_TOOLCHAIN_FILE="$env:VCPKG_INSTALLATION_ROOT\scripts\buildsystems\vcpkg.cmake" -DBUILD_BENCH=ON -DBUILD_FUZZ_BINARY=ON -DWERROR=ON @@ -471,32 +467,11 @@ jobs: path: ~/AppData/Local/vcpkg/archives key: ${{ matrix.conf.triplet }}-vcpkg-binary-${{ hashFiles('cmake_version', 'msbuild_version', 'toolset_version', 'vcpkg.json') }} - - name: Restore Ccache cache - id: ccache-cache - uses: actions/cache/restore@v4 - with: - path: ~/AppData/Local/ccache - key: ${{ matrix.conf.triplet }}-ccache-${{ github.run_id }} - restore-keys: ${{ matrix.conf.triplet }}-ccache- - - name: Build Release configuration working-directory: build run: | - ccache --zero-stats cmake --build . -j $env:NUMBER_OF_PROCESSORS --config Release - - name: Ccache stats - run: | - ccache --version | head -n 1 - ccache --show-stats --verbose - - - name: Save Ccache cache - uses: actions/cache/save@v4 - if: github.event_name != 'pull_request' && steps.ccache-cache.outputs.cache-hit != 'true' - with: - path: ~/AppData/Local/ccache - key: ${{ matrix.conf.triplet }}-ccache-${{ github.run_id }} - - name: Inspect build artifacts working-directory: build run: | diff --git a/CMakeLists.txt b/CMakeLists.txt index a88a204ae15de..33bd330a93906 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -107,11 +107,7 @@ cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${BUILD_TE option(ENABLE_HARDENING "Attempt to harden the resulting executables." ON) option(REDUCE_EXPORTS "Attempt to reduce exported symbols in the resulting executables." OFF) option(WERROR "Treat compiler warnings as errors." OFF) - -# TODO: These tri-state options will be removed and most features -# will become opt-in by default before merging into master. -include(TristateOption) -tristate_option(WITH_CCACHE "Use ccache for compiling." "if ccache is found." AUTO) +option(WITH_CCACHE "Attempt to use ccache for compiling." ON) option(WITH_NATPMP "Enable NAT-PMP." OFF) if(WITH_NATPMP) @@ -365,6 +361,8 @@ endif() include(cmake/introspection.cmake) +include(cmake/ccache.cmake) + include(cmake/crc32c.cmake) include(cmake/leveldb.cmake) include(cmake/minisketch.cmake) @@ -498,8 +496,6 @@ configure_file(cmake/script/CoverageFuzz.cmake CoverageFuzz.cmake COPYONLY) configure_file(cmake/script/CoverageInclude.cmake.in CoverageInclude.cmake @ONLY) configure_file(contrib/filter-lcov.py filter-lcov.py COPYONLY) -include(cmake/optional.cmake) - # Don't allow extended (non-ASCII) symbols in identifiers. This is easier for code review. try_append_cxx_flags("-fno-extended-identifiers" TARGET core_base_interface SKIP_LINK) diff --git a/cmake/ccache.cmake b/cmake/ccache.cmake new file mode 100644 index 0000000000000..30d0e8fb034c2 --- /dev/null +++ b/cmake/ccache.cmake @@ -0,0 +1,25 @@ +# Copyright (c) 2023-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +if(NOT MSVC) + find_program(CCACHE_EXECUTABLE ccache) + if(CCACHE_EXECUTABLE) + execute_process( + COMMAND readlink -f ${CMAKE_CXX_COMPILER} + OUTPUT_VARIABLE compiler_resolved_link + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + if(CCACHE_EXECUTABLE STREQUAL compiler_resolved_link) + set(WITH_CCACHE "ccache masquerades as the compiler") + elseif(WITH_CCACHE) + list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE}) + list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_EXECUTABLE}) + endif() + else() + set(WITH_CCACHE OFF) + endif() +endif() + +mark_as_advanced(CCACHE_EXECUTABLE) diff --git a/cmake/optional.cmake b/cmake/optional.cmake deleted file mode 100644 index 91ee04cd768b6..0000000000000 --- a/cmake/optional.cmake +++ /dev/null @@ -1,51 +0,0 @@ -# Copyright (c) 2023 The Bitcoin Core developers -# Distributed under the MIT software license, see the accompanying -# file COPYING or http://www.opensource.org/licenses/mit-license.php. - -# Optional features and packages. - -if(WITH_CCACHE) - set(ccache_hints) - if(MSVC AND EXISTS "$ENV{ChocolateyInstall}") - # Bypass a shim executable provided by Chocolatey. - # See https://docs.chocolatey.org/en-us/features/shim - file(GLOB ccache_hints "$ENV{ChocolateyInstall}/lib/ccache/tools/ccache-*") - endif() - find_program(CCACHE_COMMAND ccache HINTS ${ccache_hints}) - unset(ccache_hints) - - if(CCACHE_COMMAND) - if(MSVC) - if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24) - # ccache >= 4.8 requires compile batching turned off that is available since CMake 3.24. - # See https://github.com/ccache/ccache/wiki/MS-Visual-Studio - set(WITH_CCACHE ON) - file(COPY_FILE ${CCACHE_COMMAND} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT) - list(APPEND CMAKE_VS_GLOBALS - "CLToolExe=cl.exe" - "CLToolPath=${CMAKE_BINARY_DIR}" - "DebugInformationFormat=OldStyle" - ) - set(CMAKE_VS_NO_COMPILE_BATCHING ON) - # By default Visual Studio generators will use /Zi which is not compatible - # with ccache, so tell Visual Studio to use /Z7 instead. - set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$:Embedded>") - elseif(WITH_CCACHE STREQUAL "AUTO") - message(WARNING "ccache requested and found, but CMake >= 3.24 is required to use it properly. Disabling.\n" - "To skip ccache check, use \"-DWITH_CCACHE=OFF\".\n") - set(WITH_CCACHE OFF) - else() - message(FATAL_ERROR "ccache requested and found, but CMake >= 3.24 is required to use it properly.") - endif() - else() - set(WITH_CCACHE ON) - list(APPEND CMAKE_C_COMPILER_LAUNCHER ${CCACHE_COMMAND}) - list(APPEND CMAKE_CXX_COMPILER_LAUNCHER ${CCACHE_COMMAND}) - endif() - elseif(WITH_CCACHE STREQUAL "AUTO") - set(WITH_CCACHE OFF) - else() - message(FATAL_ERROR "ccache requested, but not found.") - endif() - mark_as_advanced(CCACHE_COMMAND) -endif()