Skip to content

Commit 870819d

Browse files
committed
Add new workflow.
1 parent 6fcf27b commit 870819d

20 files changed

+174
-2248
lines changed

.github/workflows/ci-linux.yaml

Lines changed: 0 additions & 88 deletions
This file was deleted.

.github/workflows/ci-windows.yaml

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
# Copyright (c) 2021 Luca Cappa
2+
# Released under the term specified in file LICENSE.txt
3+
# SPDX short identifier: MIT
4+
5+
# A "pure" GitHub workflow using CMake, Ninja and vcpkg to build a C/C++ codebase.
6+
# It leverages both CMakePresets.json and vcpkg.json to have consistent build locallly
7+
# and on continuous integration servers (aka build agents).
8+
# It is called "pure workflow" because it is an example which minimizes the usage of
9+
# custom GitHub actions, but leverages directly the tools that could be easily run on
10+
# your development machines (i.e. CMake, vcpkg, Ninja) to ensure a perfectly identical
11+
# and reproducible build locally (on your development machine) and remotely (on build agents).
12+
name: hosted-pure-workflow
13+
on: [ push, workflow_dispatch ]
14+
15+
jobs:
16+
job:
17+
name: ${{ matrix.os }}-${{ github.workflow }}
18+
runs-on: ${{ matrix.os }}
19+
strategy:
20+
fail-fast: false
21+
matrix:
22+
os: [ ubuntu-latest, macos-latest, windows-latest ]
23+
include:
24+
- os: windows-latest
25+
triplet: x64-windows
26+
- os: ubuntu-latest
27+
triplet: x64-linux
28+
- os: macos-latest
29+
triplet: x64-osx
30+
env:
31+
# Indicates the location of the vcpkg as a Git submodule of the project repository.
32+
VCPKG_ROOT: ${{ github.workspace }}/vcpkg
33+
# Tells vcpkg where binary packages are stored.
34+
VCPKG_DEFAULT_BINARY_CACHE: ${{ github.workspace }}/vcpkg/bincache
35+
36+
steps:
37+
- uses: actions/checkout@v2
38+
with:
39+
submodules: true
40+
41+
- name: "Create directory '${{ env.VCPKG_DEFAULT_BINARY_CACHE }}'"
42+
run: mkdir -p $VCPKG_DEFAULT_BINARY_CACHE
43+
shell: bash
44+
45+
# Setup the build machine with the most recent versions of CMake and Ninja. Both are cached if not already: on subsequent runs both will be quickly restored from GitHub cache service.
46+
- uses: lukka/get-cmake@latest
47+
48+
- uses: docker-practice/actions-setup-docker@master
49+
- run: |
50+
if [ "$RUNNER_OS" != "Windows" ]; then
51+
docker pull crossbario/crossbar
52+
else
53+
echo "Skipping on Windows."
54+
fi
55+
shell: bash
56+
# Restore both vcpkg and its artifacts from the GitHub cache service.
57+
- name: Restore Dependency Cache.
58+
uses: actions/cache@v2
59+
with:
60+
# The first path is the location of vcpkg: it contains the vcpkg executable and data files, as long as the
61+
# built package archives (aka binary cache) which are located by VCPKG_DEFAULT_BINARY_CACHE env var.
62+
# The other paths starting with '!' are exclusions: they contain termporary files generated during the build of the installed packages.
63+
path: |
64+
${{ env.VCPKG_ROOT }}
65+
!${{ env.VCPKG_ROOT }}/buildtrees
66+
!${{ env.VCPKG_ROOT }}/packages
67+
!${{ env.VCPKG_ROOT }}/downloads
68+
!${{ env.VCPKG_ROOT }}/installed
69+
# The key is composed in a way that it gets properly invalidated: this must happen whenever vcpkg's Git commit id changes, or the list of packages changes. In this case a cache miss must happen and a new entry with a new key with be pushed to GitHub the cache service.
70+
# The key includes: hash of the vcpkg.json file, the hash of the vcpkg Git commit id, and the used vcpkg's triplet. The vcpkg's commit id would suffice, but computing an hash out it does not harm.
71+
# Note: given a key, the cache content is immutable. If a cache entry has been created improperly, in order the recreate the right content the key must be changed as well, and it must be brand new (i.e. not existing already).
72+
key: |
73+
${{ hashFiles( 'vcpkg.json' ) }}-${{ hashFiles( '.git/modules/vcpkg/HEAD' )}}-${{ matrix.triplet }}
74+
# On Windows runners, let's ensure to have the Developer Command Prompt environment setup correctly. As used here the Developer Command Prompt created is targeting x64 and using the default the Windows SDK.
75+
- uses: ilammy/msvc-dev-cmd@v1
76+
77+
# Run CMake to generate Ninja project files, using the vcpkg's toolchain file to resolve and install the dependencies as specified in vcpkg.json.
78+
- name: Install Dependencies.
79+
run: |
80+
cmake --preset ninja-multi-vcpkg
81+
82+
# Build the whole project with Ninja (which is spawn by CMake). Debug configuration.
83+
- name: Build.
84+
run: |
85+
cmake --build --preset ninja-multi-vcpkg-debug
86+
# Test the whole project with CTest.
87+
- name: Run Tests.
88+
run: |
89+
if [ "$RUNNER_OS" != "Windows" ]; then
90+
ctest --preset ninja-multi-vcpkg-debug
91+
else
92+
echo "Skipping on Windows."
93+
fi
94+
shell: bash

CMakePresets.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
{
2+
"version": 3,
3+
"cmakeMinimumRequired": {
4+
"major": 3,
5+
"minor": 21,
6+
"patch": 0
7+
},
8+
"configurePresets": [
9+
{
10+
"name": "ninja-multi-vcpkg",
11+
"displayName": "Ninja Multi-Config",
12+
"description": "Configure with vcpkg toolchain and generate Ninja project files for all configurations",
13+
"binaryDir": "${sourceDir}/builds/${presetName}",
14+
"generator": "Ninja Multi-Config",
15+
"cacheVariables": {
16+
"CMAKE_TOOLCHAIN_FILE": {
17+
"type": "FILEPATH",
18+
"value": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
19+
}
20+
}
21+
}
22+
],
23+
"buildPresets": [
24+
{
25+
"name": "ninja-multi-vcpkg-debug",
26+
"configurePreset": "ninja-multi-vcpkg",
27+
"displayName": "Build ninja-multi-vcpkg-debug",
28+
"description": "Build ninja-multi-vcpkg Debug configuration",
29+
"configuration": "Debug"
30+
},
31+
{
32+
"name": "ninja-multi-vcpkg-release",
33+
"configurePreset": "ninja-multi-vcpkg",
34+
"displayName": "Build ninja-multi-vcpkg-release",
35+
"description": "Build ninja-multi-vcpkg Release configuration",
36+
"configuration": "RelWithDebInfo"
37+
}
38+
],
39+
"testPresets": [
40+
{
41+
"name": "ninja-multi-vcpkg-debug",
42+
"configurePreset": "ninja-multi-vcpkg",
43+
"configuration": "Debug"
44+
},
45+
{
46+
"name": "ninja-multi-vcpkg-release",
47+
"configurePreset": "ninja-multi-vcpkg",
48+
"configuration": "RelWithDebInfo"
49+
}
50+
]
51+
}

examples/CMakeLists.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@ make_example(websocket_callee websocket_callee.cpp)
1616
make_example(cryptosign-openssl cryptosign-openssl.cpp)
1717
make_example(cryptosign-botan cryptosign-botan.cpp)
1818

19-
if(UNIX)
19+
if (UNIX)
2020
make_example(uds uds.cpp)
21-
endif()
21+
endif ()
2222

2323
# By default MSVC has a 2^16 limit on the number of sections in an object file,
2424
# and this needs more than that.
2525
if (MSVC)
2626
set_source_files_properties(websocket_callee.cpp PROPERTIES COMPILE_FLAGS /bigobj)
27-
endif()
27+
set_source_files_properties(cryptosign-openssl.cpp PROPERTIES COMPILE_FLAGS /bigobj)
28+
set_source_files_properties(cryptosign-botan.cpp PROPERTIES COMPILE_FLAGS /bigobj)
29+
endif ()

0 commit comments

Comments
 (0)