Skip to content
Open
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
88 changes: 69 additions & 19 deletions .github/workflows/build-toolchain.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,23 +31,16 @@ jobs:
name: ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}
runs-on: windows-2022
timeout-minutes: 30

env:
VCPKG_FILE_CACHE: ${{ github.workspace }}\vcpkg-bincache
VCPKG_BINARY_SOURCES: clear;files,${{ github.workspace }}\vcpkg-bincache,readwrite
VCPKG_FEATURE_FLAGS: manifests,versions,binarycaching

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Cache vcpkg binary artifacts
uses: actions/cache@v4
with:
path: ${{ github.workspace }}\vcpkg-bincache
key: vcpkg-bincache-${{ runner.os }}-${{ hashFiles('vcpkg.json','vcpkg-lock.json') }}-${{ inputs.preset }}
restore-keys: |
vcpkg-bincache-${{ runner.os }}-${{ hashFiles('vcpkg.json','vcpkg-lock.json') }}-
vcpkg-bincache-${{ runner.os }}-

- name: Cache VC6 Installation
if: startsWith(inputs.preset, 'vc6')
id: cache-vc6
Expand Down Expand Up @@ -91,13 +84,11 @@ jobs:
if: startsWith(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 @@ -112,15 +103,65 @@ jobs:
with:
arch: x86

- name: Compute vcpkg cache key parts
if: startsWith(inputs.preset, 'win32')
id: vcpkg_key
shell: pwsh
run: |
$baseline = (Get-Content vcpkg.json | ConvertFrom-Json)."builtin-baseline"

$msvc = $env:VCToolsVersion
if (-not $msvc) { $msvc = "unknown" }

# Reduce churn: keep major.minor (e.g. 14.44)
$msvcMajorMinor = ($msvc -split '\.')[0..1] -join '.'

$triplet = "x86-windows"
if ("${{ inputs.preset }}" -like "x64*") { $triplet = "x64-windows" }

"baseline=$baseline" >> $env:GITHUB_OUTPUT
"msvc=$msvcMajorMinor" >> $env:GITHUB_OUTPUT
"triplet=$triplet" >> $env:GITHUB_OUTPUT

Write-Host "vcpkg cache key parts: baseline=$baseline, msvc=$msvcMajorMinor, triplet=$triplet"

- name: Restore vcpkg binary cache
if: startsWith(inputs.preset, 'win32')
id: vcpkg_cache
uses: actions/cache/restore@v4
with:
path: ${{ github.workspace }}\vcpkg-bincache
key: vcpkg-bincache-v2-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}
restore-keys: |
vcpkg-bincache-v2-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-
vcpkg-bincache-v2-${{ runner.os }}-

- name: Setup vcpkg
uses: lukka/run-vcpkg@v11
with:
runVcpkgInstall: false
doNotCache: true

- name: Configure vcpkg to use cached directory
if: startsWith(inputs.preset, 'win32')
shell: pwsh
run: |
$cacheDir = "${{ github.workspace }}\vcpkg-bincache"
New-Item -ItemType Directory -Force -Path $cacheDir | Out-Null

# lukka/run-vcpkg sets its own temp cache dir; override to force our cached dir
$env:VCPKG_DEFAULT_BINARY_CACHE = $cacheDir
$env:VCPKG_BINARY_SOURCES = "clear;files,$cacheDir,readwrite"

"VCPKG_DEFAULT_BINARY_CACHE=$cacheDir" >> $env:GITHUB_ENV
"VCPKG_BINARY_SOURCES=$env:VCPKG_BINARY_SOURCES" >> $env:GITHUB_ENV

- name: Configure ${{ inputs.game }} with CMake Using ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Preset
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' }}"
Expand All @@ -130,27 +171,36 @@ jobs:
$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
shell: pwsh
run: |
cmake --build --preset ${{ inputs.preset }}

- name: Save vcpkg binary cache
# Only one job should save to avoid "Unable to reserve cache" conflicts.
if: ${{ startsWith(inputs.preset, 'win32') && steps.vcpkg_cache.outputs.cache-hit != 'true' && inputs.game == 'Generals' && inputs.preset == 'win32-vcpkg-debug' }}
uses: actions/cache/save@v4
with:
path: ${{ github.workspace }}\vcpkg-bincache
key: vcpkg-bincache-v2-${{ runner.os }}-msvc${{ steps.vcpkg_key.outputs.msvc }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}

- name: Collect ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Artifact
shell: pwsh
run: |
$buildDir = "build\${{ inputs.preset }}"
$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
if ("${{ inputs.preset }}" -like "win32*") {
$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\$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 | Move-Item -Destination $artifactsDir -Verbose -Force

- name: Upload ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Artifact
Expand Down
Loading