Skip to content

[CMAKE][GITHUB] Simplify and consolidate CMakePresets for multi-config builds #1235

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 27 additions & 37 deletions .github/workflows/build-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ on:
preset:
required: true
type: string
description: "CMake preset"
description: "CMake configure preset"
configuration:
required: true
type: string
description: "Build configuration (Debug, Release, RelWithDebInfo)"
tools:
required: false
default: true
Expand All @@ -28,15 +32,15 @@ on:

jobs:
build:
name: Preset ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}
name: ${{ inputs.game }} ${{ inputs.preset }}-${{ inputs.configuration }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}
runs-on: windows-latest
timeout-minutes: 40
steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Cache VC6 Installation
if: startsWith(inputs.preset, 'vc6')
if: endsWith(inputs.preset, 'vc6')
id: cache-vc6
uses: actions/cache@v4
with:
Expand All @@ -51,7 +55,7 @@ jobs:
key: cmake-deps-${{ inputs.preset }}-${{ hashFiles('CMakePresets.json','cmake/**/*.cmake','**/CMakeLists.txt') }}

- name: Download VC6 Portable from Cloudflare R2
if: ${{ startsWith(inputs.preset, 'vc6') && steps.cache-vc6.outputs.cache-hit != 'true' }}
if: ${{ endsWith(inputs.preset, 'vc6') && steps.cache-vc6.outputs.cache-hit != 'true' }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.R2_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.R2_SECRET_ACCESS_KEY }}
Expand All @@ -66,7 +70,7 @@ jobs:
$fileHash = (Get-FileHash -Path VS6_VisualStudio6.7z -Algorithm SHA256).Hash
Write-Host "Downloaded file SHA256: $fileHash"
Write-Host "Expected file SHA256: $env:EXPECTED_HASH"
if ($hash -ne $env:EXPECTED_HASH) {
if ($fileHash -ne $env:EXPECTED_HASH) {
Write-Error "Hash verification failed! File may be corrupted or tampered with."
exit 1
}
Expand All @@ -76,16 +80,13 @@ jobs:
Remove-Item VS6_VisualStudio6.7z -Verbose

- name: Set Up VC6 Environment
if: startsWith(inputs.preset, 'vc6')
if: endsWith(inputs.preset, 'vc6')
shell: pwsh
run: |
# Define the base directories as local variables first
$VSCommonDir = "C:\VC6\VC6SP6\Common"
$MSDevDir = "C:\VC6\VC6SP6\Common\msdev98"
$MSVCDir = "C:\VC6\VC6SP6\VC98"
$VcOsDir = "WINNT"

# Set the variables in GitHub environment
"VSCommonDir=$VSCommonDir" >> $env:GITHUB_ENV
"MSDevDir=$MSDevDir" >> $env:GITHUB_ENV
"MSVCDir=$MSVCDir" >> $env:GITHUB_ENV
Expand All @@ -95,56 +96,45 @@ jobs:
"LIB=$MSVCDir\LIB;$MSVCDir\MFC\LIB;$env:LIB" >> $env:GITHUB_ENV

- name: Set Up VC2022 Environment
if: startsWith(inputs.preset, 'win32')
if: ${{ !endsWith(inputs.preset, 'vc6') }}
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x86

- name: Setup vcpkg
uses: lukka/run-vcpkg@v11

- name: Configure ${{ inputs.game }} with CMake Using ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Preset
- name: Configure (${{ inputs.preset }}, ${{ inputs.configuration }}) for ${{ inputs.game }}
shell: pwsh
run: |
$buildFlags = @(
"-DRTS_BUILD_ZEROHOUR=${{ inputs.game == 'GeneralsMD' && 'ON' || 'OFF' }}",
"-DRTS_BUILD_GENERALS=${{ inputs.game == 'Generals' && 'ON' || 'OFF' }}"
"-DRTS_BUILD_ZEROHOUR=${{ inputs.game == 'GeneralsMD' && 'ON' || 'OFF' }}",
"-DRTS_BUILD_GENERALS=${{ inputs.game == 'Generals' && 'ON' || 'OFF' }}"
)

$gamePrefix = "${{ inputs.game == 'Generals' && 'GENERALS' || 'ZEROHOUR' }}"
$buildFlags += "-DRTS_BUILD_CORE_TOOLS=${{ inputs.tools && 'ON' || 'OFF' }}"
$buildFlags += "-DRTS_BUILD_${gamePrefix}_TOOLS=${{ inputs.tools && 'ON' || 'OFF' }}"
$buildFlags += "-DRTS_BUILD_CORE_EXTRAS=${{ inputs.extras && 'ON' || 'OFF' }}"
$buildFlags += "-DRTS_BUILD_${gamePrefix}_EXTRAS=${{ inputs.extras && 'ON' || 'OFF' }}"

Write-Host "Build flags: $($buildFlags -join ' | ')"

cmake --preset ${{ inputs.preset }} $buildFlags

- name: Build ${{ inputs.game }} with CMake Using ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Preset
- name: Build ${{ inputs.game }} [${{ inputs.preset }} | ${{ inputs.configuration }}]
shell: pwsh
run: |
cmake --build --preset ${{ inputs.preset }}

- name: Collect ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Artifact
run: cmake --build build/${{ inputs.preset }} --config ${{ inputs.configuration }}

- name: Collect Artifact - ${{ inputs.game }} - ${{ inputs.preset }} - ${{ inputs.configuration }}
shell: pwsh
run: |
$buildDir = "build\${{ inputs.preset }}"
$artifactsDir = New-Item -ItemType Directory -Force -Path "$buildDir\${{ inputs.game }}\artifacts" -Verbose
$buildDir = "build/${{ inputs.preset }}/${{ inputs.configuration }}"
$artifactsDir = New-Item -ItemType Directory -Force -Path "$buildDir/${{ inputs.game }}/artifacts" -Verbose

if ("${{ inputs.preset }}" -like "win32*") {
# For win32 preset, look in config-specific subdirectories
$configToUse = if ("${{ inputs.preset }}" -match "debug") { "Debug" } else { "Release" }
$files = Get-ChildItem -Path "$buildDir\Core\$configToUse","$buildDir\${{ inputs.game }}\$configToUse" -File | Where-Object { $_.Extension -in @(".exe", ".dll", ".pdb") } -Verbose
} else {
$files = Get-ChildItem -Path "$buildDir\Core","$buildDir\${{ inputs.game }}" -File | Where-Object { $_.Extension -in @(".exe", ".dll", ".pdb") } -Verbose
}
$files = Get-ChildItem -Path "$buildDir/Core", "$buildDir/${{ inputs.game }}" -File | Where-Object { $_.Extension -in @(".exe", ".dll", ".pdb") } -Verbose
$files | Move-Item -Destination $artifactsDir -Verbose -Force

- name: Upload ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Artifact
- name: Upload Artifact - ${{ inputs.game }} - ${{ inputs.preset }} - ${{ inputs.configuration }}
uses: actions/upload-artifact@v4
with:
name: ${{ inputs.game }}-${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}
path: build\${{ inputs.preset }}\${{ inputs.game }}\artifacts
name: ${{ inputs.game }}-${{ inputs.preset }}-${{ inputs.configuration }}
path: build/${{ inputs.preset }}/${{ inputs.configuration }}/${{ inputs.game }}/artifacts
retention-days: 30
if-no-files-found: error


77 changes: 13 additions & 64 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,89 +57,38 @@ jobs:
echo "- Shared: ${{ steps.filter.outputs.shared == 'true' && '✅' || '❌' }}" >> $GITHUB_STEP_SUMMARY

build-generals:
name: Build Generals${{ matrix.preset && '' }}
name: Build Generals${{ matrix.preset && '' }}-${{ matrix.configuration }}
needs: detect-changes
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.generals == 'true' || needs.detect-changes.outputs.shared == 'true' }}
strategy:
matrix:
include:
- preset: "vc6"
tools: true
extras: true
- preset: "vc6-profile"
tools: true
extras: true
- preset: "vc6-debug"
tools: true
extras: true
- preset: "win32"
tools: true
extras: true
- preset: "win32-profile"
tools: true
extras: true
- preset: "win32-debug"
tools: true
extras: true
# vcpkg builds have been disabled for now due to excessive build times of 30 minutes per preset
# - preset: "win32-vcpkg"
# tools: true
# extras: true
# - preset: "win32-vcpkg-profile"
# tools: true
# extras: true
# - preset: "win32-vcpkg-debug"
# tools: true
# extras: true
preset: [ninja, ninja-vc6]
configuration: [Debug, Release, RelWithDebInfo]
fail-fast: false
uses: ./.github/workflows/build-toolchain.yml
with:
game: "Generals"
preset: ${{ matrix.preset }}
tools: ${{ matrix.tools }}
extras: ${{ matrix.extras }}
configuration: ${{ matrix.configuration }}
tools: true
extras: true
secrets: inherit

build-generalsmd:
name: Build GeneralsMD${{ matrix.preset && '' }}
name: Build GeneralsMD${{ matrix.preset && '' }}-${{ matrix.configuration }}
needs: detect-changes
if: ${{ github.event_name == 'workflow_dispatch' || needs.detect-changes.outputs.generalsmd == 'true' || needs.detect-changes.outputs.shared == 'true' }}
strategy:
matrix:
include:
- preset: "vc6"
tools: true
extras: true
- preset: "vc6-profile"
tools: true
extras: true
- preset: "vc6-debug"
tools: true
extras: true
- preset: "win32"
tools: true
extras: true
- preset: "win32-profile"
tools: true
extras: true
- preset: "win32-debug"
tools: true
extras: true
# vcpkg builds have been disabled for now due to excessive build times of 30 minutes per preset
# - preset: "win32-vcpkg"
# tools: true
# extras: true
# - preset: "win32-vcpkg-profile"
# tools: true
# extras: true
# - preset: "win32-vcpkg-debug"
# tools: true
# extras: true
preset: [ninja, ninja-vc6]
configuration: [Debug, Release, RelWithDebInfo]
fail-fast: false
uses: ./.github/workflows/build-toolchain.yml
with:
game: "GeneralsMD"
preset: ${{ matrix.preset }}
tools: ${{ matrix.tools }}
extras: ${{ matrix.extras }}
configuration: ${{ matrix.configuration }}
tools: true
extras: true
secrets: inherit

Loading
Loading