Debian Codegraph @

protolib/.github/workflows/cmake.yml

raw
1 name: CMake build
2
3 on: [push, pull_request]
4
5 env:
6 CMAKE_VERSION: 3.16.2
7 NINJA_VERSION: 1.9.0
8 BUILD_TYPE: Release
9 CCACHE_VERSION: 3.7.7
10
11 jobs:
12 build:
13 name: ${{ matrix.config.name }}
14 runs-on: ${{ matrix.config.os }}
15 strategy:
16 fail-fast: false
17 matrix:
18 config:
19 - {
20 name: "Windows Latest MSVC", artifact: "Windows-MSVC.tar.xz",
21 os: windows-latest,
22 cc: "cl", cxx: "cl",
23 environment_script: "C:/Program Files (x86)/Microsoft Visual Studio/2019/Enterprise/VC/Auxiliary/Build/vcvars64.bat"
24 }
25 - {
26 name: "Windows Latest MinGW", artifact: "Windows-MinGW.tar.xz",
27 os: windows-latest,
28 cc: "gcc", cxx: "g++"
29 }
30 - {
31 name: "Ubuntu Latest GCC", artifact: "Linux.tar.xz",
32 os: ubuntu-latest,
33 cc: "gcc", cxx: "g++"
34 }
35 - {
36 name: "macOS Latest Clang", artifact: "macOS.tar.xz",
37 os: macos-latest,
38 cc: "clang", cxx: "clang++"
39 }
40
41 steps:
42 - uses: actions/checkout@v1
43
44 - name: Download Ninja and CMake
45 id: cmake_and_ninja
46 shell: cmake -P {0}
47 run: |
48 set(cmake_version $ENV{CMAKE_VERSION})
49 set(ninja_version $ENV{NINJA_VERSION})
50 message(STATUS "Using host CMake version: ${CMAKE_VERSION}")
51 if ("${{ runner.os }}" STREQUAL "Windows")
52 set(ninja_suffix "win.zip")
53 set(cmake_suffix "win64-x64.zip")
54 set(cmake_dir "cmake-${cmake_version}-win64-x64/bin")
55 elseif ("${{ runner.os }}" STREQUAL "Linux")
56 set(ninja_suffix "linux.zip")
57 set(cmake_suffix "Linux-x86_64.tar.gz")
58 set(cmake_dir "cmake-${cmake_version}-Linux-x86_64/bin")
59 elseif ("${{ runner.os }}" STREQUAL "macOS")
60 set(ninja_suffix "mac.zip")
61 set(cmake_suffix "Darwin-x86_64.tar.gz")
62 set(cmake_dir "cmake-${cmake_version}-Darwin-x86_64/CMake.app/Contents/bin")
63 endif()
64 set(ninja_url "https://github.com/ninja-build/ninja/releases/download/v${ninja_version}/ninja-${ninja_suffix}")
65 file(DOWNLOAD "${ninja_url}" ./ninja.zip SHOW_PROGRESS)
66 execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./ninja.zip)
67 set(cmake_url "https://github.com/Kitware/CMake/releases/download/v${cmake_version}/cmake-${cmake_version}-${cmake_suffix}")
68 file(DOWNLOAD "${cmake_url}" ./cmake.zip SHOW_PROGRESS)
69 execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./cmake.zip)
70 # Save the path for other steps
71 file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}/${cmake_dir}" cmake_dir)
72 message("::set-output name=cmake_dir::${cmake_dir}")
73 if (NOT "${{ runner.os }}" STREQUAL "Windows")
74 execute_process(
75 COMMAND chmod +x ninja
76 COMMAND chmod +x ${cmake_dir}/cmake
77 )
78 endif()
79 - name: Download ccache
80 id: ccache
81 shell: cmake -P {0}
82 run: |
83 set(ccache_url "https://github.com/cristianadam/ccache/releases/download/v$ENV{CCACHE_VERSION}/${{ runner.os }}.tar.xz")
84 file(DOWNLOAD "${ccache_url}" ./ccache.tar.xz SHOW_PROGRESS)
85 execute_process(COMMAND ${CMAKE_COMMAND} -E tar xvf ./ccache.tar.xz)
86 - name: Prepare ccache timestamp
87 id: ccache_cache_timestamp
88 shell: cmake -P {0}
89 run: |
90 string(TIMESTAMP current_date "%Y-%m-%d-%H;%M;%S" UTC)
91 message("::set-output name=timestamp::${current_date}")
92 - name: ccache cache files
93 uses: actions/[email protected]
94 with:
95 path: .ccache
96 key: ${{ matrix.config.name }}-ccache-${{ steps.ccache_cache_timestamp.outputs.timestamp }}
97 restore-keys: |
98 ${{ matrix.config.name }}-ccache-
99 - name: Configure
100 shell: cmake -P {0}
101 run: |
102 set(ENV{CC} ${{ matrix.config.cc }})
103 set(ENV{CXX} ${{ matrix.config.cxx }})
104 if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x")
105 execute_process(
106 COMMAND "${{ matrix.config.environment_script }}" && set
107 OUTPUT_FILE environment_script_output.txt
108 )
109 file(STRINGS environment_script_output.txt output_lines)
110 foreach(line IN LISTS output_lines)
111 if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$")
112 set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
113 endif()
114 endforeach()
115 endif()
116 set(path_separator ":")
117 if ("${{ runner.os }}" STREQUAL "Windows")
118 set(path_separator ";")
119 endif()
120 set(ENV{PATH} "$ENV{GITHUB_WORKSPACE}${path_separator}$ENV{PATH}")
121 execute_process(
122 COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake
123 -S .
124 -B build
125 -D CMAKE_BUILD_TYPE=$ENV{BUILD_TYPE}
126 -G Ninja
127 -D CMAKE_MAKE_PROGRAM=ninja
128 -D CMAKE_C_COMPILER_LAUNCHER=ccache
129 -D CMAKE_CXX_COMPILER_LAUNCHER=ccache
130 RESULT_VARIABLE result
131 )
132 if (NOT result EQUAL 0)
133 message(FATAL_ERROR "Bad exit status")
134 endif()
135 - name: Build
136 shell: cmake -P {0}
137 run: |
138 set(ENV{NINJA_STATUS} "[%f/%t %o/sec] ")
139 if ("${{ runner.os }}" STREQUAL "Windows" AND NOT "x${{ matrix.config.environment_script }}" STREQUAL "x")
140 file(STRINGS environment_script_output.txt output_lines)
141 foreach(line IN LISTS output_lines)
142 if (line MATCHES "^([a-zA-Z0-9_-]+)=(.*)$")
143 set(ENV{${CMAKE_MATCH_1}} "${CMAKE_MATCH_2}")
144 endif()
145 endforeach()
146 endif()
147 set(path_separator ":")
148 if ("${{ runner.os }}" STREQUAL "Windows")
149 set(path_separator ";")
150 endif()
151 set(ENV{PATH} "$ENV{GITHUB_WORKSPACE}${path_separator}$ENV{PATH}")
152 file(TO_CMAKE_PATH "$ENV{GITHUB_WORKSPACE}" ccache_basedir)
153 set(ENV{CCACHE_BASEDIR} "${ccache_basedir}")
154 set(ENV{CCACHE_DIR} "${ccache_basedir}/.ccache")
155 set(ENV{CCACHE_COMPRESS} "true")
156 set(ENV{CCACHE_COMPRESSLEVEL} "6")
157 set(ENV{CCACHE_MAXSIZE} "400M")
158 if ("${{ matrix.config.cxx }}" STREQUAL "cl")
159 set(ENV{CCACHE_MAXSIZE} "600M")
160 endif()
161 execute_process(COMMAND ccache -p)
162 execute_process(COMMAND ccache -z)
163 execute_process(
164 COMMAND ${{ steps.cmake_and_ninja.outputs.cmake_dir }}/cmake --build build
165 RESULT_VARIABLE result
166 )
167 if (NOT result EQUAL 0)
168 message(FATAL_ERROR "Bad exit status")
169 endif()
170 execute_process(COMMAND ccache -s)