Skip to content

Commit

Permalink
Merge pull request #60385 from akrieger/ccache_msvc
Browse files Browse the repository at this point in the history
ccache support in Visual Studio
  • Loading branch information
kevingranade authored Sep 1, 2022
2 parents cb944bf + a330505 commit d8ef623
Show file tree
Hide file tree
Showing 15 changed files with 199 additions and 131 deletions.
31 changes: 18 additions & 13 deletions .github/workflows/matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ jobs:
title: Basic Build and Test (Clang 6, Ubuntu, Curses)
# ~190MB in a clean build
# ~30MB compressed
# .16 : 1 -> max ~485MB
ccache_limit: 3G
# observed usage: 3.0GB -> 300MB
ccache_limit: 2G

- compiler: g++-9
os: ubuntu-latest
Expand All @@ -109,8 +109,8 @@ jobs:
title: GCC 9, Curses, LTO
# ~850MB in a clean build
# ~370MB compressed
# .44 : 1 -> max ~1.8G
ccache_limit: 4G
# observed usage: 4.0GB -> 1.5GB
ccache_limit: 3G

- compiler: clang++-12
os: ubuntu-latest
Expand All @@ -126,8 +126,8 @@ jobs:
title: Clang 12, Ubuntu, Tiles, ASan
# ~390MB in a clean build
# ~50MB compressed
# .13 : 1 -> max ~540MB
ccache_limit: 4G
# observed usage: 4.0GB -> 400MB
ccache_limit: 3G

- compiler: g++-11
os: ubuntu-latest
Expand All @@ -141,8 +141,8 @@ jobs:
title: GCC 11, Ubuntu, Curses, ASan
# ~480MB in a clean build
# ~50MB compressed
# .10 : 1 -> max ~530MB
ccache_limit: 5G
# observed usage: 4.4GB -> 400MB
ccache_limit: 4G

- compiler: clang++
os: macos-10.15
Expand All @@ -156,7 +156,7 @@ jobs:
title: Clang 12, macOS 10.15, Tiles, Sound, UBSan
# ~880MB ccache-compressed in a clean build
# ~100 compressed
# .11 : 1 -> max ~450MB
# observed usage: 3.85GB -> 500MB
ccache_limit: 4G

- compiler: g++
Expand All @@ -174,8 +174,8 @@ jobs:
wine: wine
# ~285MB in a clean build
# ~36MB compressed
# .12 : 1 -> max ~390MB
ccache_limit: 3G
# observed usage: 3.0GB -> 350MB
ccache_limit: 2G

- compiler: g++-7
os: ubuntu-18.04
Expand All @@ -188,8 +188,13 @@ jobs:
title: GCC 7, Ubuntu, Tiles, Sound, CMake
# ~180MB in a clean build
# ~25MB compressed
# .14 : 1 -> max ~430MB
ccache_limit: 3G
# observed usage: 3.0GB -> 300MB
ccache_limit: 2G

# Reserving space for msvc ccache & vcpkg cache
# observed usage:
# vcpkg: ??? -> 500MB
# ccache: 8GB -> 1.0GB

name: ${{ matrix.title }}
runs-on: ${{ matrix.os }}
Expand Down
98 changes: 93 additions & 5 deletions .github/workflows/msvc-full-features.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ concurrency:
cancel-in-progress: true

env:
# Compressed size ~1GB based on observations
CCACHE_LIMIT: 8GB
CDDA_CCACHE_PATH: ${{ github.workspace }}\ccache\
CDDA_USE_CCACHE: true
# There's not enough disk space to build both release and debug versions of
# our dependencies, so we hack the triplet file to build only release versions
# Have to use github.workspace because runner namespace isn't available yet.
VCPKG_OVERLAY_TRIPLETS: ${{ github.workspace }}\.github\vcpkg_triplets
# Also conveniently disable ccache internal compression
CCACHE_HARDLINK: true
# vcpkg with object_creator deps totals ~500MB at this compression level
ZSTD_CLEVEL: 17

jobs:
Expand All @@ -61,8 +68,14 @@ jobs:
- name: Add msbuild to PATH
uses: microsoft/[email protected]

- name: Use GNU tar to enable zstd for actions/cache
run: |
echo "Adding GNU tar to PATH"
echo C:\Program Files\Git\usr\bin>>"%GITHUB_PATH%"
shell: cmd

- name: Restore artifacts, or run vcpkg, build and cache artifacts
uses: lukka/run-vcpkg@v10.2
uses: lukka/run-vcpkg@v10.4
id: runvcpkg
with:
# run-vcpkg tries to hash vcpkg.json but complans if it finds more than one.
Expand All @@ -79,17 +92,74 @@ jobs:
run: |
vcpkg integrate install
- name: Download ccache
uses: robinraju/[email protected]
with:
repository: 'ccache/ccache'
tag: 'v4.6.1'
fileName: 'ccache-4.6.1-windows-x86_64.zip'

- name: Install ccache
id: install-ccache
run: |
unzip ccache-4.6.1-windows-x86_64.zip
cp ccache-4.6.1-windows-x86_64/ccache.exe ccache-4.6.1-windows-x86_64/cl.exe
cp ccache-4.6.1-windows-x86_64/ccache.exe ccache-4.6.1-windows-x86_64/clang-cl.exe
mv ccache-4.6.1-windows-x86_64 ${{ env.CDDA_CCACHE_PATH }}
- name: Get ccache vars
id: get-vars
run: |
echo "::set-output name=datetime::$(/bin/date -u "+%Y%m%d%H%M")"
echo "::set-output name=ccache-path::$(echo "$APPDATA\\ccache")"
shell: bash

- name: ccache cache files
uses: actions/cache@v3
with:
path: ${{ steps.get-vars.outputs.ccache-path }}
# double-dash after compiler is not a typo, it is to disambiguate between g++-<date> and g++-11-<date> for restore key prefix matching
key: ccache-${{ github.ref_name }}-${{ runner.os }}-msvc--${{ steps.get-vars.outputs.datetime }}
restore-keys: |
ccache-master-${{ runner.os }}-msvc--
- name: Configure ccache
run: |
${{ env.CDDA_CCACHE_PATH }}\ccache.exe -M 10G
${{ env.CDDA_CCACHE_PATH }}\ccache.exe -s -v
${{ env.CDDA_CCACHE_PATH }}\ccache.exe -z
- name: Symlink intermediates to C
run: |
mkdir -p "$env:TEMP\objwin"
New-Item -ItemType SymbolicLink -Target "$env:TEMP\objwin" objwin
- name: Build
run: |
cd msvc-full-features
msbuild -m -p:Configuration=Release -p:Platform=x64 "-target:Cataclysm-vcpkg-static;Cataclysm-test-vcpkg-static;JsonFormatter-vcpkg-static" Cataclysm-vcpkg-static.sln
msbuild -m -p:Configuration=Release -p:Platform=x64 "-target:Cataclysm-vcpkg-static;Cataclysm-test-vcpkg-static;JsonFormatter-vcpkg-static;ObjectCreator-vcpkg-static" Cataclysm-vcpkg-static.sln
- name: Dump logs if build failed
- name: Post-build ccache manipulation
if: ${{ !failure() }}
run: |
${{ env.CDDA_CCACHE_PATH }}\ccache.exe -s -v
${{ env.CDDA_CCACHE_PATH }}\ccache.exe -M ${{ env.CCACHE_LIMIT }}
${{ env.CDDA_CCACHE_PATH }}\ccache.exe -c
${{ env.CDDA_CCACHE_PATH }}\ccache.exe -s -v
- name: clear ccache on PRs
if: ${{ github.ref_name != 'master' }}
run: |
${{ env.CDDA_CCACHE_PATH }}\ccache.exe -C
- name: Dump vcpkg logs if build failed
if: failure()
run: |
echo =================================================
Get-ChildItem "${{ runner.workspace }}/Cataclysm-DDA/msvc-full-features/vcpkg_installed" -Recurse
echo =================================================
Get-ChildItem "${{ runner.workspace }}/Cataclysm-DDA/msvc-object_creator/vcpkg_installed" -Recurse
echo =================================================
Get-ChildItem "${{ runner.workspace }}/b/vcpkg/buildtrees" |
Foreach-Object {
Get-ChildItem $_.FullName -Filter *.log |
Expand All @@ -116,6 +186,24 @@ jobs:
run: |
.\Cataclysm-test-vcpkg-static-Release-x64.exe --min-duration 0.2 --rng-seed time
- name: Clean
- name: Dump disk usage logs if job failed
if: failure()
run: |
echo =================================================
df
echo =================================================
du -sh *
echo =================================================
du -sh msvc-full-features/*
echo =================================================
du -sh msvc-object_creator/*
echo =================================================
du -sh tools/*
echo =================================================
shell: bash

- name: Don't upload vcpkg cache on failure or PRs
if: ${{ failure() || cancelled() || github.ref_name != 'master' }}
run: |
Get-ChildItem -Path Cataclysm-lib-vcpkg-static-Release-x64.* | Foreach-Object { rm $_.FullName }
echo "RUNVCPKG_NO_CACHE=1" >> $GITHUB_ENV
shell: bash
107 changes: 0 additions & 107 deletions .github/workflows/object_creator.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ json_formatter
*.lastbuildstate
.vs/
.vscode/
Directory.Build.props
Directory.Build.targets

# Visual Studio project files
/msvc-full-features/**/
Expand Down
29 changes: 29 additions & 0 deletions doc/COMPILING/COMPILING-VS-VCPKG.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,32 @@ It is recommended you run the unit tests in a Release configuration. Debug build
### Make a distribution

There is a batch script in `msvc-full-features` folder `distribute.bat`. It will create a sub folder `distribution` and copy all required files(eg. `data/`, `Cataclysm.exe` and dlls) into that folder. Then you can zip it and share the archive on the Internet.

### ccache integration

It is possible to use ccache with Visual Studio and gain the same benefits as other platforms.

1. Download the "Windows x86_64 (binary release)" of ccache from https://ccache.dev/download.html.

- Note: Version 4.6.2 has a bug which causes a spammy warning on build. As of now, version 4.6.1 is known to work and not cause spam on build. You can download version 4.6.1 from https://github.com/ccache/ccache/releases/tag/v4.6.1, it is the "ccache-4.6.1-windows-x86_64.zip" option under Assets.

2. Extract the contents of the zip file somewhere convenient but not on $PATH.

- For example, if Cataclysm is checked out at `C:/dev/Cataclysm-DDA/`, then extract the folder and move the contents to `C:/dev/ccache/`. Verify the binary exists at `C:/dev/ccache/ccache.exe`.

3. Create a copy of `ccache.exe` in the same folder, called `cl.exe`.

- If you use the LLVM toolchain ("clang-cl.exe") when building, make another copy of `ccache.exe` called `clang-cl.exe`.

4. Create a file called `Directory.Build.props` at the root of the Cataclysm-DDA folder with the following contents. The value of `CDDA_CCACHE_PATH` should be the folder where you put `ccache.exe`. Assuming this path is `C:\dev\ccache\` (note: `\` vs `/` matters, you need to use `\` here):

```
<Project>
<PropertyGroup>
<CDDA_USE_CCACHE>true</CDDA_USE_CCACHE>
<CDDA_CCACHE_PATH>C:\dev\ccache\</CDDA_CCACHE_PATH>
</PropertyGroup>
</Project>
```

5. ccache should now just work when building with Release modes in Visual Studio. Debug builds do not work because of limitations from the size of CDDA and the msvc toolchain. However, Debug builds are almost intolerably slow anyway so this limitation is not something we are going to fix right now.
Loading

0 comments on commit d8ef623

Please sign in to comment.