diff --git a/.github/actions/setup-build-environment/action.yaml b/.github/actions/setup-build-environment/action.yaml index 55918aeb0d..0e6879603d 100644 --- a/.github/actions/setup-build-environment/action.yaml +++ b/.github/actions/setup-build-environment/action.yaml @@ -8,6 +8,14 @@ inputs: description: "Visual Studio version to use ('2022' or '2026'). Defaults to '2026'." required: false default: "2026" + cmake-preset: + description: "The CMake configure preset name (e.g. ALL, ALL-VS2022). Used to resolve the expected generator for cache validation." + required: false + default: "ALL" + build-dir: + description: "The CMake binary directory to cache (e.g. build/ALL, build/ALL-VS2022)." + required: false + default: "build/ALL" outputs: msvc-version: description: "The detected MSVC compiler version" @@ -86,7 +94,7 @@ runs: - name: Cache CMake build output uses: actions/cache@v4 with: - path: build/ALL + path: ${{ inputs.build-dir }} key: ${{ runner.os }}-cmake-msvc-${{ steps.msvc_version.outputs.version }}-${{ inputs.cache-key-suffix }}-${{ github.event.inputs.cache-key-suffix || 'default' }}-${{ hashFiles('.gitmodules', 'extern/**', 'CMakePresets.json', 'vcpkg.json', 'vcpkg-configuration.json') }} restore-keys: | ${{ runner.os }}-cmake-msvc-${{ steps.msvc_version.outputs.version }}-${{ inputs.cache-key-suffix }}-${{ github.event.inputs.cache-key-suffix || 'default' }}- @@ -95,7 +103,8 @@ runs: - name: Remove stale CMake cache if configuration changed shell: pwsh run: | - $cacheFile = "build/ALL/CMakeCache.txt" + $buildDir = "${{ inputs.build-dir }}" + $cacheFile = "$buildDir/CMakeCache.txt" if (Test-Path $cacheFile) { $content = Get-Content $cacheFile -Raw $stale = $false @@ -109,20 +118,33 @@ runs: } } - # Check generator mismatch + # Check generator mismatch — resolve the expected generator from the + # configure preset, following the inherits chain, so VS2022 and VS2026 + # presets each validate against their own generator string. if ($content -match 'CMAKE_GENERATOR:INTERNAL=(.+)') { $cachedGenerator = $Matches[1].Trim() - # Read expected generator from CMakePresets.json - $presets = Get-Content "CMakePresets.json" -Raw | ConvertFrom-Json - $msvcPreset = $presets.configurePresets | Where-Object { $_.generator } | Select-Object -First 1 - if ($msvcPreset -and $msvcPreset.generator -ne $cachedGenerator) { - Write-Host "❌ Generator mismatch: cached='$cachedGenerator', expected='$($msvcPreset.generator)'" + $allPresets = (Get-Content "CMakePresets.json" -Raw | ConvertFrom-Json).configurePresets + function Resolve-PresetGenerator([string]$name, [int]$depth = 0) { + if ($depth -gt 10) { return $null } + $p = $allPresets | Where-Object { $_.name -eq $name } | Select-Object -First 1 + if (-not $p) { return $null } + if ($p.generator) { return $p.generator } + $parents = if ($p.inherits -is [array]) { $p.inherits } else { @($p.inherits) } + foreach ($parent in $parents) { + $gen = Resolve-PresetGenerator $parent ($depth + 1) + if ($gen) { return $gen } + } + return $null + } + $expectedGenerator = Resolve-PresetGenerator "${{ inputs.cmake-preset }}" + if ($expectedGenerator -and $expectedGenerator -ne $cachedGenerator) { + Write-Host "❌ Generator mismatch: cached='$cachedGenerator', expected='$expectedGenerator'" $stale = $true } } if ($stale) { - Write-Host "Removing stale build/ALL directory." - Remove-Item -Recurse -Force "build/ALL" + Write-Host "Removing stale $buildDir directory." + Remove-Item -Recurse -Force $buildDir } } diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 2f0651ee51..00eaabfb60 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -134,8 +134,12 @@ jobs: compiler: - name: vs2026 vs-version: "2026" + cmake-preset: ALL + build-dir: build/ALL - name: vs2022 vs-version: "2022" + cmake-preset: ALL-VS2022 + build-dir: build/ALL-VS2022 fail-fast: false steps: - name: Checkout code @@ -151,19 +155,21 @@ jobs: with: cache-key-suffix: "cpp-${{ matrix.compiler.name }}" vs-version: ${{ matrix.compiler.vs-version }} + cmake-preset: ${{ matrix.compiler.cmake-preset }} + build-dir: ${{ matrix.compiler.build-dir }} - name: Build using run-cmake uses: lukka/run-cmake@v10 with: - configurePreset: ALL + configurePreset: ${{ matrix.compiler.cmake-preset }} configurePresetAdditionalArgs: "['-DBUILD_SHADER_TESTS=OFF']" - buildPreset: ALL + buildPreset: ${{ matrix.compiler.cmake-preset }} - name: Extract version from CMake id: get_version shell: pwsh run: | - $content = Get-Content build/ALL/CMakeCache.txt + $content = Get-Content ${{ matrix.compiler.build-dir }}/CMakeCache.txt $versionLine = $content | Select-String -Pattern 'CMAKE_PROJECT_VERSION:STATIC' if ($versionLine) { $version = ($versionLine -replace '.*=([0-9]+\.[0-9]+\.[0-9]+).*', '$1').ToString() @@ -217,8 +223,12 @@ jobs: compiler: - name: vs2026 vs-version: "2026" + cmake-preset: ALL + build-dir: build/ALL - name: vs2022 vs-version: "2022" + cmake-preset: ALL-VS2022 + build-dir: build/ALL-VS2022 config: - name: "Flatrim" file: ".github/configs/shader-validation.yaml" @@ -245,6 +255,8 @@ jobs: with: cache-key-suffix: "validation-${{ matrix.compiler.name }}-${{ matrix.config.name }}" vs-version: ${{ matrix.compiler.vs-version }} + cmake-preset: ${{ matrix.compiler.cmake-preset }} + build-dir: ${{ matrix.compiler.build-dir }} - name: Prepare shaders if: steps.check-hlsl.outputs.skip != 'true' uses: ./.github/actions/prepare-shaders @@ -286,7 +298,7 @@ jobs: echo "fxc.exe not found - shader validation requires fxc.exe. Set --fxc to a valid path or ensure fxc.exe is in PATH." >&2 exit 1 fi - hlslkit-compile --fxc "${{ steps.find_fxc.outputs.fxc_path }}" --shader-dir build/ALL/aio/Shaders --output-dir build/ShaderCache --config ${{ matrix.config.file }} --max-warnings 0 --suppress-warnings X1519 + hlslkit-compile --fxc "${{ steps.find_fxc.outputs.fxc_path }}" --shader-dir ${{ matrix.compiler.build-dir }}/aio/Shaders --output-dir build/ShaderCache --config ${{ matrix.config.file }} --max-warnings 0 --suppress-warnings X1519 shell: bash - name: Upload shader validation logs @@ -318,8 +330,12 @@ jobs: compiler: - name: vs2026 vs-version: "2026" + cmake-preset: ALL + build-dir: build/ALL - name: vs2022 vs-version: "2022" + cmake-preset: ALL-VS2022 + build-dir: build/ALL-VS2022 fail-fast: false steps: - name: Checkout code @@ -341,20 +357,22 @@ jobs: with: cache-key-suffix: "tests-${{ matrix.compiler.name }}" vs-version: ${{ matrix.compiler.vs-version }} + cmake-preset: ${{ matrix.compiler.cmake-preset }} + build-dir: ${{ matrix.compiler.build-dir }} - name: Build shader tests if: steps.check-hlsl.outputs.skip != 'true' uses: lukka/run-cmake@v10 with: - configurePreset: ALL + configurePreset: ${{ matrix.compiler.cmake-preset }} configurePresetAdditionalArgs: "['-DBUILD_SHADER_TESTS=ON']" - buildPreset: ALL + buildPreset: ${{ matrix.compiler.cmake-preset }} buildPresetAdditionalArgs: "['--target shader_tests']" - name: Run shader unit tests if: steps.check-hlsl.outputs.skip != 'true' run: | - ctest --test-dir build/ALL -C Release --output-on-failure -R ShaderTests --timeout 300 + ctest --test-dir ${{ matrix.compiler.build-dir }} -C Release --output-on-failure -R ShaderTests --timeout 300 - name: Upload test results on failure if: failure() && steps.check-hlsl.outputs.skip != 'true' @@ -362,7 +380,7 @@ jobs: with: name: shader-test-results-${{ matrix.compiler.name }} path: | - build/ALL/Testing/** + ${{ matrix.compiler.build-dir }}/Testing/** retention-days: 7 if-no-files-found: ignore