Skip to content

Commit

Permalink
Enabled vcpkg dependecies binary caching to GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
SNMetamorph committed Apr 23, 2023
1 parent 8a9a5c2 commit 6384ec3
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/nightly-builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,25 @@ jobs:
- os: windows-latest
cmake_preset: ci-windows-x86
build_conf: Debug

env:
# Indicates the location of the vcpkg as a Git submodule of the project repository.
VCPKG_ROOT: ${{ github.workspace }}/external/vcpkg
# Tells vcpkg where binary packages are stored.
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/external/vcpkg/bincache
# Let's use GitHub Action cache as storage for the vcpkg Binary Caching feature.
VCPKG_BINARY_SOURCES: 'clear;x-gha,readwrite'

steps:
# Set env vars needed for vcpkg to leverage the GitHub Action cache as a storage
# for Binary Caching.
- name: Set env vars needed for vcpkg to leverage the GitHub Action cache
uses: actions/github-script@v6
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
- name: Checkout repository
uses: actions/checkout@v3
with:
Expand All @@ -21,6 +39,28 @@ jobs:
# We'll use this as our working directory for all subsequent commands
run: cmake -E make_directory ${{github.workspace}}/build

- name: "Create directory '${{ env.VCPKG_DEFAULT_BINARY_CACHE }}'"
shell: bash
run: mkdir -p $VCPKG_DEFAULT_BINARY_CACHE

# Restore vcpkg from the GitHub Action cache service. Note that packages are restored by vcpkg's binary caching
# when it is being run afterwards by CMake.
- name: Restore vcpkg
uses: actions/cache@v3
with:
# The first path is the location of vcpkg: it contains the vcpkg executable and data files, as long as the
# built package archives (aka binary cache) which are located by VCPKG_DEFAULT_BINARY_CACHE env var.
# The other paths starting with '!' are exclusions: they contain termporary files generated during the build of the installed packages.
path: |
${{ env.VCPKG_ROOT }}
!${{ env.VCPKG_ROOT }}/buildtrees
!${{ env.VCPKG_ROOT }}/packages
!${{ env.VCPKG_ROOT }}/downloads
!${{ env.VCPKG_ROOT }}/installed
# The key is composed in a way that it gets properly invalidated whenever a different version of vcpkg is being used.
key: |
${{ hashFiles( '.git/modules/external/vcpkg/HEAD' )}}
- name: Configure CMake
# Use a bash shell so we can use the same syntax for environment variable
# access regardless of the host operating system
Expand Down
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ if(NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
endif()

set(VCPKG_OVERLAY_PORTS "${CMAKE_SOURCE_DIR}/vcpkg/overlay_ports")
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/external/vcpkg/scripts/buildsystems/vcpkg.cmake")
if(EXTERNAL_VCPKG_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE ${EXTERNAL_VCPKG_TOOLCHAIN_FILE})
else()
set(CMAKE_TOOLCHAIN_FILE "${CMAKE_SOURCE_DIR}/external/vcpkg/scripts/buildsystems/vcpkg.cmake")
endif()
project(goldsrc-monitor)

# Build options
Expand Down
6 changes: 5 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@
"strategy": "set"
},
"cacheVariables": {
"VCPKG_TARGET_TRIPLET": "x86-windows-static"
"VCPKG_TARGET_TRIPLET": "x86-windows-static",
"EXTERNAL_VCPKG_TOOLCHAIN_FILE": {
"type": "FILEPATH",
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
}
},
"vendor": { "microsoft.com/VisualStudioSettings/CMake/1.0": { "hostOS": [ "Windows" ] } }
}
Expand Down

0 comments on commit 6384ec3

Please sign in to comment.