Tutorial: Set up a vcpkg binary cache using GitHub Actions Cache

Note

This section covers an experimental feature of vcpkg which may change or be removed at any time.

vcpkg supports using the GitHub Actions cache as binary caching storage when running in the context of a GitHub Actions workflow. If you don't care about uploading binary packages to an external NuGet feed, this is the recommended method to use binary caching in a GitHub Actions workflow. Otherwise, read the tutorial to use GitHub Packages in a GitHub Actions workflow.

In this tutorial, you'll learn how to:

Prerequisites

  • A code editor
  • A GitHub repository using GitHub Actions
  • A project using vcpkg

1 - Export required GitHub Actions environment variables

vcpkg needs the Actions Cache URL and Runtime Token to be exported as environment variables available in your workflow. Copy the following step in your workflow file:

- name: Export GitHub Actions cache environment variables
  uses: actions/github-script@v7
  with:
    script: |
      core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
      core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

2 - Configure vcpkg to use the GitHub Actions cache

Next set the value of VCPKG_BINARY_SOURCES as follows:

env: 
    VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"

And that's it! vcpkg will now upload or restore packages from your GitHub Actions cache.

Next steps

Here are other tasks to try next: