diff --git a/.ai/memory/build/dependencies.md b/.ai/memory/build/dependencies.md index b86a0a1..da31716 100644 --- a/.ai/memory/build/dependencies.md +++ b/.ai/memory/build/dependencies.md @@ -37,18 +37,38 @@ could reuse an install built for another feature set. GitHub Actions vcpkg cache keys must also distinguish the requested feature set. On PR #80, Debug and Release initially shared a key; the Debug job saved its smaller package cache first, and the Release job could not replace it with the -`full-drivers` packages. PR-scoped caches can also take precedence over a -development-branch cache with the same key. The workflow now saves caches only -from `development` and `main` pushes and lets pull requests restore them. -`main` is the default branch and cannot restore `development`-scoped caches, -so it must save its own. See -[`build.yml`](../../../.github/workflows/build.yml) and the observed run -`43613765529`. +`full-drivers` packages. `main` is the default branch and cannot restore +`development`-scoped caches, so it must save its own. + +An exact cache-key hit does not mean vcpkg reuses the packages. Package ABIs +include vcpkg's own scripts, and an unpinned vcpkg clone (vcpkg master moved +past `builtin-baseline`) changed every ABI: run `43765171463` hit all caches +but rebuilt GDAL and its dependencies for 30-86 minutes per job, and the +save-on-miss-only rule never refreshed the stale caches. CI therefore runs +`bootstrap-vcpkg.ps1 -Baseline` (vcpkg at the manifest baseline, full clone +because vcpkg reads older port versions from git history; a depth-1 clone fails +to load `gdal@3.12.4`). Separate per-leg dependency jobs save caches under unique +`-` keys. The sync script prunes unused archives +only after a successful install; after a failed install it retains all +archives, including packages not reached in the install plan. Pull requests +save only when vcpkg added packages; pushes also refresh stale-prefix caches. +An archive is named by the SHA-256 of `share//vcpkg_abi_info.txt` in the +install tree (verified locally). Each consumer waits only for its matching +platform and configuration dependency job; Release jobs use `-release` +triplets. + +The MSBuild parity step must not rebuild on its own: `Compare-CompileCommands.ps1` +without `-MSBuildLog` rebuilds with the default features, which in a +full-driver Release job reinstalled GDAL without `full-drivers` (+25 minutes) +and left the tests and artifacts on the reduced driver set. CI passes the build +step's detailed log instead. See +[`build.yml`](../../../.github/workflows/build.yml). ## References - [Dependency manifest](../../../vcpkg.json) - [Shared vcpkg configuration](../../../Directory.Build.props) - [Feature stamp and runtime-data deployment](../../../Directory.Build.targets) +- [CI binary-cache pruning](../../../build/scripts/Sync-VcpkgBinaryCache.ps1) - [Build and dependency guide](../../../docs/BUILDING.md#dependencies) - [GDAL version requirement](../../../docs/gdal-version.md) diff --git a/.github/workflows/build-msbuild.yml b/.github/workflows/build-msbuild.yml new file mode 100644 index 0000000..6d5cf21 --- /dev/null +++ b/.github/workflows/build-msbuild.yml @@ -0,0 +1,116 @@ +name: MSBuild build + +on: + workflow_call: + inputs: + platform: + required: true + type: string + configuration: + required: true + type: string + +jobs: + build: + runs-on: windows-2025 + timeout-minutes: 180 + + env: + VCPKG_BINARY_SOURCES: 'clear;files,${{ github.workspace }}\vcpkg-binary-cache,readwrite' + # The runner image does not ship SDK 10.0.28000 yet. + MWG_WINDOWS_SDK: '10.0' + + steps: + - name: Checkout + uses: actions/checkout@v7 + + - name: Compute vcpkg cache key + id: cache_key + shell: pwsh + run: | + $leg = 'vcpkg-binary-${{ runner.os }}-${{ inputs.platform }}-${{ inputs.configuration == 'Release' && 'release-full' || 'tests' }}-' + Add-Content -Path $env:GITHUB_OUTPUT -Value "leg=$leg" + Add-Content -Path $env:GITHUB_OUTPUT -Value "prefix=$leg$env:ImageVersion-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'build/triplets/*.cmake') }}-" + + - name: Restore vcpkg binary packages + uses: actions/cache/restore@v6 + with: + path: vcpkg-binary-cache + key: ${{ steps.cache_key.outputs.prefix }}${{ github.run_id }}-${{ github.run_attempt }} + restore-keys: | + ${{ steps.cache_key.outputs.prefix }} + ${{ steps.cache_key.outputs.leg }} + + - name: Bootstrap vcpkg + shell: pwsh + run: ./build/scripts/bootstrap-vcpkg.ps1 -Baseline + + - name: Set up MSBuild + uses: microsoft/setup-msbuild@v3 + + - name: Check build configuration + shell: pwsh + run: ./build/scripts/Test-BuildConfiguration.ps1 + + # The detailed log feeds the parity baseline below; a clean checkout + # compiles every translation unit, so no second (re)build is needed. + - name: Build + shell: pwsh + run: | + $release = '${{ inputs.configuration }}' -eq 'Release' + # Release builds use the release-only vcpkg triplets. + $vcpkgArguments = @('-p:MwgVcpkgFeatures=tests') + if ($release) { + $vcpkgArguments = @('-p:MwgVcpkgFeatures=tests%3Bfull-drivers', '-p:MwgVcpkgReleaseOnly=true') + } + New-Item -ItemType Directory -Force -Path out/parity | Out-Null + msbuild MapWinGIS6.slnx ` + -restore ` + -p:Configuration=${{ inputs.configuration }} ` + -p:Platform=${{ inputs.platform }} ` + -p:MwgWindowsSdk=$env:MWG_WINDOWS_SDK ` + @vcpkgArguments ` + -m -v:m ` + "-flp:logfile=out\parity\msbuild-${{ inputs.configuration }}-${{ inputs.platform }}.log;verbosity=detailed" + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + - name: Measure build parity baseline + shell: pwsh + run: | + pwsh -File build/scripts/Compare-CompileCommands.ps1 ` + -Configuration ${{ inputs.configuration }} ` + -Platform ${{ inputs.platform }} ` + -MSBuildLog out/parity/msbuild-${{ inputs.configuration }}-${{ inputs.platform }}.log ` + -FailOnLostFlags + + - name: Test + shell: pwsh + run: | + foreach ($test in @( + @{ Name = "core"; Project = "MapWinGIS.Core.Tests" }, + @{ Name = "core-gdal-init"; Project = "MapWinGIS.Core.GdalInitialization.Tests" }, + @{ Name = "activex"; Project = "MapWinGIS.ActiveX.Tests" } + )) { + $exe = "bin/${{ inputs.configuration }}/${{ inputs.platform }}/$($test.Project).exe" + $report = "testresults-$($test.Name)-${{ inputs.platform }}-${{ inputs.configuration }}.xml" + & $exe --gtest_output="xml:$report" + if ($LASTEXITCODE -ne 0) { + exit $LASTEXITCODE + } + } + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v7 + with: + name: testresults-${{ inputs.platform }}-${{ inputs.configuration }} + path: testresults-*-${{ inputs.platform }}-${{ inputs.configuration }}.xml + if-no-files-found: ignore + + - name: Upload binaries + if: ${{ inputs.configuration == 'Release' }} + uses: actions/upload-artifact@v7 + with: + name: MapWinGIS.Core-${{ inputs.platform }} + path: bin/Release/${{ inputs.platform }}/ + if-no-files-found: error diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b0829a4..bcf1b39 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -9,8 +9,86 @@ concurrency: group: build-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} cancel-in-progress: true +# vcpkg binary caches +# ------------------- +# Only the vcpkg-deps jobs write caches. They save the binary cache under +# "-" after vcpkg installs dependencies. +# Consumers wait only for their matching platform and configuration leg. The +# prefix covers vcpkg.json, whose builtin-baseline pins the vcpkg checkout +# (bootstrap-vcpkg.ps1 -Baseline). Legs: +# -tests Debug builds: default triplet, "tests" feature. +# -release-full Release builds: release-only triplet, +# "tests" and "full-drivers" features. + jobs: + vcpkg-deps-x64-tests: + permissions: + contents: read + uses: ./.github/workflows/vcpkg-deps.yml + with: + leg: x64-tests + + vcpkg-deps-win32-tests: + permissions: + contents: read + uses: ./.github/workflows/vcpkg-deps.yml + with: + leg: Win32-tests + + vcpkg-deps-x64-release-full: + permissions: + contents: read + uses: ./.github/workflows/vcpkg-deps.yml + with: + leg: x64-release-full + + vcpkg-deps-win32-release-full: + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + permissions: + contents: read + uses: ./.github/workflows/vcpkg-deps.yml + with: + leg: Win32-release-full + + vcpkg-cache-cleanup: + needs: [vcpkg-deps-x64-tests, vcpkg-deps-win32-tests, vcpkg-deps-x64-release-full, vcpkg-deps-win32-release-full] + if: ${{ !cancelled() }} + runs-on: windows-2025 + timeout-minutes: 10 + + permissions: + actions: write + contents: read + + strategy: + fail-fast: false + matrix: + leg: [x64-tests, x64-release-full, Win32-tests, Win32-release-full] + + steps: + - name: Delete superseded vcpkg caches + continue-on-error: true + shell: pwsh + env: + GH_TOKEN: ${{ github.token }} + run: | + $leg = "vcpkg-binary-$env:RUNNER_OS-${{ matrix.leg }}-" + $suffix = "$env:GITHUB_RUN_ID-$env:GITHUB_RUN_ATTEMPT" + $caches = gh cache list --repo $env:GITHUB_REPOSITORY --ref $env:GITHUB_REF ` + --key $leg --limit 100 --json id,key | ConvertFrom-Json + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + $keep = @($caches | Where-Object { $_.key.EndsWith($suffix, [StringComparison]::Ordinal) }) + if ($keep.Count -eq 0) { Write-Host "No cache was saved for ${{ matrix.leg }}."; exit 0 } + foreach ($cache in @($caches | Where-Object id -ne $keep[0].id)) { + Write-Host "Deleting $($cache.key)" + gh cache delete $cache.id --repo $env:GITHUB_REPOSITORY + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + } + cmake-parity: + needs: vcpkg-deps-x64-tests + # Still build when a dependency leg failed; the job then builds what is missing. + if: ${{ !cancelled() }} runs-on: windows-2025 timeout-minutes: 180 @@ -22,27 +100,28 @@ jobs: - name: Checkout uses: actions/checkout@v7 - - name: Record runner image version - id: runner_image + - name: Compute vcpkg cache key + id: cache_key shell: pwsh - run: Add-Content -Path $env:GITHUB_OUTPUT -Value "image_version=$env:ImageVersion" + run: | + $leg = 'vcpkg-binary-${{ runner.os }}-x64-tests-' + Add-Content -Path $env:GITHUB_OUTPUT -Value "leg=$leg" + Add-Content -Path $env:GITHUB_OUTPUT -Value "prefix=$leg$env:ImageVersion-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'build/triplets/*.cmake') }}-" - name: Restore vcpkg binary packages - id: cache uses: actions/cache/restore@v6 with: path: vcpkg-binary-cache - key: vcpkg-binary-${{ runner.os }}-x64-tests-${{ steps.runner_image.outputs.image_version }}-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'build/triplets/*.cmake') }} + key: ${{ steps.cache_key.outputs.prefix }}${{ github.run_id }}-${{ github.run_attempt }} restore-keys: | - vcpkg-binary-${{ runner.os }}-x64-tests- - vcpkg-binary-${{ runner.os }}-x64- + ${{ steps.cache_key.outputs.prefix }} + ${{ steps.cache_key.outputs.leg }} - name: Bootstrap vcpkg shell: pwsh - run: ./build/scripts/bootstrap-vcpkg.ps1 + run: ./build/scripts/bootstrap-vcpkg.ps1 -Baseline - name: Configure CMake preset - id: configure shell: pwsh run: | $vswhere = Join-Path ${env:ProgramFiles(x86)} 'Microsoft Visual Studio\Installer\vswhere.exe' @@ -56,13 +135,6 @@ jobs: & $env:ComSpec /d /s /c $commands if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - - name: Save vcpkg binary packages - if: always() && github.event_name == 'push' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main') && steps.cache.outputs.cache-hit != 'true' && steps.configure.outcome == 'success' - uses: actions/cache/save@v6 - with: - path: vcpkg-binary-cache - key: vcpkg-binary-${{ runner.os }}-x64-tests-${{ steps.runner_image.outputs.image_version }}-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'build/triplets/*.cmake') }} - - name: Build CMake preset id: build shell: pwsh @@ -86,191 +158,82 @@ jobs: -FailOnLostFlags ` -FailOnNewWarnings - cmake-vs: - runs-on: windows-2025 - timeout-minutes: 180 - - strategy: - fail-fast: false - matrix: ${{ fromJSON(github.event_name == 'push' && github.ref == 'refs/heads/main' && '{"platform":["x64","Win32"],"configuration":["Debug","Release"]}' || '{"include":[{"platform":"x64","configuration":"Debug"},{"platform":"x64","configuration":"Release"},{"platform":"Win32","configuration":"Debug"}]}') }} - - env: - VCPKG_BINARY_SOURCES: 'clear;files,${{ github.workspace }}\vcpkg-binary-cache,readwrite' - MWG_WINDOWS_SDK: '10.0' - - steps: - - name: Checkout - uses: actions/checkout@v7 - - - name: Record runner image version - id: runner_image - shell: pwsh - run: Add-Content -Path $env:GITHUB_OUTPUT -Value "image_version=$env:ImageVersion" - - - name: Restore vcpkg binary packages - id: cache - uses: actions/cache/restore@v6 - with: - path: vcpkg-binary-cache - key: vcpkg-binary-${{ runner.os }}-${{ matrix.platform }}-${{ matrix.configuration == 'Release' && 'full' || 'tests' }}-${{ steps.runner_image.outputs.image_version }}-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'build/triplets/*.cmake') }} - restore-keys: | - vcpkg-binary-${{ runner.os }}-${{ matrix.platform }}-${{ matrix.configuration == 'Release' && 'full' || 'tests' }}- - vcpkg-binary-${{ runner.os }}-${{ matrix.platform }}- - - - name: Bootstrap vcpkg - shell: pwsh - run: ./build/scripts/bootstrap-vcpkg.ps1 - - - name: Configure CMake - id: configure - shell: pwsh - run: | - $platform = '${{ matrix.platform }}' - $configuration = '${{ matrix.configuration }}' - $architecture = if ($platform -eq 'x64') { 'x64' } else { 'x86' } - $configurePreset = "vs2026-$architecture" - $buildPreset = "$configurePreset-$($configuration.ToLowerInvariant())" - $features = if ($configuration -eq 'Release') { 'tests;full-drivers' } else { 'tests' } - cmake --preset $configurePreset ` - "-DMWG_WINDOWS_SDK=$env:MWG_WINDOWS_SDK" ` - "-DVCPKG_MANIFEST_FEATURES=$features" - if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - Add-Content -Path $env:GITHUB_ENV -Value "MWG_CMAKE_BUILD_PRESET=$buildPreset" - - - name: Save vcpkg binary packages - if: always() && github.event_name == 'push' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main') && steps.cache.outputs.cache-hit != 'true' && steps.configure.outcome == 'success' - uses: actions/cache/save@v6 - with: - path: vcpkg-binary-cache - key: vcpkg-binary-${{ runner.os }}-${{ matrix.platform }}-${{ matrix.configuration == 'Release' && 'full' || 'tests' }}-${{ steps.runner_image.outputs.image_version }}-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'build/triplets/*.cmake') }} - - - name: Build CMake preset - shell: pwsh - run: | - cmake --build --preset $env:MWG_CMAKE_BUILD_PRESET --parallel - if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - - - name: Test CMake preset - shell: pwsh - run: | - ctest --preset $env:MWG_CMAKE_BUILD_PRESET --output-on-failure -LE interactive - if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } - - - name: Upload test results - if: always() - uses: actions/upload-artifact@v7 - with: - name: testresults-cmake-${{ matrix.platform }}-${{ matrix.configuration }} - path: out/b/${{ matrix.platform == 'x64' && 'vs-x64' || 'vs-x86' }}/test-results/*.xml - if-no-files-found: warn - - - name: Upload Release binaries - if: matrix.configuration == 'Release' - uses: actions/upload-artifact@v7 - with: - name: MapWinGIS.CMake-${{ matrix.platform }} - path: out/b/${{ matrix.platform == 'x64' && 'vs-x64' || 'vs-x86' }}/bin/Release/ - if-no-files-found: error - - build: - runs-on: windows-2025 - timeout-minutes: 180 - - strategy: - fail-fast: false - matrix: ${{ fromJSON(github.event_name == 'push' && github.ref == 'refs/heads/main' && '{"platform":["x64","Win32"],"configuration":["Debug","Release"]}' || '{"platform":["x64"],"configuration":["Debug","Release"]}') }} - - env: - VCPKG_BINARY_SOURCES: 'clear;files,${{ github.workspace }}\vcpkg-binary-cache,readwrite' - # The runner image does not ship SDK 10.0.28000 yet. - MWG_WINDOWS_SDK: '10.0' - - steps: - - name: Checkout - uses: actions/checkout@v7 - - - name: Record runner image version - id: runner_image - shell: pwsh - run: Add-Content -Path $env:GITHUB_OUTPUT -Value "image_version=$env:ImageVersion" - - - name: Restore vcpkg binary packages - id: cache - uses: actions/cache/restore@v6 - with: - path: vcpkg-binary-cache - key: vcpkg-binary-${{ runner.os }}-${{ matrix.platform }}-${{ matrix.configuration == 'Release' && 'full' || 'tests' }}-${{ steps.runner_image.outputs.image_version }}-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'build/triplets/*.cmake') }} - restore-keys: | - vcpkg-binary-${{ runner.os }}-${{ matrix.platform }}-${{ matrix.configuration == 'Release' && 'full' || 'tests' }}- - vcpkg-binary-${{ runner.os }}-${{ matrix.platform }}- - - - name: Bootstrap vcpkg - shell: pwsh - run: ./build/scripts/bootstrap-vcpkg.ps1 - - - name: Set up MSBuild - uses: microsoft/setup-msbuild@v3 - - - name: Check build configuration - shell: pwsh - run: ./build/scripts/Test-BuildConfiguration.ps1 - - - name: Build - id: build - shell: pwsh - run: | - $features = if ('${{ matrix.configuration }}' -eq 'Release') { 'tests%3Bfull-drivers' } else { 'tests' } - msbuild MapWinGIS6.slnx ` - -restore ` - -p:Configuration=${{ matrix.configuration }} ` - -p:Platform=${{ matrix.platform }} ` - -p:MwgWindowsSdk=$env:MWG_WINDOWS_SDK ` - "-p:MwgVcpkgFeatures=$features" ` - -m -v:m - - - name: Save vcpkg binary packages - if: always() && github.event_name == 'push' && (github.ref == 'refs/heads/development' || github.ref == 'refs/heads/main') && steps.cache.outputs.cache-hit != 'true' && steps.build.outcome == 'success' - uses: actions/cache/save@v6 - with: - path: vcpkg-binary-cache - key: vcpkg-binary-${{ runner.os }}-${{ matrix.platform }}-${{ matrix.configuration == 'Release' && 'full' || 'tests' }}-${{ steps.runner_image.outputs.image_version }}-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'build/triplets/*.cmake') }} - - - name: Measure build parity baseline - shell: pwsh - run: | - pwsh -File build/scripts/Compare-CompileCommands.ps1 ` - -Configuration ${{ matrix.configuration }} ` - -Platform ${{ matrix.platform }} ` - -FailOnLostFlags - - - name: Test - shell: pwsh - run: | - foreach ($test in @( - @{ Name = "core"; Project = "MapWinGIS.Core.Tests" }, - @{ Name = "core-gdal-init"; Project = "MapWinGIS.Core.GdalInitialization.Tests" }, - @{ Name = "activex"; Project = "MapWinGIS.ActiveX.Tests" } - )) { - $exe = "bin/${{ matrix.configuration }}/${{ matrix.platform }}/$($test.Project).exe" - $report = "testresults-$($test.Name)-${{ matrix.platform }}-${{ matrix.configuration }}.xml" - & $exe --gtest_output="xml:$report" - if ($LASTEXITCODE -ne 0) { - exit $LASTEXITCODE - } - } - - - name: Upload test results - if: always() - uses: actions/upload-artifact@v7 - with: - name: testresults-${{ matrix.platform }}-${{ matrix.configuration }} - path: testresults-*-${{ matrix.platform }}-${{ matrix.configuration }}.xml - if-no-files-found: ignore - - - name: Upload binaries - if: matrix.configuration == 'Release' - uses: actions/upload-artifact@v7 - with: - name: MapWinGIS.Core-${{ matrix.platform }} - path: bin/Release/${{ matrix.platform }}/ - if-no-files-found: error + cmake-vs-debug-x64: + needs: vcpkg-deps-x64-tests + if: ${{ !cancelled() }} + permissions: + contents: read + uses: ./.github/workflows/cmake-vs.yml + with: + platform: x64 + configuration: Debug + + cmake-vs-debug-win32: + needs: vcpkg-deps-win32-tests + if: ${{ !cancelled() }} + permissions: + contents: read + uses: ./.github/workflows/cmake-vs.yml + with: + platform: Win32 + configuration: Debug + + cmake-vs-release-x64: + needs: vcpkg-deps-x64-release-full + if: ${{ !cancelled() }} + permissions: + contents: read + uses: ./.github/workflows/cmake-vs.yml + with: + platform: x64 + configuration: Release + + cmake-vs-release-win32: + needs: vcpkg-deps-win32-release-full + if: ${{ !cancelled() && github.event_name == 'push' && github.ref == 'refs/heads/main' }} + permissions: + contents: read + uses: ./.github/workflows/cmake-vs.yml + with: + platform: Win32 + configuration: Release + + build-debug-x64: + needs: vcpkg-deps-x64-tests + if: ${{ !cancelled() }} + permissions: + contents: read + uses: ./.github/workflows/build-msbuild.yml + with: + platform: x64 + configuration: Debug + + build-debug-win32: + needs: vcpkg-deps-win32-tests + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + permissions: + contents: read + uses: ./.github/workflows/build-msbuild.yml + with: + platform: Win32 + configuration: Debug + + build-release-x64: + needs: vcpkg-deps-x64-release-full + if: ${{ !cancelled() }} + permissions: + contents: read + uses: ./.github/workflows/build-msbuild.yml + with: + platform: x64 + configuration: Release + + build-release-win32: + needs: vcpkg-deps-win32-release-full + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + permissions: + contents: read + uses: ./.github/workflows/build-msbuild.yml + with: + platform: Win32 + configuration: Release diff --git a/.github/workflows/cmake-vs.yml b/.github/workflows/cmake-vs.yml new file mode 100644 index 0000000..c22be17 --- /dev/null +++ b/.github/workflows/cmake-vs.yml @@ -0,0 +1,98 @@ +name: CMake Visual Studio build + +on: + workflow_call: + inputs: + platform: + required: true + type: string + configuration: + required: true + type: string + +jobs: + build: + runs-on: windows-2025 + timeout-minutes: 180 + + env: + VCPKG_BINARY_SOURCES: 'clear;files,${{ github.workspace }}\vcpkg-binary-cache,readwrite' + MWG_WINDOWS_SDK: '10.0' + + steps: + - name: Checkout + uses: actions/checkout@v7 + + - name: Compute vcpkg cache key + id: cache_key + shell: pwsh + run: | + $leg = 'vcpkg-binary-${{ runner.os }}-${{ inputs.platform }}-${{ inputs.configuration == 'Release' && 'release-full' || 'tests' }}-' + Add-Content -Path $env:GITHUB_OUTPUT -Value "leg=$leg" + Add-Content -Path $env:GITHUB_OUTPUT -Value "prefix=$leg$env:ImageVersion-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'build/triplets/*.cmake') }}-" + + - name: Restore vcpkg binary packages + uses: actions/cache/restore@v6 + with: + path: vcpkg-binary-cache + key: ${{ steps.cache_key.outputs.prefix }}${{ github.run_id }}-${{ github.run_attempt }} + restore-keys: | + ${{ steps.cache_key.outputs.prefix }} + ${{ steps.cache_key.outputs.leg }} + + - name: Bootstrap vcpkg + shell: pwsh + run: ./build/scripts/bootstrap-vcpkg.ps1 -Baseline + + - name: Configure CMake + shell: pwsh + run: | + $platform = '${{ inputs.platform }}' + $configuration = '${{ inputs.configuration }}' + $architecture = if ($platform -eq 'x64') { 'x64' } else { 'x86' } + $configurePreset = "vs2026-$architecture" + $buildPreset = "$configurePreset-$($configuration.ToLowerInvariant())" + $arguments = @("-DMWG_WINDOWS_SDK=$env:MWG_WINDOWS_SDK") + if ($configuration -eq 'Release') { + # Release-only triplets skip the debug build of every dependency. + $arguments += @( + '-DVCPKG_MANIFEST_FEATURES=tests;full-drivers', + "-DVCPKG_TARGET_TRIPLET=$architecture-windows-v145-release", + '-DVCPKG_HOST_TRIPLET=x64-windows-v145-release', + "-DVCPKG_INSTALLED_DIR=$env:GITHUB_WORKSPACE/vcpkg_installed/cmake-$platform-release" + ) + } + else { + $arguments += '-DVCPKG_MANIFEST_FEATURES=tests' + } + cmake --preset $configurePreset @arguments + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + Add-Content -Path $env:GITHUB_ENV -Value "MWG_CMAKE_BUILD_PRESET=$buildPreset" + + - name: Build CMake preset + shell: pwsh + run: | + cmake --build --preset $env:MWG_CMAKE_BUILD_PRESET --parallel + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + - name: Test CMake preset + shell: pwsh + run: | + ctest --preset $env:MWG_CMAKE_BUILD_PRESET --output-on-failure -LE interactive + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + - name: Upload test results + if: always() + uses: actions/upload-artifact@v7 + with: + name: testresults-cmake-${{ inputs.platform }}-${{ inputs.configuration }} + path: out/b/${{ inputs.platform == 'x64' && 'vs-x64' || 'vs-x86' }}/test-results/*.xml + if-no-files-found: warn + + - name: Upload Release binaries + if: ${{ inputs.configuration == 'Release' }} + uses: actions/upload-artifact@v7 + with: + name: MapWinGIS.CMake-${{ inputs.platform }} + path: out/b/${{ inputs.platform == 'x64' && 'vs-x64' || 'vs-x86' }}/bin/Release/ + if-no-files-found: error diff --git a/.github/workflows/vcpkg-deps.yml b/.github/workflows/vcpkg-deps.yml new file mode 100644 index 0000000..3aa63f0 --- /dev/null +++ b/.github/workflows/vcpkg-deps.yml @@ -0,0 +1,91 @@ +name: vcpkg dependency leg + +on: + workflow_call: + inputs: + leg: + required: true + type: string + +jobs: + install: + runs-on: windows-2025 + timeout-minutes: 180 + + permissions: + contents: read + + env: + VCPKG_BINARY_SOURCES: 'clear;files,${{ github.workspace }}\vcpkg-binary-cache,readwrite' + + steps: + - name: Checkout + uses: actions/checkout@v7 + + - name: Compute vcpkg cache key + id: cache_key + shell: pwsh + run: | + $leg = 'vcpkg-binary-${{ runner.os }}-${{ inputs.leg }}-' + Add-Content -Path $env:GITHUB_OUTPUT -Value "leg=$leg" + Add-Content -Path $env:GITHUB_OUTPUT -Value "prefix=$leg$env:ImageVersion-${{ hashFiles('vcpkg.json', 'vcpkg-configuration.json', 'build/triplets/*.cmake') }}-" + + - name: Restore vcpkg binary packages + id: cache + uses: actions/cache/restore@v6 + with: + path: vcpkg-binary-cache + key: ${{ steps.cache_key.outputs.prefix }}${{ github.run_id }}-${{ github.run_attempt }} + restore-keys: | + ${{ steps.cache_key.outputs.prefix }} + ${{ steps.cache_key.outputs.leg }} + + - name: Bootstrap vcpkg + shell: pwsh + run: ./build/scripts/bootstrap-vcpkg.ps1 -Baseline + + - name: Record restored packages + shell: pwsh + run: ./build/scripts/Sync-VcpkgBinaryCache.ps1 -Record -CacheDir vcpkg-binary-cache -SnapshotFile "$env:RUNNER_TEMP\vcpkg-cache-before.txt" + + - name: Install vcpkg dependencies + id: install + shell: pwsh + run: | + $platform, $kind = '${{ inputs.leg }}' -split '-', 2 + $architecture = if ($platform -eq 'x64') { 'x64' } else { 'x86' } + $suffix = if ($kind -eq 'release-full') { '-release' } else { '' } + $features = if ($kind -eq 'release-full') { @('tests', 'full-drivers') } else { @('tests') } + $vcpkg = Join-Path $env:MWG_VCPKG_ROOT 'vcpkg.exe' + & $vcpkg install ` + "--x-manifest-root=$env:GITHUB_WORKSPACE" ` + "--x-install-root=$env:RUNNER_TEMP\vcpkg-deps-installed" ` + "--overlay-triplets=$env:GITHUB_WORKSPACE\build\triplets" ` + --triplet "$architecture-windows-v145$suffix" ` + --host-triplet "x64-windows-v145$suffix" ` + @($features | ForEach-Object { "--x-feature=$_" }) ` + --clean-after-build + if ($LASTEXITCODE -ne 0) { exit $LASTEXITCODE } + + - name: Prune vcpkg binary packages + id: sync + if: always() && steps.install.outcome != 'skipped' + shell: pwsh + run: | + $arguments = @{ + Finish = $true + CacheDir = 'vcpkg-binary-cache' + SnapshotFile = "$env:RUNNER_TEMP\vcpkg-cache-before.txt" + InstalledDir = "$env:RUNNER_TEMP\vcpkg-deps-installed" + RestoredKey = '${{ steps.cache.outputs.cache-matched-key }}' + KeyPrefix = '${{ steps.cache_key.outputs.prefix }}' + } + if ('${{ steps.install.outcome }}' -ne 'success') { $arguments.SkipPrune = $true } + ./build/scripts/Sync-VcpkgBinaryCache.ps1 @arguments + + - name: Save vcpkg binary packages + if: always() && steps.sync.outputs.changed == 'true' && (github.event_name != 'pull_request' || steps.sync.outputs.added == 'true') + uses: actions/cache/save@v6 + with: + path: vcpkg-binary-cache + key: ${{ steps.cache_key.outputs.prefix }}${{ github.run_id }}-${{ github.run_attempt }} diff --git a/Directory.Build.props b/Directory.Build.props index 9e1f754..e159e47 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -39,16 +39,20 @@ true true $(MwgRepoRoot) + + false + <_MwgVcpkgTripletSuffix Condition="'$(MwgVcpkgReleaseOnly)' == 'true'">-release - $(MwgRepoRoot)vcpkg_installed\$(Platform)\ + $(MwgRepoRoot)vcpkg_installed\$(Platform)$(_MwgVcpkgTripletSuffix)\ false true true - x64-windows-v145 - x86-windows-v145 - x64-windows-v145 + x64-windows-v145$(_MwgVcpkgTripletSuffix) + x86-windows-v145$(_MwgVcpkgTripletSuffix) + x64-windows-v145$(_MwgVcpkgTripletSuffix) tests diff --git a/Directory.Build.targets b/Directory.Build.targets index 57e5af1..2ae8e2d 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -40,6 +40,13 @@ + + + +