|
| 1 | +name: CMake CI |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [ main ] |
| 6 | + pull_request: |
| 7 | + branches: [ main ] |
| 8 | + |
| 9 | +jobs: |
| 10 | + build: |
| 11 | + strategy: |
| 12 | + fail-fast: false |
| 13 | + matrix: |
| 14 | + os: [ubuntu-latest, windows-latest] |
| 15 | + include: |
| 16 | + - os: ubuntu-latest |
| 17 | + vulkan-install: | |
| 18 | + # Download and install Vulkan SDK using the tar.gz method |
| 19 | + VULKAN_VERSION=$(curl -s https://vulkan.lunarg.com/sdk/latest/linux.txt) |
| 20 | + echo "Using Vulkan SDK version: $VULKAN_VERSION" |
| 21 | +
|
| 22 | + # Create a temporary directory for the SDK |
| 23 | + mkdir -p vulkan-sdk |
| 24 | + cd vulkan-sdk |
| 25 | +
|
| 26 | + # Download the SDK |
| 27 | + curl -O "https://sdk.lunarg.com/sdk/download/$VULKAN_VERSION/linux/vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.xz" |
| 28 | +
|
| 29 | + # Extract the SDK - use tar with J flag for xz compression |
| 30 | + tar -xJf vulkansdk-linux-x86_64-$VULKAN_VERSION.tar.xz |
| 31 | +
|
| 32 | + # Set up environment variables |
| 33 | + echo "VULKAN_SDK=$PWD/$VULKAN_VERSION/x86_64" >> $GITHUB_ENV |
| 34 | + echo "PATH=$PWD/$VULKAN_VERSION/x86_64/bin:$PATH" >> $GITHUB_ENV |
| 35 | + echo "LD_LIBRARY_PATH=$PWD/$VULKAN_VERSION/x86_64/lib:$LD_LIBRARY_PATH" >> $GITHUB_ENV |
| 36 | + echo "VK_LAYER_PATH=$PWD/$VULKAN_VERSION/x86_64/etc/vulkan/explicit_layer.d" >> $GITHUB_ENV |
| 37 | +
|
| 38 | + # Return to the original directory |
| 39 | + cd .. |
| 40 | + deps-install: | |
| 41 | + # GitHub runners already have cmake, ninja-build, and clang installed |
| 42 | + sudo apt-get update |
| 43 | + sudo apt-get install -y \ |
| 44 | + libglfw3-dev \ |
| 45 | + libglm-dev \ |
| 46 | + libtinyobjloader-dev \ |
| 47 | + libstb-dev |
| 48 | + test-cmd: | |
| 49 | + # Check if some of the expected executables were built |
| 50 | + if [ -f "00_base_code/00_base_code" ]; then |
| 51 | + echo "00_base_code built successfully" |
| 52 | + else |
| 53 | + echo "00_base_code build failed" |
| 54 | + exit 1 |
| 55 | + fi |
| 56 | +
|
| 57 | + if [ -f "15_hello_triangle/15_hello_triangle" ]; then |
| 58 | + echo "15_hello_triangle built successfully" |
| 59 | + else |
| 60 | + echo "15_hello_triangle build failed" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + if [ -f "31_compute_shader/31_compute_shader" ]; then |
| 65 | + echo "31_compute_shader built successfully" |
| 66 | + else |
| 67 | + echo "31_compute_shader build failed" |
| 68 | + exit 1 |
| 69 | + fi |
| 70 | + - os: windows-latest |
| 71 | + vulkan-install: | |
| 72 | + # Download the Vulkan SDK installer |
| 73 | + Invoke-WebRequest -Uri "https://sdk.lunarg.com/sdk/download/latest/windows/vulkan-sdk.exe" -OutFile "$env:TEMP\vulkan-sdk.exe" |
| 74 | +
|
| 75 | + # Run the installer with silent options |
| 76 | + Start-Process -FilePath "$env:TEMP\vulkan-sdk.exe" -ArgumentList "--accept-licenses --default-answer --confirm-command install" -Wait -NoNewWindow |
| 77 | +
|
| 78 | + # Find the actual installed SDK version |
| 79 | + $vulkanPath = Get-ChildItem "C:\VulkanSDK" | Sort-Object -Property Name -Descending | Select-Object -First 1 -ExpandProperty FullName |
| 80 | +
|
| 81 | + if (-not $vulkanPath) { |
| 82 | + $vulkanPath = "C:\VulkanSDK\latest" |
| 83 | + } |
| 84 | +
|
| 85 | + # Set environment variables with correct Windows-style paths |
| 86 | + echo "VULKAN_SDK=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 87 | + echo "$vulkanPath\Bin" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append |
| 88 | + echo "CMAKE_PREFIX_PATH=$vulkanPath" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 89 | + echo "Vulkan_INCLUDE_DIR=$vulkanPath\Include" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 90 | + echo "Vulkan_LIBRARY=$vulkanPath\Lib\vulkan-1.lib" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append |
| 91 | +
|
| 92 | + # Display debug information |
| 93 | + Write-Host "Vulkan SDK path: $vulkanPath" |
| 94 | + if (Test-Path "$vulkanPath\Lib") { |
| 95 | + Write-Host "Lib directory exists" |
| 96 | + } else { |
| 97 | + Write-Host "Lib directory does not exist" |
| 98 | + } |
| 99 | + if (Test-Path "$vulkanPath\Include") { |
| 100 | + Write-Host "Include directory exists" |
| 101 | + } else { |
| 102 | + Write-Host "Include directory does not exist" |
| 103 | + } |
| 104 | + deps-install: | |
| 105 | + vcpkg install glfw3:x64-windows glm:x64-windows tinyobjloader:x64-windows stb:x64-windows |
| 106 | + echo "CMAKE_TOOLCHAIN_FILE=$env:VCPKG_INSTALLATION_ROOT/scripts/buildsystems/vcpkg.cmake" >> $env:GITHUB_ENV |
| 107 | + test-cmd: | |
| 108 | + # Check if some of the expected executables were built |
| 109 | + if (Test-Path "00_base_code/Release/00_base_code.exe") { |
| 110 | + echo "00_base_code built successfully" |
| 111 | + } else { |
| 112 | + echo "00_base_code build failed" |
| 113 | + exit 1 |
| 114 | + } |
| 115 | +
|
| 116 | + if (Test-Path "15_hello_triangle/Release/15_hello_triangle.exe") { |
| 117 | + echo "15_hello_triangle built successfully" |
| 118 | + } else { |
| 119 | + echo "15_hello_triangle build failed" |
| 120 | + exit 1 |
| 121 | + } |
| 122 | +
|
| 123 | + if (Test-Path "31_compute_shader/Release/31_compute_shader.exe") { |
| 124 | + echo "31_compute_shader built successfully" |
| 125 | + } else { |
| 126 | + echo "31_compute_shader build failed" |
| 127 | + exit 1 |
| 128 | + } |
| 129 | +
|
| 130 | + runs-on: ${{ matrix.os }} |
| 131 | + |
| 132 | + steps: |
| 133 | + - uses: actions/checkout@v3 |
| 134 | + |
| 135 | + # Cache vcpkg packages for Windows |
| 136 | + - name: Cache vcpkg packages (Windows) |
| 137 | + if: runner.os == 'Windows' |
| 138 | + uses: actions/cache@v3 |
| 139 | + with: |
| 140 | + path: | |
| 141 | + ${{ env.VCPKG_INSTALLATION_ROOT }}/installed |
| 142 | + ${{ env.VCPKG_INSTALLATION_ROOT }}/packages |
| 143 | + ${{ env.VCPKG_INSTALLATION_ROOT }}/buildtrees |
| 144 | + key: ${{ runner.os }}-vcpkg-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('**/*.cpp') }} |
| 145 | + restore-keys: | |
| 146 | + ${{ runner.os }}-vcpkg-${{ hashFiles('**/CMakeLists.txt') }}- |
| 147 | + ${{ runner.os }}-vcpkg- |
| 148 | +
|
| 149 | + # Cache Vulkan SDK for Windows |
| 150 | + - name: Cache Vulkan SDK (Windows) |
| 151 | + if: runner.os == 'Windows' |
| 152 | + uses: actions/cache@v3 |
| 153 | + with: |
| 154 | + path: C:\VulkanSDK |
| 155 | + key: ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }} |
| 156 | + restore-keys: | |
| 157 | + ${{ runner.os }}-vulkan-sdk- |
| 158 | +
|
| 159 | + # Cache apt packages for Ubuntu |
| 160 | + - name: Cache apt packages (Ubuntu) |
| 161 | + if: runner.os == 'Linux' |
| 162 | + uses: actions/cache@v3 |
| 163 | + with: |
| 164 | + path: /var/cache/apt/archives |
| 165 | + key: ${{ runner.os }}-apt-${{ hashFiles('**/workflow.yml') }} |
| 166 | + restore-keys: | |
| 167 | + ${{ runner.os }}-apt- |
| 168 | +
|
| 169 | + # Cache Vulkan SDK for Ubuntu |
| 170 | + - name: Cache Vulkan SDK (Ubuntu) |
| 171 | + if: runner.os == 'Linux' |
| 172 | + uses: actions/cache@v3 |
| 173 | + with: |
| 174 | + path: | |
| 175 | + ${{ github.workspace }}/vulkan-sdk |
| 176 | + key: ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('**/*.cpp') }} |
| 177 | + restore-keys: | |
| 178 | + ${{ runner.os }}-vulkan-sdk-${{ hashFiles('**/CMakeLists.txt') }}- |
| 179 | + ${{ runner.os }}-vulkan-sdk- |
| 180 | +
|
| 181 | + - name: Install dependencies |
| 182 | + run: ${{ matrix.deps-install }} |
| 183 | + |
| 184 | + - name: Install Vulkan SDK |
| 185 | + run: ${{ matrix.vulkan-install }} |
| 186 | + |
| 187 | + - name: Verify Vulkan Installation (Windows) |
| 188 | + if: runner.os == 'Windows' |
| 189 | + run: | |
| 190 | + if (Test-Path $env:VULKAN_SDK) { |
| 191 | + echo "Vulkan SDK found at: $env:VULKAN_SDK" |
| 192 | +
|
| 193 | + # Check for critical directories and files |
| 194 | + $criticalPaths = @( |
| 195 | + "$env:VULKAN_SDK\Include", |
| 196 | + "$env:VULKAN_SDK\Lib", |
| 197 | + "$env:VULKAN_SDK\Bin", |
| 198 | + "$env:VULKAN_SDK\Include\vulkan\vulkan.h", |
| 199 | + "$env:VULKAN_SDK\Lib\vulkan-1.lib", |
| 200 | + "$env:VULKAN_SDK\Bin\glslangValidator.exe" |
| 201 | + ) |
| 202 | +
|
| 203 | + $allPathsExist = $true |
| 204 | + foreach ($path in $criticalPaths) { |
| 205 | + if (Test-Path $path) { |
| 206 | + echo "✓ Found: $path" |
| 207 | + } else { |
| 208 | + echo "✗ Missing: $path" |
| 209 | + $allPathsExist = $false |
| 210 | + } |
| 211 | + } |
| 212 | +
|
| 213 | + if ($allPathsExist) { |
| 214 | + echo "Vulkan SDK installation verified successfully" |
| 215 | + } else { |
| 216 | + echo "Vulkan SDK installation is incomplete!" |
| 217 | + exit 1 |
| 218 | + } |
| 219 | + } else { |
| 220 | + echo "Vulkan SDK not found!" |
| 221 | + exit 1 |
| 222 | + } |
| 223 | +
|
| 224 | + # Cache CMake build directory for Windows |
| 225 | + - name: Cache build artifacts (Windows) |
| 226 | + if: runner.os == 'Windows' |
| 227 | + uses: actions/cache@v3 |
| 228 | + with: |
| 229 | + path: ${{github.workspace}}/attachments/build |
| 230 | + key: ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('**/*.cpp') }}-${{ hashFiles('**/*.h') }} |
| 231 | + restore-keys: | |
| 232 | + ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt') }}- |
| 233 | + ${{ runner.os }}-build- |
| 234 | +
|
| 235 | + - name: Configure CMake (Windows) |
| 236 | + working-directory: ${{github.workspace}}/attachments |
| 237 | + if: runner.os == 'Windows' |
| 238 | + run: | |
| 239 | + cmake -B build -DCMAKE_BUILD_TYPE=Release ` |
| 240 | + -DVulkan_INCLUDE_DIR="$env:Vulkan_INCLUDE_DIR" ` |
| 241 | + -DVulkan_LIBRARY="$env:Vulkan_LIBRARY" ` |
| 242 | + -DCMAKE_PREFIX_PATH="$env:VULKAN_SDK" ` |
| 243 | + -DCMAKE_TOOLCHAIN_FILE="$env:CMAKE_TOOLCHAIN_FILE" |
| 244 | +
|
| 245 | + # Display CMake cache to debug Vulkan detection |
| 246 | + if (Test-Path "build/CMakeCache.txt") { |
| 247 | + Write-Host "CMake cache contents:" |
| 248 | + Get-Content "build/CMakeCache.txt" | Select-String -Pattern "Vulkan" |
| 249 | + } |
| 250 | +
|
| 251 | + # Verify Vulkan Installation for Ubuntu |
| 252 | + - name: Verify Vulkan Installation (Ubuntu) |
| 253 | + if: runner.os == 'Linux' |
| 254 | + run: | |
| 255 | + if [ -d "$VULKAN_SDK" ]; then |
| 256 | + echo "Vulkan SDK found at: $VULKAN_SDK" |
| 257 | + echo "Vulkan SDK installation verified" |
| 258 | + else |
| 259 | + echo "Vulkan SDK not found!" |
| 260 | + exit 1 |
| 261 | + fi |
| 262 | +
|
| 263 | + # Cache CMake build directory for Ubuntu |
| 264 | + - name: Cache build artifacts (Ubuntu) |
| 265 | + if: runner.os == 'Linux' |
| 266 | + uses: actions/cache@v3 |
| 267 | + with: |
| 268 | + path: ${{github.workspace}}/attachments/build |
| 269 | + key: ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt') }}-${{ hashFiles('**/*.cpp') }}-${{ hashFiles('**/*.h') }} |
| 270 | + restore-keys: | |
| 271 | + ${{ runner.os }}-build-${{ hashFiles('**/CMakeLists.txt') }}- |
| 272 | + ${{ runner.os }}-build- |
| 273 | +
|
| 274 | + - name: Configure CMake (Unix) |
| 275 | + working-directory: ${{github.workspace}}/attachments |
| 276 | + if: runner.os != 'Windows' |
| 277 | + run: | |
| 278 | + # Use Clang for better C++20 module support |
| 279 | + export CC=clang |
| 280 | + export CXX=clang++ |
| 281 | +
|
| 282 | + cmake -B build -G Ninja -DCMAKE_BUILD_TYPE=Release \ |
| 283 | + -DCMAKE_CXX_SCAN_FOR_MODULES=ON \ |
| 284 | + -DCMAKE_CXX_FLAGS="-std=c++20" |
| 285 | +
|
| 286 | + - name: Build |
| 287 | + working-directory: ${{github.workspace}}/attachments |
| 288 | + run: cmake --build build --config Release |
| 289 | + |
| 290 | + - name: Test Build Output |
| 291 | + working-directory: ${{github.workspace}}/attachments/build |
| 292 | + run: ${{ matrix.test-cmd }} |
0 commit comments