Skip to content

Commit bbd3d4d

Browse files
committed
Merge #96: cmake: Improve Ccache usage on Windows
6edbb28 fixup! ci: Test CMake edge cases (Hennadii Stepanov) bbc1c4c fixup! cmake: Add `ccache` support (Hennadii Stepanov) Pull request description: This PR: 1. Improves the user experience when using the `ccache` package installed via [Chocolatey](https://community.chocolatey.org/packages/ccache) on Windows. The new approach is the same as the one currently used in the master branch CI. 2. Also fix caching for debug configurations (see https://github.com/ccache/ccache/wiki/MS-Visual-Studio#usage-with-cmake) 3. Added caching to the "Win64 native" CI job: - https://github.com/hebasto/bitcoin/actions/runs/7828761172/job/21362637142 (it might be compared with the log for the same branch, but without the first commit: https://github.com/hebasto/bitcoin/actions/runs/7828850714/job/21363047274) Top commit has no ACKs. Tree-SHA512: 803f3155c113a9e985c001077d9d42adc876ab5a389c4aa786d4cc6eec19054a5e37d0a17ab68d260cbd0041eb331e9742e430f82ea8f8bf34b368e037442e0f
2 parents 2bf2aab + 6edbb28 commit bbd3d4d

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

.github/workflows/cmake.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,10 @@ jobs:
406406
path: ~/AppData/Local/vcpkg/archives
407407
key: ${{ runner.os }}-${{ runner.arch }}-vcpkg-binary-${{ hashFiles('cmake_version', 'msbuild_version', 'toolset_version', 'vcpkg.json') }}
408408

409+
- name: Install Ccache
410+
run: |
411+
choco install --yes --no-progress ccache
412+
409413
- name: Generate build system
410414
run: |
411415
cmake -B build --preset vs2022
@@ -417,10 +421,31 @@ jobs:
417421
path: ~/AppData/Local/vcpkg/archives
418422
key: ${{ runner.os }}-${{ runner.arch }}-vcpkg-binary-${{ hashFiles('cmake_version', 'msbuild_version', 'toolset_version', 'vcpkg.json') }}
419423

424+
- name: Restore Ccache cache
425+
id: ccache-cache
426+
uses: actions/cache/restore@v4
427+
with:
428+
path: ~/AppData/Local/ccache
429+
key: ${{ github.job }}-ccache-${{ github.run_id }}
430+
restore-keys: ${{ github.job }}-ccache-
431+
420432
- name: Build Release configuration
421433
run: |
434+
ccache --zero-stats
422435
cmake --build build -j $env:NUMBER_OF_PROCESSORS --config Release
423436
437+
- name: Ccache stats
438+
run: |
439+
ccache --version | head -n 1
440+
ccache --show-stats --verbose
441+
442+
- name: Save Ccache cache
443+
uses: actions/cache/save@v4
444+
if: github.event_name != 'pull_request' && steps.ccache-cache.outputs.cache-hit != 'true'
445+
with:
446+
path: ~/AppData/Local/ccache
447+
key: ${{ github.job }}-ccache-${{ github.run_id }}
448+
424449
- name: Test Release configuration
425450
run: |
426451
ctest --test-dir build -j $env:NUMBER_OF_PROCESSORS -C Release

cmake/optional.cmake

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,31 @@
55
# Optional features and packages.
66

77
if(CCACHE)
8-
find_program(CCACHE_COMMAND ccache)
8+
set(ccache_hints)
9+
if(MSVC AND EXISTS "$ENV{ChocolateyInstall}")
10+
# Bypass a shim executable provided by Chocolatey.
11+
# See https://docs.chocolatey.org/en-us/features/shim
12+
file(GLOB ccache_hints "$ENV{ChocolateyInstall}/lib/ccache/tools/ccache-*")
13+
endif()
14+
find_program(CCACHE_COMMAND ccache HINTS ${ccache_hints})
15+
unset(ccache_hints)
16+
917
if(CCACHE_COMMAND)
1018
if(MSVC)
1119
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.24)
1220
# ccache >= 4.8 requires compile batching turned off that is available since CMake 3.24.
1321
# See https://github.com/ccache/ccache/wiki/MS-Visual-Studio
1422
set(CCACHE ON)
15-
set(MSVC_CCACHE_WRAPPER_CONTENT "\"${CCACHE_COMMAND}\" \"${CMAKE_CXX_COMPILER}\"")
16-
set(MSVC_CCACHE_WRAPPER_FILENAME wrapped-cl.bat)
17-
file(WRITE ${CMAKE_BINARY_DIR}/${MSVC_CCACHE_WRAPPER_FILENAME} "${MSVC_CCACHE_WRAPPER_CONTENT} %*")
23+
file(COPY_FILE ${CCACHE_COMMAND} ${CMAKE_BINARY_DIR}/cl.exe ONLY_IF_DIFFERENT)
1824
list(APPEND CMAKE_VS_GLOBALS
19-
"CLToolExe=${MSVC_CCACHE_WRAPPER_FILENAME}"
25+
"CLToolExe=cl.exe"
2026
"CLToolPath=${CMAKE_BINARY_DIR}"
2127
"DebugInformationFormat=OldStyle"
2228
)
2329
set(CMAKE_VS_NO_COMPILE_BATCHING ON)
30+
# By default Visual Studio generators will use /Zi which is not compatible
31+
# with ccache, so tell Visual Studio to use /Z7 instead.
32+
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<$<CONFIG:Debug,RelWithDebInfo>:Embedded>")
2433
elseif(CCACHE STREQUAL "AUTO")
2534
message(WARNING "ccache requested and found, but CMake >= 3.24 is required to use it properly. Disabling.\n"
2635
"To skip ccache check, use \"-DCCACHE=OFF\".\n")

0 commit comments

Comments
 (0)