Skip to content

Commit 481d661

Browse files
committed
ci: use sccache for windows builds
1 parent 94a1a7b commit 481d661

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

.circleci/build_win.ps1

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,28 @@ else {
1818
mkdir build
1919
cd build
2020
$boost_dir=(Resolve-Path $PSScriptRoot\..\deps\boost\lib\cmake\Boost-*)
21-
..\deps\cmake\bin\cmake -G "Visual Studio 16 2019" -DBoost_DIR="$boost_dir\" -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_INSTALL_PREFIX="$PSScriptRoot\..\upload" ..
21+
22+
# Configure CMake with sccache if available
23+
$cmakeArgs = @(
24+
"-G", "Visual Studio 16 2019",
25+
"-DBoost_DIR=$boost_dir\",
26+
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded",
27+
"-DCMAKE_INSTALL_PREFIX=$PSScriptRoot\..\upload"
28+
)
29+
30+
# Check if sccache is available and add it as compiler launcher
31+
$sccachePath = Get-Command sccache -ErrorAction SilentlyContinue
32+
if ($sccachePath) {
33+
Write-Host "Configuring CMake to use sccache"
34+
$cmakeArgs += "-DCMAKE_CXX_COMPILER_LAUNCHER=sccache"
35+
$cmakeArgs += "-DCMAKE_C_COMPILER_LAUNCHER=sccache"
36+
} else {
37+
Write-Host "sccache not found, building without cache"
38+
}
39+
40+
..\deps\cmake\bin\cmake @cmakeArgs ..
2241
if ( -not $? ) { throw "CMake configure failed." }
23-
msbuild solidity.sln /p:Configuration=Release /m:10 /v:minimal
42+
..\deps\cmake\bin\cmake --build . --config Release -j 10
2443
if ( -not $? ) { throw "Build failed." }
2544
..\deps\cmake\bin\cmake --build . -j 10 --target install --config Release
2645
if ( -not $? ) { throw "Install target failed." }

.circleci/config.yml

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,74 @@ commands:
252252
paths:
253253
- ~/.ccache
254254

255+
setup_sccache:
256+
steps:
257+
- run:
258+
name: Create CMake files checksum
259+
command: |
260+
Get-ChildItem -Path . -Filter "CMakeLists.txt" -Recurse | Get-Content | Out-File -FilePath C:\Users\circleci\all-cmake-files.txt -Encoding UTF8
261+
shell: powershell.exe
262+
- restore_cache:
263+
keys:
264+
- sccache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "C:\\Users\\circleci\\all-cmake-files.txt" }}
265+
- sccache-v1-{{ arch }}-{{ .Branch }}-
266+
- sccache-v1-{{ arch }}-
267+
- run:
268+
name: Install and configure sccache
269+
command: |
270+
# Check if sccache is already installed
271+
$sccachePath = Get-Command sccache -ErrorAction SilentlyContinue
272+
if (-not $sccachePath) {
273+
Write-Host "Installing sccache..."
274+
# Download sccache
275+
$sccacheVersion = "v0.8.2"
276+
$sccacheUrl = "https://github.com/mozilla/sccache/releases/download/$sccacheVersion/sccache-$sccacheVersion-x86_64-pc-windows-msvc.tar.gz"
277+
Invoke-WebRequest -Uri $sccacheUrl -OutFile sccache.tar.gz -UserAgent ""
278+
279+
# Extract sccache
280+
tar -xf sccache.tar.gz
281+
$sccacheDir = Get-ChildItem -Directory -Filter "sccache-*" | Select-Object -First 1
282+
Move-Item "$sccacheDir\sccache.exe" "C:\Windows\System32\"
283+
Remove-Item sccache.tar.gz
284+
Remove-Item -Recurse $sccacheDir
285+
}
286+
287+
# Configure sccache
288+
$env:SCCACHE_CACHE_SIZE = "2G"
289+
$env:SCCACHE_DIR = "C:\Users\circleci\sccache"
290+
[Environment]::SetEnvironmentVariable("SCCACHE_CACHE_SIZE", "2G", "Machine")
291+
[Environment]::SetEnvironmentVariable("SCCACHE_DIR", "C:\Users\circleci\sccache", "Machine")
292+
293+
# Create sccache directory if it doesn't exist
294+
if (-not (Test-Path "C:\Users\circleci\sccache")) {
295+
New-Item -ItemType Directory -Path "C:\Users\circleci\sccache" -Force | Out-Null
296+
}
297+
298+
# Start sccache server and show initial stats
299+
sccache --stop-server | Out-Null
300+
sccache --start-server
301+
Write-Host "sccache initial stats:"
302+
sccache --show-stats
303+
shell: powershell.exe
304+
305+
finalize_sccache:
306+
steps:
307+
- run:
308+
name: Show sccache stats
309+
command: |
310+
$sccachePath = Get-Command sccache -ErrorAction SilentlyContinue
311+
if ($sccachePath) {
312+
Write-Host "sccache final stats:"
313+
sccache --show-stats
314+
} else {
315+
Write-Host "sccache not available"
316+
}
317+
shell: powershell.exe
318+
- save_cache:
319+
key: sccache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "C:\\Users\\circleci\\all-cmake-files.txt" }}
320+
paths:
321+
- C:\Users\circleci\sccache
322+
255323
setup_prerelease_commit_hash:
256324
steps:
257325
- run:
@@ -1736,10 +1804,12 @@ jobs:
17361804
key: dependencies-win-{{ arch }}-{{ checksum "scripts/install_deps.ps1" }}
17371805
paths:
17381806
- .\deps
1807+
- setup_sccache
17391808
- run:
17401809
name: "Building solidity"
17411810
command: .circleci/build_win.ps1
17421811
shell: powershell.exe
1812+
- finalize_sccache
17431813
- run:
17441814
name: "Run solc.exe to make sure build was successful."
17451815
command: .\build\solc\Release\solc.exe --version

0 commit comments

Comments
 (0)