44REM SPDX-License-Identifier: MIT
55
66@ echo off
7+ setlocal enabledelayedexpansion
8+
9+ REM ---------------------------------------------------------------------------
10+ REM Optional shared compiler cache: sccache fronting Depot Cache (WebDAV).
11+ REM Mirrors build.sh's sccache_can_wrap_compiler() probe. Because sccache *is*
12+ REM the compiler launcher (cmake runs `sccache cl.exe ...` for every TU), a
13+ REM present-but-crashing sccache would red every build; so we trust it only after
14+ REM a trivial TU compiles *through* it. Enabled only when USE_CACHE=true AND
15+ REM sccache is on PATH AND the probe succeeds; otherwise the build proceeds
16+ REM uncached and green. The Visual Studio generator jobs do NOT set USE_CACHE, so
17+ REM this stays inert for them (and the VS generator ignores
18+ REM CMAKE_{C,CXX}_COMPILER_LAUNCHER anyway -- only Ninja/Makefiles honor it).
19+ REM ---------------------------------------------------------------------------
20+ set " LAUNCH = "
21+ if /I " %USE_CACHE% " == " true" (
22+ where sccache > nul 2 >& 1
23+ if errorlevel 1 (
24+ echo build.bat: USE_CACHE=true but sccache not on PATH; building WITHOUT cache.
25+ ) else (
26+ set " PROBE_DIR = %TEMP% \sccache-probe-%RANDOM% "
27+ mkdir " !PROBE_DIR! " > nul 2 >& 1
28+ (echo int sccache_probe_verify = 0;)> " !PROBE_DIR! \probe.c"
29+ sccache cl.exe /nologo /c " !PROBE_DIR! \probe.c" /Fo" !PROBE_DIR! \probe.obj" > " !PROBE_DIR! \probe.log" 2 >& 1
30+ if errorlevel 1 (
31+ echo build.bat: sccache probe FAILED wrapping cl.exe -- building WITHOUT cache.
32+ type " !PROBE_DIR! \probe.log"
33+ ) else (
34+ echo build.bat: sccache probe OK ^ (wrapped cl.exe^ ).
35+ set " LAUNCH = -DCMAKE_C_COMPILER_LAUNCHER=sccache -DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
36+ )
37+ rmdir /s /q " !PROBE_DIR! " > nul 2 >& 1
38+ )
39+ )
740
841mkdir build
9- cmake -Bbuild %*
42+ cmake -Bbuild %LAUNCH% %*
43+ if errorlevel 1 exit /b %ERRORLEVEL%
1044cmake --build build --config Release
45+ if errorlevel 1 exit /b %ERRORLEVEL%
1146
12- if errorlevel 1 exit /b %ERRORLEVEL%
47+ REM Only query stats when sccache was actually wired in as the launcher; re-invoking
48+ REM a rejected/crashing sccache here would just repeat its failure output.
49+ if defined LAUNCH (
50+ echo build.bat: sccache --show-stats
51+ sccache --show-stats
52+ )
0 commit comments