1# Copyright (c) 2021-2023 Valve Corporation
2# Copyright (c) 2021-2023 LunarG, Inc.
3
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8#     http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16# Author: Lenny Komow <lenny@lunarg.com>
17# Author: Charles Giessen <charles@lunarg.com>
18
19name: CI Build
20
21# https://docs.github.com/en/actions/using-jobs/using-concurrency
22concurrency:
23  # github.head_ref is only defined on pull_request
24  # Fallback to the run ID, which is guaranteed to be both unique and defined for the run.
25  group: ${{ github.workflow }}-${{ github.head_ref || github.run_id  }}
26  cancel-in-progress: true
27
28on:
29  push:
30  pull_request:
31    branches:
32    - main
33
34permissions: read-all
35
36jobs:
37    linux:
38        runs-on: ${{matrix.os}}
39        strategy:
40            matrix:
41                compiler: [ {cc: gcc, cxx: g++}, {cc: clang, cxx: clang++} ]
42                config: [ Debug, Release ]
43                os: [ ubuntu-20.04, ubuntu-22.04 ]
44        steps:
45            - uses: actions/checkout@v4
46            - uses: actions/setup-python@v5
47              with:
48                python-version: '3.7'
49            - name: Test CMake min
50              # NOTE: The main users who benefit from an older CMake version
51              # are linux users stuck on older LTS releases. It's idiomatic best
52              # practice to try and support them so they don't have to install
53              # the CMake tarball. Ideally the minimum we use matches what the default
54              # package provided by Ubuntu via APT.
55              if: ${{ matrix.os == 'ubuntu-20.04' }}
56              uses: lukka/get-cmake@latest
57              with:
58                cmakeVersion: 3.17.2
59            - run: sudo apt update
60            - run: sudo apt install --yes --no-install-recommends libwayland-dev libxrandr-dev
61            - run: |
62                cmake -S. -B build \
63                -D CMAKE_BUILD_TYPE=${{ matrix.config }} \
64                -D BUILD_TESTS=ON \
65                -D UPDATE_DEPS=ON \
66                -D LOADER_ENABLE_ADDRESS_SANITIZER=ON \
67                -D BUILD_WERROR=ON \
68                -D CMAKE_CXX_COMPILER=${{ matrix.compiler.cxx }} \
69                -D CMAKE_C_COMPILER=${{ matrix.compiler.cc }}
70            - run: cmake --build build
71            - run: ctest --output-on-failure --test-dir build/
72            - run: cmake --install build --prefix /tmp
73
74    codegen:
75      runs-on: ubuntu-latest
76      steps:
77        - uses: actions/checkout@v4
78        - run: scripts/update_deps.py --dir ext --no-build
79        - run: scripts/generate_source.py --verify ext/Vulkan-Headers/registry/
80
81    linux-no-asm:
82        runs-on: ubuntu-22.04
83        steps:
84            - uses: actions/checkout@v4
85            - run: sudo apt update
86            - run: sudo apt install --yes --no-install-recommends libwayland-dev libxrandr-dev
87            - run: |
88                cmake -S. -B build \
89                -D CMAKE_BUILD_TYPE=Release \
90                -D BUILD_TESTS=ON \
91                -D UPDATE_DEPS=ON \
92                -D BUILD_WERROR=ON \
93                -D USE_GAS=OFF \
94                -D CMAKE_C_COMPILER=clang \
95                -D CMAKE_CXX_COMPILER=clang++
96            - run: cmake --build build
97            - run: cmake --install build --prefix /tmp
98            - run: ctest --output-on-failure -E UnknownFunction --test-dir build/
99
100    linux-32:
101        runs-on: ubuntu-22.04
102        strategy:
103            matrix:
104                config: [ Debug, Release ]
105        steps:
106            - uses: actions/checkout@v4
107            - uses: actions/setup-python@v5
108              with:
109                python-version: '3.7'
110            - uses: lukka/get-cmake@latest
111              with:
112                cmakeVersion: 3.17.2
113            - name: Enable 32 bit
114              run: sudo dpkg --add-architecture i386
115            - run: sudo apt-get update
116            - run: |
117                sudo apt install --yes --no-install-recommends \
118                gcc-multilib g++-multilib libc6:i386 libc6-dev-i386 libgcc-s1:i386 \
119                libwayland-dev:i386 libxrandr-dev:i386
120            - run: |
121                cmake -S. -B build \
122                -D CMAKE_BUILD_TYPE=${{matrix.config}} \
123                -D BUILD_TESTS=ON \
124                -D UPDATE_DEPS=ON \
125                -D BUILD_WERROR=ON \
126                -D SYSCONFDIR=/etc/not_vulkan \
127                -G Ninja
128              env:
129                CFLAGS: -m32
130                CXXFLAGS: -m32
131                LDFLAGS: -m32
132                ASFLAGS: --32
133            - run: cmake --build build
134            - run: cmake --install build --prefix /tmp
135            - run: ctest --output-on-failure
136              working-directory: build/
137
138    linux-32-no-asm:
139        runs-on: ubuntu-22.04
140        steps:
141            - uses: actions/checkout@v4
142            - uses: actions/setup-python@v5
143              with:
144                python-version: '3.7'
145            - uses: lukka/get-cmake@latest
146              with:
147                cmakeVersion: 3.17.2
148            - name: Enable 32 bit
149              run: sudo dpkg --add-architecture i386
150            - run: sudo apt-get update
151            - run: |
152                sudo apt install --yes --no-install-recommends \
153                gcc-multilib g++-multilib libc6:i386 libc6-dev-i386 libgcc-s1:i386 \
154                libwayland-dev:i386 libxrandr-dev:i386
155            - run: |
156                cmake -S. -B build \
157                -D CMAKE_BUILD_TYPE=Release \
158                -D BUILD_TESTS=ON \
159                -D UPDATE_DEPS=ON \
160                -D BUILD_WERROR=ON \
161                -D USE_GAS=OFF \
162                -G Ninja
163              env:
164                CFLAGS: -m32
165                CXXFLAGS: -m32
166                LDFLAGS: -m32
167                ASFLAGS: --32
168            - run: cmake --build build
169            - run: ctest --output-on-failure -E UnknownFunction
170              working-directory: build/
171
172    windows_vs:
173        runs-on: windows-latest
174        strategy:
175            matrix:
176                arch: [ Win32, x64 ]
177                config: [ Debug, Release ]
178        steps:
179            - uses: actions/checkout@v4
180            - run: |
181                cmake -S. -B build `
182                -D BUILD_TESTS=ON `
183                -D UPDATE_DEPS=ON `
184                -D CMAKE_BUILD_TYPE=${{matrix.config}} `
185                -A ${{ matrix.arch }} `
186                -D BUILD_WERROR=ON
187            - run: cmake --build build/ --config ${{matrix.config}}
188            - run: cmake --install build --prefix build/install --config ${{matrix.config}}
189            - run: ctest --output-on-failure -C ${{matrix.config}} --test-dir build/
190
191    windows_vs-no-asm:
192        runs-on: windows-latest
193        strategy:
194            matrix:
195                arch: [ Win32, x64 ]
196        steps:
197            - uses: actions/checkout@v4
198            - run: |
199                cmake -S. -B build `
200                -D BUILD_TESTS=ON `
201                -D UPDATE_DEPS=ON `
202                -D USE_MASM=OFF `
203                -D CMAKE_BUILD_TYPE=Release `
204                -A ${{ matrix.arch }} `
205                -D BUILD_WERROR=ON
206            - run: cmake --build build/ --config Release
207            - run: ctest --output-on-failure -C Release -E UnknownFunction --test-dir build/
208
209    # Test both clang and clang-cl (Chromium project uses clang-cl)
210    windows_clang:
211      runs-on: windows-2022
212      strategy:
213        matrix:
214            compiler: [ clang, clang-cl ]
215            config: [ Debug, Release ]
216      steps:
217          - uses: actions/checkout@v4
218          - uses: ilammy/msvc-dev-cmd@v1
219          - run: |
220              cmake -S. -B build `
221              -D CMAKE_C_COMPILER=${{matrix.compiler}} `
222              -D CMAKE_CXX_COMPILER=${{matrix.compiler}} `
223              -D UPDATE_DEPS=ON `
224              -D CMAKE_BUILD_TYPE=${{matrix.config}} `
225              -D BUILD_WERROR=ON `
226              -D BUILD_TESTS=ON `
227              -G Ninja
228          - run: cmake --build build/
229          - run: ctest --output-on-failure --test-dir build/
230          - run: cmake --install build --prefix build/install
231
232    mac:
233        runs-on: macos-11
234        strategy:
235            matrix:
236                config: [ Debug, Release ]
237                static_build: [ APPLE_STATIC_LOADER=ON, APPLE_STATIC_LOADER=OFF ]
238        steps:
239            - uses: actions/checkout@v4
240            - uses: actions/setup-python@v5
241              with:
242                python-version: '3.7'
243            - uses: lukka/get-cmake@latest
244            - run: |
245                cmake -S. -B build \
246                -D CMAKE_BUILD_TYPE=${{matrix.config}} \
247                -D ${{matrix.static_build}} \
248                -D BUILD_TESTS=ON \
249                -D UPDATE_DEPS=ON \
250                -D BUILD_WERROR=ON \
251                -D LOADER_ENABLE_ADDRESS_SANITIZER=ON \
252                -G Ninja
253              env:
254                # Prevents regression of KhronosGroup/Vulkan-Loader/issues/1332
255                LDFLAGS: -Wl,-fatal_warnings
256            - run: cmake --build build
257            - run: cmake --install build --prefix /tmp
258            - run: ctest --output-on-failure --test-dir build/
259
260    apple-cross-compile:
261      name: ${{ matrix.CMAKE_SYSTEM_NAME }}
262      runs-on: macos-12
263      strategy:
264          matrix:
265            CMAKE_SYSTEM_NAME: [ iOS, tvOS ]
266      steps:
267          - uses: actions/checkout@v4
268          - uses: actions/setup-python@v5
269            with:
270              python-version: '3.7'
271          - uses: lukka/get-cmake@latest
272          - run: |
273              cmake -S . -B build \
274              -D CMAKE_SYSTEM_NAME=${{ matrix.CMAKE_SYSTEM_NAME }} \
275              "-D CMAKE_OSX_ARCHITECTURES=arm64;x86_64" \
276              -D CMAKE_BUILD_TYPE=Debug \
277              -D UPDATE_DEPS=ON \
278              -D BUILD_WERROR=ON \
279              -G Ninja
280            env:
281              LDFLAGS: -Wl,-fatal_warnings
282          - run: cmake --build build
283          - run: cmake --install build --prefix /tmp
284          - name: Verify Universal Binary
285            run: |
286              vtool -show-build /tmp/lib/libvulkan.dylib | grep 'architecture x86_64'
287              vtool -show-build /tmp/lib/libvulkan.dylib | grep 'architecture arm64'
288
289    # Building a universal binary disables assembly automatically
290    # Furthermore the Vulkan SDK ships universal binaries
291    mac-univeral:
292        name: "Universal Binary Testing (STATIC ${{ matrix.static }}) w/ ${{ matrix.generator }}"
293        runs-on: macos-latest
294        strategy:
295            matrix:
296                static: [ 'ON', 'OFF' ]
297                generator: [ Ninja, Xcode ]
298        steps:
299            - uses: actions/checkout@v4
300            - uses: actions/setup-python@v5
301              with:
302                python-version: '3.7'
303            - uses: lukka/get-cmake@latest
304            - run: |
305                cmake -S. -B build \
306                -D CMAKE_BUILD_TYPE=Release \
307                -D APPLE_STATIC_LOADER=${{matrix.static}} \
308                "-D CMAKE_OSX_ARCHITECTURES=arm64;x86_64" \
309                -D BUILD_TESTS=ON \
310                -D UPDATE_DEPS=ON \
311                -D BUILD_WERROR=ON \
312                -G ${{ matrix.generator }}
313              env:
314                LDFLAGS: -Wl,-fatal_warnings
315            - run: cmake --build build --config Release
316            - run: ctest --output-on-failure --build-config Release -E UnknownFunction --test-dir build/
317            - run: cmake --install build --config Release --prefix /tmp
318            - name: Verify Universal Binary
319              if: ${{ matrix.static == 'OFF' }}
320              run: |
321                vtool -show-build /tmp/lib/libvulkan.dylib | grep 'architecture x86_64'
322                vtool -show-build /tmp/lib/libvulkan.dylib | grep 'architecture arm64'
323
324    chromium:
325      runs-on: ubuntu-latest
326      steps:
327        - uses: actions/checkout@v4
328        - run: scripts/gn/gn.py
329
330    mingw:
331      runs-on: windows-2022
332      defaults:
333        run:
334          shell: bash
335      steps:
336        - uses: actions/checkout@v4
337        - uses: actions/setup-python@v5
338          with:
339            python-version: '3.8'
340        - uses: lukka/get-cmake@latest
341        - name: Setup uasm
342          run: |
343            C:/msys64/usr/bin/pacman -Sy --noconfirm --needed mingw-w64-x86_64-uasm
344            printf '%s\n' 'C:/msys64/mingw64/bin' >> $GITHUB_PATH
345        - name: UASM Check
346          run: uasm -?
347        - run: |
348            cmake -S. -B build \
349            -D UPDATE_DEPS=ON \
350            -D CMAKE_BUILD_TYPE=Release \
351            -D BUILD_WERROR=ON \
352            -G Ninja
353        - run: cmake --build build
354        - run: cmake --install build --prefix /tmp
355
356    mingw-no-asm:
357      runs-on: windows-2022
358      defaults:
359        run:
360          shell: bash
361      steps:
362        - uses: actions/checkout@v4
363        - uses: actions/setup-python@v5
364          with:
365            python-version: '3.8'
366        - uses: lukka/get-cmake@latest
367        # Make sure this doesn't fail even without explicitly setting '-D USE_MASM=OFF' and without uasm
368        - run: |
369            cmake -S. -B build \
370            -D UPDATE_DEPS=ON \
371            -D CMAKE_BUILD_TYPE=Release \
372            -D BUILD_WERROR=ON \
373            -G Ninja
374        - run: cmake --build build
375        - run: cmake --install build --prefix /tmp
376
377    mingw-no-asm-explicit:
378      runs-on: windows-2022
379      defaults:
380        run:
381          shell: bash
382      steps:
383        - uses: actions/checkout@v4
384        - uses: lukka/get-cmake@latest
385        - run: |
386            cmake -S. -B build \
387            -D UPDATE_DEPS=ON \
388            -D CMAKE_BUILD_TYPE=Release \
389            -D BUILD_WERROR=ON \
390            -D USE_MASM=OFF \
391            -G Ninja
392        - run: cmake --build build
393        - run: cmake --install build --prefix /tmp
394