forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
209 lines (178 loc) · 9.32 KB
/
build-toolchain.yml
File metadata and controls
209 lines (178 loc) · 9.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
name: Build Toolchain
permissions:
contents: read
pull-requests: write
on:
workflow_call:
inputs:
game:
required: true
type: string
description: "Game to build (Generals, GeneralsMD)"
preset:
required: true
type: string
description: "CMake preset"
tools:
required: false
default: true
type: boolean
description: "Build tools"
extras:
required: false
default: false
type: boolean
description: "Build extras"
jobs:
build:
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@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
- name: Cache VC6 Installation
if: startsWith(inputs.preset, 'vc6')
id: cache-vc6
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: C:\VC6
key: vc6-permanent-cache-v2
- name: Cache CMake Dependencies
id: cache-cmake-deps
uses: actions/cache@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: build\${{ inputs.preset }}\_deps
key: cmake-deps-${{ inputs.preset }}-${{ hashFiles('CMakePresets.json','cmake/**/*.cmake','**/CMakeLists.txt') }}
- name: Download VC6 Portable from itsmattkc repo
if: ${{ startsWith(inputs.preset, 'vc6') && steps.cache-vc6.outputs.cache-hit != 'true' }}
env:
EXPECTED_HASH: "D0EE1F6DCEF7DB3AD703120D9FB4FAD49EBCA28F44372E40550348B1C00CA583"
COMMIT: "001c4bafdcf2ef4b474d693acccd35a91e848f40"
shell: pwsh
run: |
Write-Host "Downloading VC6 Portable Installation" -ForegroundColor Cyan
Invoke-WebRequest -Uri https://github.com/itsmattkc/MSVC600/archive/$env:COMMIT.zip -OutFile VS6_VisualStudio6.zip
Write-Host "Verifying File Integrity" -ForegroundColor Cyan
$fileHash = (Get-FileHash -Path VS6_VisualStudio6.zip -Algorithm SHA256).Hash
Write-Host "Downloaded file SHA256: $fileHash"
Write-Host "Expected file SHA256: $env:EXPECTED_HASH"
if ($fileHash -ne $env:EXPECTED_HASH) {
Write-Error "Hash verification failed! File may be corrupted or tampered with."
exit 1
}
Write-Host "Extracting Archive" -ForegroundColor Cyan
& Expand-Archive -Path VS6_VisualStudio6.zip -DestinationPath C:\VC6
Move-Item -Path C:\VC6\MSVC600-$env:COMMIT -Destination C:\VC6\VC6SP6
Remove-Item VS6_VisualStudio6.zip -Verbose
- name: Set Up VC6 Environment
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
"VcOsDir=$VcOsDir" >> $env:GITHUB_ENV
"PATH=$MSDevDir\BIN;$MSVCDir\BIN;$VSCommonDir\TOOLS\$VcOsDir;$VSCommonDir\TOOLS;$env:PATH" >> $env:GITHUB_ENV
"INCLUDE=$MSVCDir\ATL\INCLUDE;$MSVCDir\INCLUDE;$MSVCDir\MFC\INCLUDE;$env:INCLUDE" >> $env:GITHUB_ENV
"LIB=$MSVCDir\LIB;$MSVCDir\MFC\LIB;$env:LIB" >> $env:GITHUB_ENV
- name: Set Up VC2022 Environment
if: startsWith(inputs.preset, 'win32')
uses: ilammy/msvc-dev-cmd@0b201ec74fa43914dc39ae48a89fd1d8cb592756 # v1.13.0
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"
$triplet = "x86-windows"
if ("${{ inputs.preset }}" -like "x64*") { $triplet = "x64-windows" }
"baseline=$baseline" >> $env:GITHUB_OUTPUT
"triplet=$triplet" >> $env:GITHUB_OUTPUT
Write-Host "vcpkg cache key parts: baseline=$baseline, triplet=$triplet"
- name: Restore vcpkg binary cache
if: startsWith(inputs.preset, 'win32')
id: vcpkg_cache
uses: actions/cache/restore@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: ${{ github.workspace }}\vcpkg-bincache
key: vcpkg-bincache-v3-${{ runner.os }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}-${{ hashFiles('triplets/*.cmake') }}
restore-keys: |
vcpkg-bincache-v3-${{ runner.os }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-
vcpkg-bincache-v3-${{ runner.os }}-
- name: Setup vcpkg
uses: lukka/run-vcpkg@5e0cab206a5ea620130caf672fce3e4a6b5666a1 # v11.5
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
"VCPKG_OVERLAY_TRIPLETS=${{ github.workspace }}\triplets" >> $env:GITHUB_ENV
"VCPKG_INSTALL_OPTIONS=--x-abi-tools-use-exact-versions" >> $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' }}"
)
$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
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@cdf6c1fa76f9f475f3d7449005a359c84ca0f306 # v5.0.3
with:
path: ${{ github.workspace }}\vcpkg-bincache
key: vcpkg-bincache-v3-${{ runner.os }}-baseline${{ steps.vcpkg_key.outputs.baseline }}-${{ steps.vcpkg_key.outputs.triplet }}-${{ hashFiles('triplets/*.cmake') }}
- 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*") {
$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 | Move-Item -Destination $artifactsDir -Verbose -Force
- name: Upload ${{ inputs.game }} ${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }} Artifact
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
name: ${{ inputs.game }}-${{ inputs.preset }}${{ inputs.tools && '+t' || '' }}${{ inputs.extras && '+e' || '' }}
path: build\${{ inputs.preset }}\${{ inputs.game }}\artifacts
retention-days: 30
if-no-files-found: error