Skip to content

Commit 3e2ef94

Browse files
committed
ci: use sccache for windows builds
1 parent 94a1a7b commit 3e2ef94

File tree

2 files changed

+112
-2
lines changed

2 files changed

+112
-2
lines changed

.circleci/build_win.ps1

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,33 @@ 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+
$sccachePath = Get-Command sccache -ErrorAction SilentlyContinue
24+
if ($sccachePath) {
25+
Write-Host "Configuring build to use sccache with Ninja generator"
26+
# Use Ninja generator which supports compiler launchers
27+
$cmakeArgs = @(
28+
"-G", "Ninja",
29+
"-DBoost_DIR=$boost_dir\",
30+
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded",
31+
"-DCMAKE_INSTALL_PREFIX=$PSScriptRoot\..\upload",
32+
"-DCMAKE_CXX_COMPILER_LAUNCHER=sccache",
33+
"-DCMAKE_C_COMPILER_LAUNCHER=sccache"
34+
)
35+
} else {
36+
Write-Host "sccache not found, using Visual Studio generator without cache"
37+
$cmakeArgs = @(
38+
"-G", "Visual Studio 16 2019",
39+
"-DBoost_DIR=$boost_dir\",
40+
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded",
41+
"-DCMAKE_INSTALL_PREFIX=$PSScriptRoot\..\upload"
42+
)
43+
}
44+
45+
..\deps\cmake\bin\cmake @cmakeArgs ..
2246
if ( -not $? ) { throw "CMake configure failed." }
23-
msbuild solidity.sln /p:Configuration=Release /m:10 /v:minimal
47+
..\deps\cmake\bin\cmake --build . --config Release -j 10
2448
if ( -not $? ) { throw "Build failed." }
2549
..\deps\cmake\bin\cmake --build . -j 10 --target install --config Release
2650
if ( -not $? ) { throw "Install target failed." }

.circleci/config.yml

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,90 @@ 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+
# Check if Ninja is already installed
288+
$ninjaPath = Get-Command ninja -ErrorAction SilentlyContinue
289+
if (-not $ninjaPath) {
290+
Write-Host "Installing Ninja..."
291+
# Download Ninja
292+
$ninjaVersion = "v1.11.1"
293+
$ninjaUrl = "https://github.com/ninja-build/ninja/releases/download/$ninjaVersion/ninja-win.zip"
294+
Invoke-WebRequest -Uri $ninjaUrl -OutFile ninja.zip -UserAgent ""
295+
296+
# Extract Ninja
297+
Expand-Archive -Path ninja.zip -DestinationPath ninja
298+
Move-Item "ninja\ninja.exe" "C:\Windows\System32\"
299+
Remove-Item ninja.zip
300+
Remove-Item -Recurse ninja
301+
}
302+
303+
# Configure sccache
304+
$env:SCCACHE_CACHE_SIZE = "2G"
305+
$env:SCCACHE_DIR = "C:\Users\circleci\sccache"
306+
[Environment]::SetEnvironmentVariable("SCCACHE_CACHE_SIZE", "2G", "Machine")
307+
[Environment]::SetEnvironmentVariable("SCCACHE_DIR", "C:\Users\circleci\sccache", "Machine")
308+
309+
# Create sccache directory if it doesn't exist
310+
if (-not (Test-Path "C:\Users\circleci\sccache")) {
311+
New-Item -ItemType Directory -Path "C:\Users\circleci\sccache" -Force | Out-Null
312+
}
313+
314+
# Start sccache server and show initial stats
315+
sccache --stop-server | Out-Null
316+
sccache --start-server
317+
Write-Host "sccache initial stats:"
318+
sccache --show-stats
319+
shell: powershell.exe
320+
321+
finalize_sccache:
322+
steps:
323+
- run:
324+
name: Show sccache stats
325+
command: |
326+
$sccachePath = Get-Command sccache -ErrorAction SilentlyContinue
327+
if ($sccachePath) {
328+
Write-Host "sccache final stats:"
329+
sccache --show-stats
330+
} else {
331+
Write-Host "sccache not available"
332+
}
333+
shell: powershell.exe
334+
- save_cache:
335+
key: sccache-v1-{{ arch }}-{{ .Branch }}-{{ checksum "C:\\Users\\circleci\\all-cmake-files.txt" }}
336+
paths:
337+
- C:\Users\circleci\sccache
338+
255339
setup_prerelease_commit_hash:
256340
steps:
257341
- run:
@@ -1736,10 +1820,12 @@ jobs:
17361820
key: dependencies-win-{{ arch }}-{{ checksum "scripts/install_deps.ps1" }}
17371821
paths:
17381822
- .\deps
1823+
- setup_sccache
17391824
- run:
17401825
name: "Building solidity"
17411826
command: .circleci/build_win.ps1
17421827
shell: powershell.exe
1828+
- finalize_sccache
17431829
- run:
17441830
name: "Run solc.exe to make sure build was successful."
17451831
command: .\build\solc\Release\solc.exe --version

0 commit comments

Comments
 (0)