From 1c3823095eb9300fd0aae1fb569a3cc09b1346cc Mon Sep 17 00:00:00 2001
From: Justin Pryzby <pryzbyj@telsasoft.com>
Date: Sun, 22 May 2022 11:55:02 -0500
Subject: [PATCH] cirrus/windows: ccache

https://community.chocolatey.org/packages/ccache

https://www.postgresql.org/message-id/flat/20220522232606.GZ19626%40telsasoft.com
20220321001747.5o2zfoeqxvbjmdid@alap3.anarazel.de
20211012083721.hvixq4pnh2pixr3j%40alap3.anarazel.de
CA%2BhUKGLs6ENKL4w1o%2B1RpcS4VLyLXSUMWRYJVaiLBOJtarW25g%40mail.gmail.com

https://cirrus-ci.com/task/5456827583299584
https://cirrus-ci.com/task/6019777536720896

ci-os-only: xindows, windows-meson-ninja, xindows-meson-msbuild
---
 .cirrus.yml | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/.cirrus.yml b/.cirrus.yml
index bf20f85f8ce..ed9e86557d7 100644
--- a/.cirrus.yml
+++ b/.cirrus.yml
@@ -814,6 +814,9 @@ windows_template: &windows_template
     # currently have a tool for that...
     CIRRUS_ESCAPING_PROCESSES: 1
 
+    CCACHE_DIR: $CIRRUS_WORKING_DIR/.ccache
+    CCACHE_LOGFILE: ccache.log
+
   only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows.*'
 
   windows_container:
@@ -828,12 +831,14 @@ windows_template: &windows_template
     set
 
   setup_additional_packages_script: |
-    REM choco install -y --no-progress ...
-
+    choco install -y --no-progress ccache --version 4.6.1
+    cp c:\ProgramData\chocolatey\lib\ccache\tools\ccache-4.6.1-windows-x86_64\ccache.exe \BuildTools\VC\Auxiliary\Build
+    cp c:\ProgramData\chocolatey\lib\ccache\tools\ccache-4.6.1-windows-x86_64\ccache.exe \ProgramData\chocolatey\bin\cl.exe
 
 task:
   <<: *windows_template
   name: Windows - Server 2019, VS 2019 - Homegrown
+  only_if: $CIRRUS_CHANGE_MESSAGE !=~ '.*\nci-os-only:.*' || $CIRRUS_CHANGE_MESSAGE =~ '.*\nci-os-only:[^\n]*windows-mkvcbuild'
 
   configure_script:
     # copy errors out when using forward slashes
@@ -901,14 +906,22 @@ task:
     - mkdir subprojects
     - meson wrap install lz4
     - meson wrap install zlib
-    - meson setup --buildtype debug --backend ninja  -Dcassert=true -Db_pch=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe build
+    - set CC=ccache.exe cl.exe
+    - meson setup --buildtype plain --backend ninja  -Dcassert=true -Db_pch=false -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -Dc_args="/Z7 /MDd" build
+
+  ccache_cache:
+    folder: $CCACHE_DIR
 
   build_script:
+    - ccache.exe --zero-stats
     - vcvarsall x64
     - ninja -C build
+    - ccache.exe --show-stats
+
+  always:
+    upload_caches: ccache
 
   check_world_script:
-    - vcvarsall x64
     - meson test --no-rebuild -C build
 
   on_failure:
@@ -934,14 +947,21 @@ task:
     - mkdir subprojects
     - meson wrap install lz4
     - meson wrap install zlib
-    - meson setup --buildtype debug --backend vs -Dcassert=true -Db_pch=true -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe build
+    - meson setup --buildtype plain --backend vs -Dcassert=true -Db_pch=false -Dssl=openssl -Dlz4=enabled -Dzlib=enabled -Dextra_lib_dirs=c:\openssl\1.1\lib -Dextra_include_dirs=c:\openssl\1.1\include -DTAR=c:/windows/system32/tar.exe -Dc_args=/Z7 build
+
+  ccache_cache:
+    folder: $CCACHE_DIR
 
   build_script:
+    - ccache.exe --zero-stats
     - vcvarsall x64
-    - msbuild /p:UseMultiToolTask=true %MSBFLAGS% build\postgresql.sln
+    - msbuild /p:UseMultiToolTask=true /p:CLToolPath=c:\ProgramData\chocolatey\bin %MSBFLAGS% build\postgresql.sln
+    - ccache.exe --show-stats
+
+  always:
+    upload_caches: ccache
 
   check_world_script:
-    - vcvarsall x64
     - meson test --no-rebuild -C build
 
   always:
-- 
2.17.1

