Skip to content

Commit 8754ee8

Browse files
committed
ci: use sccache for windows builds
1 parent 94a1a7b commit 8754ee8

File tree

2 files changed

+125
-2
lines changed

2 files changed

+125
-2
lines changed

.circleci/build_win.ps1

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
$ErrorActionPreference = "Stop"
22

3+
# Initialize Visual Studio environment
4+
$vcvarsall = "C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\VC\Auxiliary\Build\vcvarsall.bat"
5+
if (Test-Path $vcvarsall) {
6+
cmd.exe /c "`"$vcvarsall`" amd64 && set" |
7+
ForEach-Object {
8+
if ($_ -match "=") {
9+
$v = $_.split("=", 2); set-item -force -path "ENV:\$($v[0])" -value "$($v[1])"
10+
}
11+
}
12+
} else {
13+
Write-Host "Warning: vcvarsall.bat not found at $vcvarsall. Assuming compilers are in the PATH."
14+
}
15+
316
cd "$PSScriptRoot\.."
417

518
if ("$Env:FORCE_RELEASE" -Or "$Env:CIRCLE_TAG") {
@@ -18,9 +31,33 @@ else {
1831
mkdir build
1932
cd build
2033
$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" ..
34+
35+
# Configure CMake with sccache if available
36+
$sccachePath = Get-Command sccache -ErrorAction SilentlyContinue
37+
if ($sccachePath) {
38+
Write-Host "Configuring build to use sccache with Ninja generator"
39+
# Use Ninja generator which supports compiler launchers
40+
$cmakeArgs = @(
41+
"-G", "Ninja",
42+
"-DBoost_DIR=$boost_dir\",
43+
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded",
44+
"-DCMAKE_INSTALL_PREFIX=$PSScriptRoot\..\upload",
45+
"-DCMAKE_CXX_COMPILER_LAUNCHER=sccache",
46+
"-DCMAKE_C_COMPILER_LAUNCHER=sccache"
47+
)
48+
} else {
49+
Write-Host "sccache not found, using Visual Studio generator without cache"
50+
$cmakeArgs = @(
51+
"-G", "Visual Studio 16 2019",
52+
"-DBoost_DIR=$boost_dir\",
53+
"-DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded",
54+
"-DCMAKE_INSTALL_PREFIX=$PSScriptRoot\..\upload"
55+
)
56+
}
57+
58+
..\deps\cmake\bin\cmake @cmakeArgs ..
2259
if ( -not $? ) { throw "CMake configure failed." }
23-
msbuild solidity.sln /p:Configuration=Release /m:10 /v:minimal
60+
..\deps\cmake\bin\cmake --build . --config Release -j 10
2461
if ( -not $? ) { throw "Build failed." }
2562
..\deps\cmake\bin\cmake --build . -j 10 --target install --config Release
2663
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)