The run-vcpkg action restores from cache vcpkg along with the previously installed ports. Briefly:
- If there is a cache miss, vpckg is fetched and installed; the cache's key is composed by hashing the hosting OS name, the command line arguments and the vcpkg's commit id.
- Restoring from cache can be skipped with
doNotCache:true
.
- Restoring from cache can be skipped with
- Then
vcpkg
is run to install the desired ports. This is a no-op if artifacts are already restored.- This step can be skipped with
setupOnly:true
.
- This step can be skipped with
- Artifacts and vcpkg are then saved in cache (if it was a 'cache miss').
- Saving to cache can be skipped with
doNotCache:true
.
- Saving to cache can be skipped with
The provided samples use GitHub hosted runners.
Good companions are the run-cmake action and the get-cmake actions.
- Contributing
- Quickstart
- Best practices
- Action reference: all input/output parameters
- Samples
- Projects
Read CONTRIBUTING.md
It is highly recommended to use vcpkg as a submodule. Here below the sample where vcpkg is a Git submodule:
# Sample when vcpkg is a submodule of your repository (highly recommended!)
#-uses: actions/cache@v1 <===== YOU DO NOT NEED THIS!
# Install latest CMake.
- uses: lukka/get-cmake@latest
# Restore from cache the previously built ports. If "cache miss", then provision vcpkg, install desired ports, finally cache everything for the next run.
- name: Restore from cache and run vcpkg
uses: lukka/run-vcpkg@v5
with:
# Response file stored in source control, it provides the list of ports and triplet(s).
vcpkgArguments: '@${{ env.vcpkgResponseFile }}'
# Location of the vcpkg as submodule of the repository.
vcpkgDirectory: '${{ github.workspace }}/vcpkg'
# Since the cache must be invalidated when content of the response file changes, let's
# compute its hash and append this to the computed cache's key.
appendedCacheKey: ${{ hashFiles(env.vcpkgResponseFile) }}
- name: 'Build with CMake and Ninja'
uses: lukka/run-cmake@v3
with:
cmakeListsOrSettingsJson: CMakeListsTxtAdvanced
cmakeListsTxtPath: '${{ github.workspace }}/cmakesettings.json/CMakeLists.txt'
useVcpkgToolchainFile: true
buildDirectory: '${{ runner.workspace }}/b/ninja'
cmakeAppendedArgs: '-GNinja Multi-Config'
# Or build multiple configurations out of a CMakeSettings.json file created with Visual Studio.
# cmakeListsOrSettingsJson: CMakeSettingsJson
# cmakeSettingsJsonPath: '${{ github.workspace }}/cmakesettings.json/CMakeSettings.json'
# configurationRegexFilter: '${{ matrix.configuration }}'
When setupOnly: true
, it only setups vcpkg and set VCPKG_ROOT environment variable without installing any port. The provisioned vcpkg can then be used as follows in a subsequent step:
# Restore from cache the previously built ports. If cache-miss, download, build vcpkg.
- name: Restore from cache and install vcpkg
# Download and build vcpkg, without installing any port. If content is cached already, it is a no-op.
uses: lukka/run-vcpkg@v5
with:
setupOnly: true
# Now that vcpkg is installed, it is being used to run desired arguments.
- run: |
$VCPKG_ROOT/vcpkg @$vcpkgResponseFile
$VCPKG_ROOT/vcpkg install boost:linux-x64
shell: bash
When using vcpkg, be aware of how it works, specifically:
- a specific version of vcpkg must be used either locally and on build servers;
- a specific version of vcpkg is identified by the commit id of the used vcpkg repository;
- it not possible to choose which version of a port to install, instead it is the used version of vcpkg that establishes which version (just one) of a port is available;
To sum up, you need to pin the specific version of vcpkg you want to use to keep a consistent development experience between local and remote build environments. This is accomplished by using vcpkg as submodule of your Git repository; this way the version of vcpkg used is implied by the commit id specified by the submodule for vcpkg.
vcpkg accepts a response file that contains the arguments, suitable to store the list of ports to be installed. It is useful to store the response file under source control, this helps to run vcpkg the same exact way locally and remotely on the build servers. For example if you want to run:
vcpkg install boost zlib:x64 libmodbus --triplet x64
it is instead possible to run
vcpkg install @response_file.txt
where response_file.txt
contains (with no trailing whitespaces allowed):
boost
zlib:x64
libmodbus
--triplet
x64
View the workflows based on the run-cmake and run-vcpkg actions.
CMakeSettings.json samples | |
---|---|
Linux/macOS/Windows, hosted runner, with vcpkg as submodule |
All the content in this repository is licensed under the MIT License.
Copyright (c) 2019-2020 Luca Cappa
Other than submitting a pull request, donating is another way to contribute to this project.