├── .github └── workflows │ └── ci.yml ├── CMakeLists.txt ├── LICENSE ├── README.md ├── action.yml ├── action_helpers.sh ├── cmake └── json_utils.cmake └── tests ├── CMakeLists.txt ├── test_vulkan.c └── vulkan_sdk_specs └── linux.json /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: Setup 2 | on: 3 | push: 4 | pull_request: 5 | branches: [ main ] 6 | workflow_dispatch: 7 | inputs: 8 | extra_tests: 9 | description: 'Enable additional CI tests' 10 | required: false 11 | default: 'false' 12 | components: 13 | description: Vulkan SDK Components 14 | required: false 15 | default: 'Vulkan-Headers Vulkan-Loader SPIRV-Headers SPIRV-Cross SPIRV-Tools SPIRV-Reflect Glslang' 16 | # Vulkan-ValidationLayers robin-hood-hashing 17 | versions: 18 | description: Vulkan SDK Versions 19 | required: false 20 | default: '[ "latest" ]' 21 | oses: 22 | description: 'Matrix OSes' 23 | required: true 24 | default: '[ "ubuntu-latest", "windows-latest", "windows-2022", "macos-13", "macos-latest" ]' 25 | jobs: 26 | setup-all-matrix: 27 | if: ${{ github.event.inputs.extra_tests == 'true' || github.event.inputs.extra_tests == 'matrix' }} 28 | runs-on: ${{ matrix.runs-on }} 29 | strategy: 30 | matrix: 31 | runs-on: ${{ fromJSON(github.event.inputs.oses) }} 32 | version: ${{ fromJSON(github.event.inputs.versions) }} 33 | steps: 34 | - uses: actions/checkout@v4 35 | - uses: ./ 36 | with: 37 | vulkan-query-version: ${{ matrix.version }} 38 | vulkan-components: ${{ github.event.inputs.components }} 39 | vulkan-use-cache: true 40 | - name: Print runner configurations 41 | run: | 42 | echo runner os: ${{ runner.os }}, arch: ${{ runner.arch }} 43 | - uses: seanmiddleditch/gha-setup-vsdevenv@v5 44 | # - name: checkout seanmiddleditch/gha-setup-vsdevenv@v4 45 | # if: runner.os == 'Windows' 46 | # uses: actions/checkout@v4 47 | # with: 48 | # repository: seanmiddleditch/gha-setup-vsdevenv 49 | # ref: v4 50 | # path: gha-setup-vsdevenv 51 | # - name: execute seanmiddleditch/gha-setup-vsdevenv@v4 52 | # if: runner.os == 'Windows' 53 | # shell: cmd 54 | # working-directory: gha-setup-vsdevenv 55 | # run: | 56 | # npm install @actions/core 57 | # node dist/index.js | grep -v ::set-output 58 | - name: Test Vulkan SDK Install 59 | shell: bash 60 | run: | 61 | echo "Vulkan SDK Version=='$VULKAN_SDK_VERSION'" 62 | echo "VULKAN_SDK=='$VULKAN_SDK'" 63 | glslangValidator --version 64 | test -n "$VULKAN_SDK_VERSION" 65 | cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. 66 | cmake --build tests/build --config release 67 | ./tests/build/test_vulkan 68 | # 69 | # setup-ubuntu-with-fetched-config-json: 70 | # runs-on: ubuntu-latest 71 | # steps: 72 | # - uses: actions/checkout@v4 73 | # - name: Fetch config.json 74 | # run: | 75 | # curl -s -o vulkan_ubuntu_config.json https://vulkan.lunarg.com/sdk/config/1.2.182.0/linux/config.json 76 | # - uses: ./ 77 | # with: 78 | # vulkan-config-file: vulkan_ubuntu_config.json 79 | # vulkan-components: | 80 | # Vulkan-Headers Vulkan-Loader Vulkan-ValidationLayers 81 | # SPIRV-Cross SPIRV-Tools SPIRV-Reflect 82 | # Glslang 83 | # - name: Test Vulkan SDK Install 84 | # run: | 85 | # echo "Vulkan SDK Version=='$VULKAN_SDK_VERSION'" 86 | # echo "VULKAN_SDK=='$VULKAN_SDK'" 87 | # test -n "$VULKAN_SDK_VERSION" || exit 4 88 | # cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. 89 | # cmake --build tests/build --config release 90 | # PATH=$PATH:$VULKAN_SDK/bin ./tests/build/test_vulkan 91 | # glslangValidator --version 92 | # spirv-cfg --version 93 | # which spirv-cross 94 | # 95 | setup-ubuntu-with-local-config-json: 96 | if: ${{ contains(github.event.inputs.extra_tests, 'default') }} 97 | runs-on: ubuntu-latest 98 | steps: 99 | - uses: actions/checkout@v4 100 | - uses: ./ 101 | with: 102 | vulkan-config-file: tests/vulkan_sdk_specs/linux.json 103 | vulkan-components: Vulkan-Headers, Vulkan-Loader 104 | vulkan-use-cache: true+ 105 | - name: Test Vulkan SDK Install 106 | run: | 107 | echo "Vulkan SDK Version=='$VULKAN_SDK_VERSION'" 108 | echo "VULKAN_SDK=='$VULKAN_SDK'" 109 | test -n "$VULKAN_SDK_VERSION" || exit 4 110 | cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. 111 | cmake --build tests/build --config release -- -j2 112 | PATH=$PATH:$VULKAN_SDK/bin ./tests/build/test_vulkan 113 | # 114 | # setup-windows-prebuilt: 115 | # runs-on: windows-latest 116 | # steps: 117 | # - uses: actions/checkout@v4 118 | # - uses: ./ 119 | # with: 120 | # vulkan-components: prebuilt loader 121 | # vulkan-use-cache: true 122 | # - name: Test Vulkan SDK Install 123 | # shell: cmd 124 | # run: | 125 | # echo "Vulkan SDK Version=='%VULKAN_SDK_VERSION%'" 126 | # echo "VULKAN_SDK=='%VULKAN_SDK%'" 127 | # if "%VULKAN_SDK_VERSION%"=="" exit 1 128 | # cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. || exit /b 2 129 | # cmake --build tests/build --config release || exit /b 3 130 | # set PATH=%PATH%;%VULKAN_SDK%/bin 131 | # glslangValidator --version 132 | # dir /R VULKAN_SDK 133 | # dir /R tests 134 | # dir .\tests\build\test_vulkan.exe 135 | # echo testing... 136 | # .\tests\build\test_vulkan || true || exit /b 4 137 | # 138 | # setup-macos-using-prebuilt-cached: 139 | # runs-on: macos-12 140 | # steps: 141 | # - uses: actions/checkout@v4 142 | # - uses: ./ 143 | # with: 144 | # vulkan-version: 1.2.189.0 145 | # vulkan-components: prebuilt loader 146 | # vulkan-use-cache: true 147 | # # - name: Setup tmate session 148 | # # uses: mxschmitt/action-tmate@v3.9 149 | # # with: 150 | # # limit-access-to-actor: true 151 | # - name: Test Vulkan SDK Install 152 | # run: | 153 | # echo "Vulkan SDK Version=='$VULKAN_SDK_VERSION'" 154 | # echo "VULKAN_SDK=='$VULKAN_SDK'" 155 | # test -n "$VULKAN_SDK_VERSION" 156 | # cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. 157 | # cmake --build tests/build --config release 158 | # PATH=$PATH:$VULKAN_SDK/bin ./tests/build/test_vulkan 159 | # 160 | setup-windows-with-version-powershell: 161 | if: ${{ contains(github.event.inputs.extra_tests, 'default') }} 162 | runs-on: windows-latest 163 | steps: 164 | - uses: actions/checkout@v4 165 | - uses: ./ 166 | with: 167 | vulkan-query-version: 1.3.204.0 168 | vulkan-components: Vulkan-Headers, Vulkan-Loader 169 | vulkan-use-cache: true 170 | 171 | - uses: seanmiddleditch/gha-setup-vsdevenv@v4 172 | if: runner.os == 'Windows' 173 | - name: Test Vulkan SDK Install 174 | shell: powershell 175 | run: | 176 | echo "Vulkan SDK Version=='$env:VULKAN_SDK_VERSION'" 177 | if (!$env:VULKAN_SDK_VERSION) { throw "vulkan sdk install error" } 178 | cd tests 179 | cmake -G "Visual Studio 16 2019" -B build -S . -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. 180 | cmake --build build --config release 181 | $ENV:PATH="$ENV:PATH;$ENV:VULKAN_SDK/bin" 182 | tail -100 build/CMakeFiles/*.log 183 | ./build/test_vulkan 184 | # 185 | setup-macos-with-latest: 186 | if: ${{ contains(github.event.inputs.extra_tests, 'default') }} 187 | runs-on: macos-12 188 | steps: 189 | - uses: actions/checkout@v4 190 | - uses: ./ 191 | with: 192 | vulkan-query-version: 1.3.204.0 193 | vulkan-components: Vulkan-Headers, Vulkan-Loader, Glslang 194 | vulkan-use-cache: true+ 195 | - name: Test Vulkan SDK Install 196 | run: | 197 | echo "Vulkan SDK Version=='$VULKAN_SDK_VERSION'" 198 | echo "VULKAN_SDK=='$VULKAN_SDK'" 199 | test -n "$VULKAN_SDK_VERSION" 200 | cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. 201 | cmake --build tests/build --config release -- -j2 202 | glslangValidator --version 203 | PATH=$PATH:$VULKAN_SDK/bin ./tests/build/test_vulkan 204 | # 205 | # setup-ubuntu-without-version: 206 | # if: ${{ github.event.inputs.extra_tests == 'true' }} 207 | # runs-on: ubuntu-latest 208 | # container: 209 | # image: ubuntu:16.04 210 | # steps: 211 | # - uses: actions/checkout@v4 212 | # - name: Install Python3 213 | # run: | 214 | # apt-get -qq update 215 | # apt-get -qq install python3 216 | # - uses: ./ 217 | # with: 218 | # vulkan-components: headers, loader, validation 219 | # - name: Test Vulkan SDK Install 220 | # run: | 221 | # echo "Vulkan SDK Version=='$VULKAN_SDK_VERSION'" 222 | # echo "VULKAN_SDK=='$VULKAN_SDK'" 223 | # test -n "$VULKAN_SDK_VERSION" 224 | # cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. 225 | # cmake --build tests/build --config release 226 | # PATH=$PATH:$VULKAN_SDK/bin ./tests/build/test_vulkan 227 | # 228 | # setup-ubuntu-with-version: 229 | # if: ${{ github.event.inputs.extra_tests == 'true' }} 230 | # runs-on: ubuntu-latest 231 | # steps: 232 | # - uses: actions/checkout@v4 233 | # - uses: ./ 234 | # with: 235 | # vulkan-version: 1.2.162.0 236 | # vulkan-components: headers, loader, spirv-cross, spirv-tools 237 | # - name: Test Vulkan SDK Install 238 | # run: | 239 | # echo "Vulkan SDK Version=='$VULKAN_SDK_VERSION'" 240 | # echo "VULKAN_SDK=='$VULKAN_SDK'" 241 | # test -n "$VULKAN_SDK_VERSION" 242 | # cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. 243 | # cmake --build tests/build --config release 244 | # PATH=$PATH:$VULKAN_SDK/bin ./tests/build/test_vulkan 245 | # 246 | # setup-ubuntu-prebuilt: 247 | # if: ${{ github.event.inputs.extra_tests == 'true' }} 248 | # runs-on: ubuntu-latest 249 | # steps: 250 | # - uses: actions/checkout@v4 251 | # - uses: ./ 252 | # with: 253 | # vulkan-components: prebuilt 254 | # vulkan-use-cache: true 255 | # - name: Test Vulkan SDK Install 256 | # run: | 257 | # echo "Vulkan SDK Version=='$VULKAN_SDK_VERSION'" 258 | # echo "VULKAN_SDK=='$VULKAN_SDK'" 259 | # test -n "$VULKAN_SDK_VERSION" 260 | # cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. 261 | # cmake --build tests/build --config release 262 | # PATH=$PATH:$VULKAN_SDK/bin ./tests/build/test_vulkan 263 | # 264 | # setup-windows-without-version-cmd: 265 | # if: ${{ github.event.inputs.extra_tests == 'true' }} 266 | # runs-on: windows-latest 267 | # steps: 268 | # - uses: actions/checkout@v4 269 | # - uses: ./ 270 | # - name: Test Vulkan SDK Install 271 | # shell: cmd 272 | # run: | 273 | # echo "Vulkan SDK Version=='%VULKAN_SDK_VERSION%'" 274 | # echo "VULKAN_SDK=='%VULKAN_SDK%'" 275 | # if "%VULKAN_SDK_VERSION%"=="" exit 1 276 | # cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. || exit /b 1 277 | # cmake --build tests/build --config release || exit /b 1 278 | # set PATH=%PATH%;%VULKAN_SDK%/bin 279 | # .\tests\build\test_vulkan || exit /b 1 280 | # 281 | # setup-macos-with-version: 282 | # if: ${{ github.event.inputs.extra_tests == 'true' }} 283 | # runs-on: macos-12 284 | # steps: 285 | # - uses: actions/checkout@v4 286 | # - uses: ./ 287 | # with: 288 | # vulkan-version: 1.2.189.0 289 | # vulkan-components: headers loader 290 | # - name: Test Vulkan SDK Install 291 | # run: | 292 | # echo "Vulkan SDK Version=='$VULKAN_SDK_VERSION'" 293 | # echo "VULKAN_SDK=='$VULKAN_SDK'" 294 | # test -n "$VULKAN_SDK_VERSION" 295 | # cmake -B tests/build -S tests -DCMAKE_BUILD_TYPE=Release -DCMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE=. 296 | # cmake --build tests/build --config release 297 | # PATH=$PATH:$VULKAN_SDK/bin ./tests/build/test_vulkan 298 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Vulkan SDK config.json cmake wrapper 2 | # 2022.02.16 humbletim MIT license 3 | # see: https://github.com/humbletim/setup-vulkan-sdk 4 | 5 | # cmake variables: 6 | # -DVULKAN_SDK -- where to install SDK components 7 | # -DVULKAN_SDK_CONFIG -- config.json that specifies repos/branches 8 | # -DVULKAN_SDK_COMPONENTS -- which SDK components to install 9 | 10 | # note: a Vulkan SDK config.json can be downloaded using the template: 11 | # https://vulkan.lunarg.com/sdk/config/VERSION/PLATFORM/config.json 12 | # (see: https://vulkan.lunarg.com/content/view/latest-sdk-version-api) 13 | 14 | cmake_minimum_required(VERSION 3.19) 15 | # note: 3.19+ needed for JSON parsing 16 | 17 | include(ExternalProject) 18 | include(cmake/json_utils.cmake) 19 | 20 | project(VulkanSDKComponents) 21 | 22 | set(AVAILABLE_COMPONENTS "Vulkan-Headers Vulkan-Loader SPIRV-Headers SPIRV-Cross SPIRV-Tools SPIRV-Reflect Glslang") 23 | # TODO: Vulkan-ExtensionLayer Khronos-Tools LunarG-Tools DXC gfxreconstruct MoltenVK Vulkan-Docs Vulkan-ValidationLayers robin-hood-hashing shaderc 24 | 25 | macro(_assert varname) 26 | if (NOT ${varname}) 27 | message(FATAL_ERROR "assertion failed (${varname}):\n" ${ARGN}) 28 | endif() 29 | endmacro() 30 | 31 | _assert(VULKAN_SDK "define -DVULKAN_SDK= to desired VULKAN_SDK installation folder") 32 | _assert(VULKAN_SDK_CONFIG "define -DVULKAN_SDK_CONFIG= to Vulkan SDK config.json") 33 | _assert(VULKAN_SDK_COMPONENTS "define -DVULKAN_SDK_COMPONENTS=\"Vulkan-Headers;Vulkan-Loader;etc.\"\n" 34 | "available: ${AVAILABLE_COMPONENTS}") 35 | 36 | STRING(REGEX REPLACE "[, ]+" ";" VULKAN_SDK_COMPONENTS "${VULKAN_SDK_COMPONENTS}") 37 | 38 | if (DEFINED CMAKE_INSTALL_PREFIX) 39 | message(STATUS "CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX} -- replacing with VULKAN_SDK=${VULKAN_SDK}") 40 | set(CMAKE_INSTALL_PREFIX ${VULKAN_SDK}) 41 | endif() 42 | 43 | ############################################################################## 44 | # manual Vulkan SDK build overrides 45 | 46 | # manually list SPIRV-Headers as SPIRV-Tools dependency 47 | set_property(GLOBAL APPEND PROPERTY SPIRV-Tools_deps_extra "SPIRV-Headers\;SPIRV-Headers_SOURCE_DIR") 48 | 49 | # manually list robin-hood-hashing as Vulkan-ValidationLayers dependency 50 | set_property(GLOBAL APPEND PROPERTY Vulkan-ValidationLayers_deps_extra "robin-hood-hashing\;ROBIN_HOOD_HASHING_INSTALL_DIR") 51 | 52 | # robin-hood-hashing is odd in Vulkan SDK config.json's -- but only the header is actually needed 53 | set_property(GLOBAL APPEND PROPERTY robin-hood-hashing_install_command 54 | test -d ${VULKAN_SDK}/include/ || mkdir -v ${VULKAN_SDK}/include/ && 55 | cp -av ../robin-hood-hashing/src/include/robin_hood.h ${VULKAN_SDK}/include/ 56 | 57 | ) 58 | set_property(GLOBAL APPEND PROPERTY robin-hood-hashing_cmake_extra -DRH_STANDALONE_PROJECT:BOOL=OFF) 59 | 60 | # if SPIRV-Tools-opt is available as part of installed components enable Glslang to locate it 61 | if(VULKAN_SDK_COMPONENTS MATCHES "Glslang.*SPIRV-Tools|SPIRV-Tools.*Glslang") 62 | message("Glslang + SPIRV-Tools -- patching Glslang dependency on SPIRV-Tools-opt") 63 | set_property(GLOBAL APPEND PROPERTY Glslang_deps_extra "SPIRV-Tools\;spirv-tools_SOURCE_DIR") 64 | file(WRITE ${CMAKE_BINARY_DIR}/Glslang_SPIRV_patch.cmake [====[ 65 | add_library(SPIRV-Tools-opt INTERFACE) 66 | set_property(TARGET SPIRV-Tools-opt APPEND PROPERTY INTERFACE_LINK_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/lib ) 67 | set_property(TARGET SPIRV-Tools-opt APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES ${CMAKE_INSTALL_PREFIX}/include ) 68 | install(TARGETS SPIRV-Tools-opt EXPORT SPIRV-Tools-opt) 69 | install(EXPORT SPIRV-Tools-opt DESTINATION lib/cmake) 70 | set(spirv_tools NOTFOUND) 71 | set(spirv_tools_opt NOTFOUND) 72 | find_library(spirv_tools SPIRV-Tools PATHS ${CMAKE_INSTALL_PREFIX}/lib REQUIRED NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH) 73 | find_library(spirv_tools_opt SPIRV-Tools-opt PATHS ${CMAKE_INSTALL_PREFIX}/lib REQUIRED NO_DEFAULT_PATH NO_PACKAGE_ROOT_PATH NO_CMAKE_PATH NO_CMAKE_ENVIRONMENT_PATH NO_SYSTEM_ENVIRONMENT_PATH NO_CMAKE_SYSTEM_PATH NO_CMAKE_FIND_ROOT_PATH) 74 | set_property(TARGET SPIRV-Tools-opt APPEND PROPERTY INTERFACE_LINK_LIBRARIES ${spirv_tools_opt} ${spirv_tools}) 75 | ]====]) 76 | set_property(GLOBAL APPEND PROPERTY Glslang_patch_command bash -c "echo 'include(${CMAKE_BINARY_DIR}/Glslang_SPIRV_patch.cmake)' | tee External/CMakeLists.txt") 77 | set_property(GLOBAL APPEND PROPERTY Glslang_cmake_extra -DENABLE_OPT:BOOL=ON) 78 | else() 79 | # otherwise disable External completely 80 | set_property(GLOBAL APPEND PROPERTY Glslang_cmake_extra -DBUILD_EXTERNAL:BOOL=OFF) 81 | endif() 82 | 83 | function(setup_component_dependency key value parentName) 84 | setup_component(${key} ${parentName}) 85 | set_property(GLOBAL APPEND PROPERTY ${parentName}_cmake_extra -D${value}:FILEPATH=${VULKAN_SDK}) 86 | set_property(GLOBAL APPEND PROPERTY ${parentName}_deps ${key}) 87 | endfunction() 88 | 89 | function(setup_component name parentName) 90 | if (TARGET ${name}) 91 | # message(STATUS "skipping second ExternalProject_Add ${name}") 92 | return() 93 | endif() 94 | # message(">>>>>>>>>>>>>>>>>>>>>> ${name}_component_defined==${${name}_component_defined}") 95 | json_get_subprops("${configJson}" "repos" "${name}" PROPERTIES url dependencies) 96 | _assert(url "could not read URL for name=${name} url=${url}") 97 | json_coalesce_subprops("${configJson}" ref "repos" "${name}" PROPERTIES commit tag branch) 98 | 99 | # process config.json dependencies first 100 | json_foreach("${dependencies}" "" setup_component_dependency ${name}) 101 | # then any override deps_extra's 102 | get_component_props(${name} deps_extra) 103 | foreach(kv ${deps_extra}) 104 | setup_component_dependency(${kv} ${name}) 105 | endforeach() 106 | 107 | get_component_props(${name} deps cmake_extra patch_command install_command) 108 | # convert spaces to list (otherwise CMAKE_ARGS seems to force quotes if there are spaces in singular values) 109 | string(REPLACE " " ";" cmake_extra "${cmake_extra}") 110 | set(cmake_args 111 | -Wno-dev 112 | -DCMAKE_INSTALL_MESSAGE=NEVER 113 | -DCMAKE_BUILD_TYPE=Release 114 | -DCMAKE_INSTALL_PREFIX=${VULKAN_SDK} 115 | # -DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} 116 | # -DCMAKE_C_COMPILER=${CMAKE_C_COMPILER} 117 | # -DCMAKE_BUILD_WITH_INSTALL_RPATH:BOOL=ON 118 | ) 119 | list(APPEND cmake_args ${cmake_extra}) 120 | message(STATUS "ExternalProject_Add ${name} ${ref} deps=[${deps}] cmake_extra=[${cmake_extra}]") 121 | ExternalProject_Add("${name}" 122 | GIT_REPOSITORY "${url}" 123 | GIT_TAG "${ref}" 124 | GIT_PROGRESS OFF 125 | CMAKE_CACHE_ARGS ${cmake_extra} 126 | CMAKE_ARGS ${cmake_args} 127 | DEPENDS ${deps} 128 | PATCH_COMMAND ${patch_command} 129 | INSTALL_COMMAND ${install_command} 130 | ) 131 | set_property(GLOBAL APPEND PROPERTY VULKAN_COMPONENTS_PROCESSED ${name}) 132 | endfunction() 133 | 134 | ############################################################################## 135 | file(READ ${VULKAN_SDK_CONFIG} configJson) 136 | 137 | list(JOIN VULKAN_SDK_COMPONENTS " " REQUESTED_COMPONENTS) 138 | json_get_subprops("${configJson}" PROPERTIES version release release_date) 139 | message("---------------------------------------------------------------------") 140 | message("sdk components: ${REQUESTED_COMPONENTS}") 141 | message(" build path: ${CMAKE_BINARY_DIR}") 142 | message(" install path: ${VULKAN_SDK}") 143 | message(" configuration: ${VULKAN_SDK_CONFIG}") 144 | message(" .version: ${version}") 145 | message(" .release_date: ${release_date}") 146 | message("---------------------------------------------------------------------") 147 | 148 | string(REPLACE " " ";" AVAILABLE_COMPONENTS_LIST ${AVAILABLE_COMPONENTS}) 149 | foreach(name ${VULKAN_SDK_COMPONENTS}) 150 | list(FIND AVAILABLE_COMPONENTS_LIST ${name} index) 151 | if (${index} EQUAL -1) 152 | message(FATAL_ERROR "unknown component: ${name}\navailable: ${AVAILABLE_COMPONENTS}") 153 | endif() 154 | setup_component(${name} "${name}") 155 | endforeach() 156 | 157 | message("===================================================================") 158 | message("VULKAN_SDK_COMPONENTS: ${VULKAN_SDK_COMPONENTS}") 159 | get_property(VULKAN_COMPONENTS_PROCESSED GLOBAL PROPERTY VULKAN_COMPONENTS_PROCESSED) 160 | message(" PROCESSED: ${VULKAN_COMPONENTS_PROCESSED}") 161 | message("===================================================================") 162 | 163 | string(TIMESTAMP TIME_T UTC) 164 | file(WRITE 165 | ${CMAKE_BINARY_DIR}/sdk.env 166 | "VULKAN_SDK=${VULKAN_SDK} 167 | VULKAN_SDK_VERSION=${version} 168 | VULKAN_SDK_BUILD_DATE=${TIME_T} 169 | VULKAN_SDK_RELEASE=${release_date} 170 | VULKAN_SDK_CONFIG=${VULKAN_SDK_CONFIG} 171 | VULKAN_SDK_COMPONENTS=\"${VULKAN_SDK_COMPONENTS}\" 172 | ") 173 | 174 | install(FILES ${CMAKE_BINARY_DIR}/sdk.env DESTINATION .) 175 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 humbletim 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # setup-vulkan-sdk v1.2.1 2 | 3 | [![test setup-vulkan-sdk](https://github.com/humbletim/setup-vulkan-sdk/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/humbletim/setup-vulkan-sdk/actions/workflows/ci.yml) 4 | 5 | This action builds and integrates individual Vulkan SDK components directly from Khronos source repos. 6 | 7 | It is meant to offer a more lightweight option for CI/CD than installing the full Vulkan SDK, especially for projects that only need the Vulkan headers and loader available. Building those two SDK components from Khronos source usually takes around a minute and afterwards only uses around ~20MB of disk space (compared to the 600M-1.8GB that a full SDK install would require). 8 | 9 | ## Usage 10 | 11 | _note: if new to GitHub Actions please see GitHub Help Documentation [Quickstart](https://docs.github.com/en/actions/quickstart) or [Creating a workflow file](https://docs.github.com/en/actions/using-workflows#creating-a-workflow-file)._ 12 | 13 | ### Example integration 14 | 15 | ```yaml 16 | -name: Prepare Vulkan SDK 17 | uses: humbletim/setup-vulkan-sdk@v1.2.1 18 | with: 19 | vulkan-query-version: 1.4.304.1 20 | vulkan-components: Vulkan-Headers, Vulkan-Loader 21 | vulkan-use-cache: true 22 | ``` 23 | 24 | SDK version numbers are resolved into corresponding Khronos repos and commit points using the official LunarG [SDK web API](https://vulkan.lunarg.com/content/view/latest-sdk-version-api). 25 | 26 | Example SDK release number usable across all three primary platforms (linux/mac/windows): 27 | - 1.4.304.1 28 | - 1.3.296.0 29 | 30 | It is also possible to specify `latest` and the action will attempt to resolve automatically. 31 | 32 | NOTE: For production workflows it is recommended to create project-local copies of sdk config.json(s); see [Advanced](#Advanced-integration) example below. 33 | 34 | ## Including Vulkan SDK command line tools 35 | 36 | It is now possible to include Glslang and SPIRV-* command line tools as part of this action. 37 | 38 | However, depending on your project's needs, it might make more sense to use unattended installation of an official Vulkan SDK binary releases instead. An alternative action is provided for that [humbletim/install-vulkan-sdk](https://github.com/marketplace/actions/install-vulkan-sdk) (note that using full SDK binary releases consume a lot more runner disk space (600MB+)). 39 | 40 | ## Action Parameters 41 | 42 | - **`vulkan-query-version`**: valid SDK release number (eg: `1.3.296.0` or `latest`). *[required]* 43 | - **`vulkan-config-file`**: project-local config.json file path. *[optional; default: '']* 44 | - note: config.json files already contain versioning info, so when specified vulkan-query-version will be ignored 45 | - **`vulkan-use-cache`**: if `true` the VULKAN_SDK folder is cached and restored across builds. *[optional; default=false]* 46 | - **`vulkan-components`**: a space or comma delimited list of individual Vulkan component selections *[required]*: 47 | - `Vulkan-Headers` - [KhronosGroup/Vulkan-Headers](https://github.com/KhronosGroup/Vulkan-Headers) 48 | - `Vulkan-Loader` - [KhronosGroup/Vulkan-Loader](https://github.com/KhronosGroup/Vulkan-Loader) 49 | - `Glslang` - [KhronosGroup/Glslang](https://github.com/KhronosGroup/Glslang) 50 | - `SPIRV-Cross` - [KhronosGroup/SPIRV-Cross](https://github.com/KhronosGroup/SPIRV-Cross) 51 | - `SPIRV-Tools` - [KhronosGroup/SPIRV-Tools](https://github.com/KhronosGroup/SPIRV-Tools) 52 | - `SPIRV-Reflect` - [KhronosGroup/SPIRV-Reflect](https://github.com/KhronosGroup/SPIRV-Reflect) 53 | - `SPIRV-Headers` - [KhronosGroup/SPIRV-Headers](https://github.com/KhronosGroup/SPIRV-Headers) 54 | 55 | - Officially supported release numbers can be found here: https://vulkan.lunarg.com/sdk/home 56 | - Documentation on querying config.json SDK specs can be found here: https://vulkan.lunarg.com/content/view/latest-sdk-version-api 57 | 58 | ## Advanced integration 59 | 60 | ```yaml 61 | - name: Fetch Vulkan SDK version spec 62 | shell: bash 63 | run: | 64 | curl -o vulkan-sdk-config.json https://vulkan.lunarg.com/sdk/config/1.4.304.1/linux/config.json 65 | 66 | - name: Configure Vulkan SDK using the downloaded spec 67 | uses: humbletim/setup-vulkan-sdk@v1.2.1 68 | with: 69 | vulkan-config-file: vulkan-sdk-config.json 70 | vulkan-components: Vulkan-Headers, Vulkan-Loader 71 | vulkan-use-cache: true 72 | ``` 73 | 74 | To "lock in" the Khronos repos and commit points (and avoid any ongoing dependency on LunarG web services), commit a copy of the config.json(s) into your local project and then reference them similarly to above. 75 | 76 | Additional integration examples can be found as part of this project's CI test suite: [.github/workflows/ci.yml](.github/workflows/ci.yml). 77 | 78 | ## References 79 | - [Vulkan SDK](https://www.lunarg.com/vulkan-sdk/) 80 | - [Vulkan SDK web services API](https://vulkan.lunarg.com/content/view/latest-sdk-version-api) 81 | - [humbletim/install-vulkan-sdk](https://github.com/humbletim/install-vulkan-sdk) 82 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Setup Vulkan SDK' 2 | description: 'Automatically builds Vulkan SDK components from source.' 3 | branding: 4 | icon: 'play' 5 | color: 'red' 6 | inputs: 7 | vulkan-config-file: 8 | description: 'Vulkan SDK configuration path (prefer this to relying on vulkan-query-version lookup)' 9 | default: '' 10 | required: false 11 | vulkan-query-version: 12 | description: 'Vulkan SDK release version (download configuration file from LunarG web services)' 13 | default: '' 14 | required: false 15 | vulkan-components: 16 | description: 'specify which Vulkan SDK components to install, e.g. Vulkan-Headers, Vulkan-Loader, Glslang' 17 | default: Vulkan-Headers, Vulkan-Loader 18 | required: true 19 | vulkan-use-cache: 20 | description: 'specify whether to cache VULKAN_SDK/ results between runs (using github actions/cache)' 21 | default: false 22 | required: false 23 | runs: 24 | using: "composite" 25 | steps: 26 | - uses: humbletim/vsdevenv-shell@e87fcf2359929606ba32db358baef5ede4737aed 27 | 28 | - name: Resolve Vulkan SDK Configuration 29 | shell: bash 30 | run: | 31 | # resolve_vulkan_sdk_environment 32 | . $GITHUB_ACTION_PATH/action_helpers.sh 33 | resolve_vulkan_sdk_environment \ 34 | "${{ inputs.vulkan-query-version }}" \ 35 | "${{ inputs.vulkan-config-file }}" \ 36 | "${{ inputs.vulkan-components }}" \ 37 | || { echo "could not resolve SDK version / JSON configuration $?" ; exit 42 ; } 38 | 39 | - name: Configure Development Environment Prerequisites 40 | shell: bash 41 | run: | 42 | # dev prerequisites 43 | case `uname -s` in 44 | Darwin) ;; 45 | Linux) 46 | sudo apt-get -qq update 47 | sudo apt-get -qq install -y libwayland-dev libxrandr-dev 48 | ;; 49 | MINGW*) ;; 50 | esac 51 | 52 | - name: Generate cache key 53 | if: inputs.vulkan-use-cache != 'false' 54 | shell: bash 55 | run: | 56 | # cache-key.txt 57 | . $PWD/_vulkan_build/env 58 | ( 59 | echo VULKAN_SDK_CONFIG_FILE=$(sha256sum $VULKAN_SDK_CONFIG_FILE || openssl sha256 $VULKAN_SDK_CONFIG_FILE) 60 | echo VULKAN_SDK_CONFIG_VERSION=$VULKAN_SDK_CONFIG_VERSION 61 | echo VULKAN_SDK_COMPONENTS=\"$VULKAN_SDK_COMPONENTS\" 62 | echo vulkan-use-cache=${{ inputs.vulkan-use-cache }} 63 | ) | tee _vulkan_build/cache-key.txt >&2 64 | 65 | - name: Check Vulkan SDK Cache 66 | id: vulkan-cached-sdk 67 | if: inputs.vulkan-use-cache != 'false' 68 | uses: actions/cache@v4 69 | with: 70 | path: VULKAN_SDK 71 | key: ${{ runner.os }}-${{ runner.arch }}-vulkan-cached-sdk-${{ hashFiles('_vulkan_build/cache-key.txt') }} 72 | 73 | - name: Configure Vulkan SDK Build Prerequisites 74 | if: steps.vulkan-cached-sdk.outputs.cache-hit != 'true' 75 | shell: bash 76 | run: | 77 | # vulkan tools prereq 78 | . $GITHUB_ACTION_PATH/action_helpers.sh 79 | . $PWD/_vulkan_build/env 80 | configure_sdk_prereqs $PWD/_vulkan_build/tools 81 | echo PATH=$PWD/_vulkan_build/tools/bin:\$PATH >> $PWD/_vulkan_build/env 82 | echo "$VULKAN_SDK_BUILD_DIR/env:" 83 | echo "--------------------------------------------------------------" 84 | cat $VULKAN_SDK_BUILD_DIR/env 85 | echo "--------------------------------------------------------------" 86 | 87 | - name: Configure Vulkan SDK Components 88 | if: steps.vulkan-cached-sdk.outputs.cache-hit != 'true' 89 | shell: vsdevenv x64 bash {0} 90 | run: | 91 | # cmake configure 92 | set -a 93 | . $PWD/_vulkan_build/env 94 | if [[ $RUNNER_OS == 'Windows' ]] ; then 95 | CC=cl.exe 96 | CXX=cl.exe 97 | fi 98 | cmake -S $GITHUB_ACTION_PATH -B ${VULKAN_SDK_BUILD_DIR} \ 99 | -DCMAKE_BUILD_TYPE=Release \ 100 | -DVULKAN_SDK=${VULKAN_SDK} \ 101 | -DVULKAN_SDK_CONFIG="${VULKAN_SDK_CONFIG_FILE}" \ 102 | -DVULKAN_SDK_COMPONENTS="${VULKAN_SDK_COMPONENTS}" \ 103 | || { echo "cmake configure failed" >&2 ; cat _vulkan_build/CMakeFiles/*.log ; exit 4 ; } 104 | 105 | - name: Build Vulkan SDK Components 106 | if: steps.vulkan-cached-sdk.outputs.cache-hit != 'true' 107 | shell: vsdevenv x64 bash {0} 108 | run: | 109 | # cmake build 110 | set -a 111 | . $PWD/_vulkan_build/env 112 | cmake --build ${VULKAN_SDK_BUILD_DIR} --config Release 113 | 114 | - name: Install Vulkan SDK Components 115 | if: steps.vulkan-cached-sdk.outputs.cache-hit != 'true' 116 | shell: bash 117 | run: | 118 | # cmake install 119 | set -a 120 | . $PWD/_vulkan_build/env 121 | cmake --install ${VULKAN_SDK_BUILD_DIR} 122 | 123 | - name: Verify Vulkan SDK Installation 124 | shell: bash 125 | run: | 126 | # verify VULKAN_SDK 127 | . $PWD/_vulkan_build/env 128 | test -s ${VULKAN_SDK}/sdk.env 129 | . ${VULKAN_SDK}/sdk.env 130 | if [[ -d "${VULKAN_SDK}" && -n "${VULKAN_SDK_VERSION}" ]] ; then 131 | echo "Vulkan SDK v${VULKAN_SDK_VERSION} successfully installed into ${VULKAN_SDK}." 132 | else 133 | echo "Could not verify Vulkan SDK installation" 134 | exit 3 135 | fi 136 | 137 | - name: Export VULKAN_SDK and bin/ PATH to environment 138 | shell: bash 139 | run: | 140 | # export vulkan env vars 141 | . $PWD/_vulkan_build/env 142 | . ${VULKAN_SDK}/sdk.env 143 | ( 144 | echo VULKAN_SDK=${VULKAN_SDK} 145 | echo VULKAN_SDK_VERSION=${VULKAN_SDK_VERSION} 146 | ) | tee -a $GITHUB_ENV 147 | echo ${VULKAN_SDK}/bin | tee -a $GITHUB_PATH 148 | rm -rf $PWD/_vulkan_build 149 | du -hs ${VULKAN_SDK} 150 | -------------------------------------------------------------------------------- /action_helpers.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # prefixed error messages so gha annotations are included in the summary report 6 | function ERROR() { 7 | echo "::error::" "$@" >&2 8 | exit 1 9 | } 10 | 11 | function LOG() { 12 | # echo "::notice::" "$@" >&2 13 | echo "$@" >&2 14 | } 15 | 16 | function lunarg_get_latest_sdk_version() { 17 | local platform=$1 18 | local url=https://vulkan.lunarg.com/sdk/latest/$platform.txt 19 | LOG "[lunarg_get_latest_sdk_version] resolving latest via webservices lookup: $url" >&2 20 | curl -sL https://vulkan.lunarg.com/sdk/latest/$platform.txt 21 | } 22 | 23 | remote_url_used= 24 | function lunarg_fetch_sdk_config() { 25 | local platform=$1 query_version=$2 26 | remote_url_used=https://vulkan.lunarg.com/sdk/config/$query_version/$platform/config.json 27 | curl -sL $remote_url_used || ERROR "[lunarg_fetch_sdk_config] error retrieving $remote_url_used (curl exit code: $?)" 28 | } 29 | 30 | function resolve_vulkan_sdk_environment() { 31 | local query_version=$1 32 | local config_file=$2 33 | local sdk_components=$(echo "$3" | xargs echo | sed -e 's@[,; ]\+@;@g') 34 | local base_dir=$PWD 35 | local platform=unknown 36 | 37 | case `uname -s` in 38 | Darwin) platform=mac ;; 39 | Linux) platform=linux ;; 40 | MINGW*) 41 | platform=windows 42 | base_dir=$(pwd -W) 43 | ;; 44 | esac 45 | 46 | build_dir=$base_dir/_vulkan_build 47 | test -d $build_dir || mkdir -v $build_dir 48 | 49 | VULKAN_SDK=$base_dir/VULKAN_SDK 50 | test -d $VULKAN_SDK || mkdir -v $VULKAN_SDK 51 | 52 | if [[ -z "$config_file" && -z "$query_version" ]] ; then 53 | ERROR "[resolve_vulkan_sdk_environment] either config_file or query_version must be specified" 54 | fi 55 | if [[ -z "$config_file" ]] ; then 56 | test -n "$query_version" 57 | config_file=$build_dir/config.json 58 | lunarg_fetch_sdk_config $platform $query_version > $config_file 59 | fi 60 | 61 | [[ -s "$config_file" ]] || ERROR "zero byte config_file ($remote_url_used)" 62 | 63 | sdk_version=$(jq -re .version $config_file || echo "") 64 | LOG "[resolve_vulkan_sdk_environment] sdk query version '$query_version' resolved into SDK config JSON version '$sdk_version'" 65 | LOG "[resolve_vulkan_sdk_environment] sdk config repos: $(jq -r '[.repos|to_entries|.[].key]|sort|join(";")' $config_file)" 66 | 67 | if [[ -z "$sdk_version" || $sdk_version == "null" ]] ; then 68 | ERROR "[resolve_vulkan_sdk_environment] error resolving sdk version or retrieving config JSON from $remote_url_used ($(jq .message $config_file))" 69 | fi 70 | 71 | ( 72 | echo VULKAN_SDK_BUILD_DIR=$build_dir 73 | echo VULKAN_SDK=$VULKAN_SDK 74 | echo VULKAN_SDK_PLATFORM=$platform 75 | echo VULKAN_SDK_QUERY_URL=$remote_url_used 76 | echo VULKAN_SDK_QUERY_VERSION=$query_version 77 | echo VULKAN_SDK_CONFIG_FILE=$config_file 78 | echo VULKAN_SDK_CONFIG_VERSION=$sdk_version 79 | echo VULKAN_SDK_COMPONENTS=\"$sdk_components\" 80 | ) > $build_dir/env 81 | 82 | LOG "=== sdk build env ================================================" 83 | LOG $build_dir/env 84 | LOG "==================================================================" 85 | 86 | } 87 | 88 | function configure_sdk_prereqs() { 89 | local vulkan_build_tools=$1 90 | test -d $vulkan_build_tools/bin || mkdir -p $vulkan_build_tools/bin 91 | export PATH=$vulkan_build_tools/bin:$PATH 92 | case `uname -s` in 93 | Darwin) ;; 94 | Linux) 95 | test -f /etc/os-release && . /etc/os-release 96 | LOG "[configure_sdk_prereqs] VERSION_ID=$VERSION_ID" 97 | case $VERSION_ID in 98 | # legacy builds using 16.04 99 | 16.04) 100 | apt-get -qq -o=Dpkg::Use-Pty=0 update 101 | apt-get -qq -o=Dpkg::Use-Pty=0 install -y jq curl git make build-essential ninja-build 102 | curl -s -L https://github.com/Kitware/CMake/releases/download/v3.20.3/cmake-3.20.3-Linux-x86_64.tar.gz | tar --strip 1 -C $vulkan_build_tools -xzf - 103 | hash 104 | cmake --version 105 | ;; 106 | # everything else 107 | *) sudo apt-get -qq -o=Dpkg::Use-Pty=0 install -y ninja-build ;; 108 | esac 109 | ;; 110 | MINGW*) 111 | curl -L -o $vulkan_build_tools/ninja-win.zip https://github.com/ninja-build/ninja/releases/download/v1.10.2/ninja-win.zip 112 | unzip -d $vulkan_build_tools/bin $vulkan_build_tools/ninja-win.zip 113 | ;; 114 | esac 115 | } 116 | -------------------------------------------------------------------------------- /cmake/json_utils.cmake: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.19) 2 | # note: 3.19+ needed for JSON parsing 3 | 4 | # json_get_subprops("${_json}" [key,key...] PROPERTIES property [property...]) 5 | function(json_get_subprops _json) 6 | cmake_parse_arguments(_sub "" "" "PROPERTIES" ${ARGN}) 7 | foreach(arg IN LISTS _sub_PROPERTIES) 8 | string(JSON value ERROR_VARIABLE jsonerror GET "${_json}" ${_sub_UNPARSED_ARGUMENTS} "${arg}") 9 | set(${arg} ${value} PARENT_SCOPE) 10 | endforeach() 11 | endfunction() 12 | 13 | # example: coalesce(VAR first second third) -> first truthy value found 14 | function(coalesce _outvar) 15 | list(FILTER ARGN EXCLUDE REGEX "-NOTFOUND|^$|^null$|^undefined$") 16 | list(GET ARGN 0 _tmp) 17 | set(${_outvar} ${_tmp} PARENT_SCOPE) 18 | endfunction() 19 | 20 | # sets OUTVAR to first non-null value 21 | # example: json_coalesce_subprops("${_json}" "repos" "${name}" PROPERTIES branch tag commit) 22 | function(json_coalesce_subprops _json _OUTVAR) 23 | cmake_parse_arguments(_sub "" "" "PROPERTIES" ${ARGN}) 24 | foreach(_arg IN LISTS _sub_PROPERTIES) 25 | string(JSON _value ERROR_VARIABLE jsonerror GET "${_json}" ${_sub_UNPARSED_ARGUMENTS} "${_arg}") 26 | if (NOT ${_value} MATCHES "-NOTFOUND|^$|^null$|^undefined$") 27 | set(${_OUTVAR} ${_value} PARENT_SCOPE) 28 | return() 29 | endif() 30 | endforeach() 31 | set(${_OUTVAR} "" PARENT_SCOPE) 32 | endfunction() 33 | 34 | # examples: 35 | # # evaluate cmake code block for each key-value pair 36 | # json_foreach("${_json}" "key1;key2" "message(subproperty key={0} value={1})") 37 | # 38 | # function(callback key value userValue) 39 | # message("subproperty key=${key} value=${value} userValue=${userValue}") 40 | # endfunction() 41 | # # evaluate specific member key-value pairs 42 | # json_foreach("${_json}" "key1;key2" callback "myuservalue") 43 | # # enumerate top-level key-value pairs 44 | # json_foreach("${_json}" "" callback) 45 | function(json_foreach _json _objectName _functionOrEval _userValue) 46 | if (NOT _json) 47 | return() 48 | endif() 49 | string(JSON _n LENGTH "${_json}" ${_objectName}) 50 | MATH(EXPR _n "${_n}-1") 51 | foreach(_i RANGE 0 ${_n}) 52 | string(JSON _key MEMBER "${_json}" ${_objectName} ${_i}) 53 | string(JSON _value GET "${_json}" ${_objectName} ${_key}) 54 | if (_functionOrEval MATCHES "[(]") # evaluate as cmake code 55 | # message("evaluating as code: ${_functionOrEval}") 56 | set(_tmp ${_functionOrEval}) 57 | string(REPLACE "{0}" ${_key} _tmp ${_tmp}) 58 | string(REPLACE "{1}" ${_value} _tmp ${_tmp}) 59 | string(REPLACE "{2}" "${_userValue}" _tmp ${_tmp}) 60 | cmake_language(EVAL CODE ${_tmp}) 61 | else() # invoke as functionname 62 | # message("evaluating as function: ${_functionOrEval}(${_key} ${_value} ${_userValue})") 63 | cmake_language(CALL ${_functionOrEval} ${_key} ${_value} "${_userValue}") 64 | endif() 65 | endforeach() 66 | endfunction() 67 | 68 | # resolve global properties into corresponding ~local variables 69 | # eg: get_component_props(Vulkan-Headers cmake_extra patch_command) 70 | # message("cmake_extra=${cmake_extra} patch_command=${patch_command}") 71 | function(get_component_props _comp) 72 | foreach(_arg ${ARGN}) 73 | get_property(_value GLOBAL PROPERTY "${_comp}_${_arg}") 74 | set(${_arg} "${_value}" PARENT_SCOPE) 75 | endforeach() 76 | endfunction() 77 | 78 | -------------------------------------------------------------------------------- /tests/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.18) 2 | project(test_vulkan) 3 | 4 | message(STATUS "") 5 | message(STATUS "|| VULKAN_SDK '$ENV{VULKAN_SDK}' PREFLIGHT TEST ||") 6 | find_package(Vulkan) 7 | get_cmake_property(Vars VARIABLES) 8 | # debug -- dump all variables starting with "vulkan"" 9 | foreach (Var ${Vars}) 10 | string( TOLOWER "${Var}" var ) 11 | if (var MATCHES "^vulkan") 12 | message(STATUS "${Var}=${${Var}}") 13 | endif() 14 | endforeach() 15 | 16 | message(STATUS "") 17 | message(STATUS "|| VULKAN_SDK TEST APPLICATION ||") 18 | find_package(Vulkan REQUIRED) 19 | add_executable(test_vulkan test_vulkan.c) 20 | target_link_libraries(test_vulkan PRIVATE Vulkan::Vulkan) 21 | 22 | ## alternative approach 23 | #target_include_directories(test_vulkan PRIVATE ${Vulkan_INCLUDE_DIR}) 24 | #target_link_libraries(test_vulkan PRIVATE ${Vulkan_LIBRARY}) 25 | -------------------------------------------------------------------------------- /tests/test_vulkan.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char** argv) { 6 | fprintf(stderr, "[test_vulkan.c] main....\n");fflush(stderr); 7 | uint32_t version = 0; 8 | PFN_vkEnumerateInstanceVersion vkEnumerateInstanceVersion = (PFN_vkEnumerateInstanceVersion)vkGetInstanceProcAddr(NULL, "vkEnumerateInstanceVersion"); 9 | if(vkEnumerateInstanceVersion) { 10 | vkEnumerateInstanceVersion(&version); 11 | } else { 12 | fprintf(stderr, "[test_vulkan.c] vkGetInstanceProcAddr (%p) lookup of vkEnumerateInstanceVersion failed...\n", vkEnumerateInstanceVersion); 13 | return 1; 14 | } 15 | 16 | printf("[test_vulkan.c] Vulkan Version: (%u) %d.%d.%d\n", version, 17 | VK_VERSION_MAJOR(version), 18 | VK_VERSION_MINOR(version), 19 | VK_VERSION_PATCH(version) 20 | ); 21 | return 0; 22 | } -------------------------------------------------------------------------------- /tests/vulkan_sdk_specs/linux.json: -------------------------------------------------------------------------------- 1 | { 2 | "version": "1.2.198.1", 3 | "release_date": "2021-12-03", 4 | "release": true, 5 | "publisher": "LunarG, Inc.", 6 | "copyright": "Copyright (c) 2015-2021 LunarG, Inc.", 7 | "comments" : "Building using the branch will build the most recent SDK on that branch. If you want to build a previous SDK on that branch, use the tag", 8 | "repos": { 9 | "Vulkan-Headers": { 10 | "url": "https://github.com/KhronosGroup/Vulkan-Headers.git", 11 | "branch": "sdk-1.2.198", 12 | "tag": "sdk-1.2.198.0", 13 | "configs": [ "Release" ] 14 | }, 15 | "Vulkan-Loader": { 16 | "url": "https://github.com/KhronosGroup/Vulkan-Loader.git", 17 | "branch": "sdk-1.2.198", 18 | "tag": "sdk-1.2.198.1", 19 | "defines": [ 20 | "BUILD_DLL_VERSIONINFO={version_string}" 21 | ], 22 | "configs": [ "RelWithDebInfo" ], 23 | "dependencies": { 24 | "Vulkan-Headers": "VULKAN_HEADERS_INSTALL_DIR" 25 | } 26 | }, 27 | "Vulkan-ValidationLayers": { 28 | "url": "https://github.com/KhronosGroup/Vulkan-ValidationLayers.git", 29 | "branch": "sdk-1.2.198", 30 | "tag": "sdk-1.2.198.0", 31 | "defines": [ 32 | "BUILD_LAYER_SUPPORT_FILES=ON", 33 | "ANNOTATED_SPEC_LINK=\"\\\"https://vulkan.lunarg.com/doc/view/_MAGIC_VERSION_ID_.0/windows/_MAGIC_ANNOTATED_SPEC_TYPE_/vkspec.html\\\"\"", 34 | "ROBIN_HOOD_HASHING_INSTALL_DIR={root_path}\\robin-hood-hashing\\repo" 35 | ], 36 | "configs": [ "Release" ], 37 | "dependencies": { 38 | "SPIRV-Headers": "SPIRV_HEADERS_INSTALL_DIR", 39 | "Vulkan-Headers": "VULKAN_HEADERS_INSTALL_DIR", 40 | "SPIRV-Tools": "SPIRV_TOOLS_INSTALL_DIR" 41 | }, 42 | "vk_layer_settings_files": [ "layers/vk_layer_settings.txt" ] 43 | }, 44 | "Vulkan-ExtensionLayer": { 45 | "url": "https://github.com/KhronosGroup/Vulkan-ExtensionLayer.git", 46 | "branch": "sdk-1.2.198", 47 | "tag": "sdk-1.2.198.0", 48 | "configs": [ "RelWithDebInfo" ], 49 | "dependencies": { 50 | "Vulkan-Headers": "VULKAN_HEADERS_INSTALL_DIR" 51 | }, 52 | "vk_layer_settings_files": [ "layers/vk_layer_settings.txt" ] 53 | }, 54 | "Khronos-Tools": { 55 | "url": "https://github.com/KhronosGroup/Vulkan-Tools.git", 56 | "branch": "sdk-1.2.198", 57 | "tag": "sdk-1.2.198.0", 58 | "defines": [ 59 | "VULKANINFO_BUILD_DLL_VERSIONINFO={version_string}" 60 | ], 61 | "configs": [ "RelWithDebInfo" ], 62 | "dependencies": { 63 | "Vulkan-Headers": "VULKAN_HEADERS_INSTALL_DIR", 64 | "Vulkan-Loader": "VULKAN_LOADER_INSTALL_DIR" 65 | } 66 | }, 67 | "Glslang": { 68 | "url": "https://github.com/KhronosGroup/Glslang.git", 69 | "branch": "sdk-1.2.198", 70 | "tag": "sdk-1.2.198.0", 71 | "script": [ "py -2 update_glslang_sources.py" ], 72 | "configs": [ "RelWithDebInfo", "Debug" ] 73 | }, 74 | "LunarG-Tools": { 75 | "url": "https://github.com/LunarG/VulkanTools.git", 76 | "branch": "sdk-1.2.198", 77 | "tag": "sdk-1.2.198.0", 78 | "script": [ "update_external_sources.bat --all" ], 79 | "configs": [ "RelWithDebInfo" ], 80 | "dependencies": { 81 | "Vulkan-Headers": "VULKAN_HEADERS_INSTALL_DIR", 82 | "Vulkan-Loader": "VULKAN_LOADER_INSTALL_DIR", 83 | "Vulkan-ValidationLayers": "VULKAN_VALIDATIONLAYERS_INSTALL_DIR" 84 | }, 85 | "vk_layer_settings_files": [ "layersvt/vk_layer_settings.txt" ] 86 | }, 87 | "SPIRV-Cross": { 88 | "url": "https://github.com/KhronosGroup/SPIRV-Cross.git", 89 | "commit": "401296d3b8fc60193e99ccabb81eb3e4fe2dd802", 90 | "defines": [ "SPIRV_CROSS_SHARED=ON" ], 91 | "configs": [ "Release", "Debug" ] 92 | }, 93 | "SPIRV-Tools": { 94 | "url": "https://github.com/KhronosGroup/SPIRV-Tools.git", 95 | "branch": "sdk-1.2.198", 96 | "tag": "sdk-1.2.198.0", 97 | "configs": [ "Release", "Debug" ], 98 | "dependencies": { 99 | "SPIRV-Headers": "SPIRV_HEADERS_INSTALL_DIR" 100 | }, 101 | "defines": [ 102 | "SPIRV-Headers_SOURCE_DIR={root_path_forward}/SPIRV-Headers/repo" 103 | ] 104 | }, 105 | "shaderc": { 106 | "url": "https://github.com/google/shaderc.git", 107 | "commit": "23539a3a9d50bab5b6d2467f4b5d2ce1b47eb8f2", 108 | "script": [ "py -2 update_shaderc_sources.py" ], 109 | "defines": [ 110 | "CMAKE_DEBUG_POSTFIX=d", 111 | "SHADERC_SKIP_TESTS=ON", 112 | "SHADERC_ENABLE_SHARED_CRT=ON", 113 | "SHADERC_SKIP_COPYRIGHT_CHECK=ON" 114 | ], 115 | "subdir": "src", 116 | "configs": [ "Release", "Debug" ] 117 | }, 118 | "DXC": { 119 | "url": "https://github.com/microsoft/DirectXShaderCompiler.git", 120 | "commit": "9adf10c8e1df38628a19d2bcff337b5d5296dffc", 121 | "platforms": ["Linux", "Darwin"] 122 | }, 123 | "gfxreconstruct": { 124 | "url": "https://github.com/LunarG/gfxreconstruct.git", 125 | "branch": "sdk-1.2.198", 126 | "tag": "sdk-1.2.198.0", 127 | "configs": [ "RelWithDebInfo" ], 128 | "vk_layer_settings_files": [ "layer/vk_layer_settings.txt" ] 129 | }, 130 | "SPIRV-Headers": { 131 | "url": "https://github.com/KhronosGroup/SPIRV-Headers.git", 132 | "branch": "sdk-1.2.198", 133 | "tag": "sdk-1.2.198.0", 134 | "configs": [ "RelWithDebInfo" ] 135 | }, 136 | "SPIRV-Reflect": { 137 | "url": "https://github.com/KhronosGroup/SPIRV-Reflect.git", 138 | "commit": "cc937caab141d889c9c9dff572c5a6854d5cf9b4", 139 | "configs": [ "RelWithDebInfo" ] 140 | }, 141 | "MoltenVK": { 142 | "url": "https://github.com/KhronosGroup/MoltenVK.git", 143 | "tag": "v1.1.6", 144 | "platforms": ["Darwin"] 145 | }, 146 | "Vulkan-Docs": { 147 | "url": "https://github.com/KhronosGroup/Vulkan-Docs.git", 148 | "tag": "v1.2.189" 149 | }, 150 | "robin-hood-hashing": { 151 | "url": "https://github.com/martinus/robin-hood-hashing.git", 152 | "commit": "3.11.3" 153 | } 154 | } 155 | } 156 | --------------------------------------------------------------------------------