Skip to content

Commit 5ed8d7c

Browse files
committed
ci: cache Windows compiler dependencies
1 parent 84adb60 commit 5ed8d7c

1 file changed

Lines changed: 87 additions & 22 deletions

File tree

.github/workflows/windows-build.yml

Lines changed: 87 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ jobs:
4141
phpts: nts
4242
update: true
4343

44-
- name: Install matching PHP development SDK
44+
- name: Resolve PHP build environment
45+
id: php-build-env
4546
shell: pwsh
4647
run: |
4748
$ErrorActionPreference = 'Stop'
@@ -51,23 +52,49 @@ jobs:
5152
$phpHome = Split-Path -Parent $phpExe
5253
$archiveName = "php-devel-pack-$phpVersion-nts-Win32-vs17-x64.zip"
5354
$archive = Join-Path $env:RUNNER_TEMP $archiveName
55+
56+
"PHP_VERSION=$phpVersion" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
57+
"PHP_HOME=$phpHome" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
58+
"PHPX_HOME=${{ github.workspace }}\vendor\swoole\phpx" |
59+
Out-File $env:GITHUB_ENV -Append -Encoding utf8
60+
"PHP_DEVEL_ARCHIVE=$archive" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
61+
"version=$phpVersion" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8
62+
"archive=$archive" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8
63+
64+
- name: Cache PHP development package
65+
uses: actions/cache@v4
66+
with:
67+
path: ${{ steps.php-build-env.outputs.archive }}
68+
key: windows-2022-php-devel-${{ steps.php-build-env.outputs.version }}-nts-vs17-x64
69+
70+
- name: Install matching PHP development SDK
71+
shell: pwsh
72+
run: |
73+
$ErrorActionPreference = 'Stop'
74+
75+
$phpVersion = $env:PHP_VERSION
76+
$phpHome = $env:PHP_HOME
77+
$archive = $env:PHP_DEVEL_ARCHIVE
78+
$archiveName = Split-Path -Leaf $archive
5479
$extractDir = Join-Path $env:RUNNER_TEMP "php-devel-$phpVersion"
55-
$downloaded = $false
5680
57-
foreach ($baseUrl in @(
58-
'https://downloads.php.net/~windows/releases',
59-
'https://downloads.php.net/~windows/releases/archives'
60-
)) {
61-
try {
62-
Invoke-WebRequest -Uri "$baseUrl/$archiveName" -OutFile $archive
63-
$downloaded = $true
64-
break
65-
} catch {
66-
Remove-Item $archive -Force -ErrorAction SilentlyContinue
81+
if (-not (Test-Path $archive)) {
82+
$downloaded = $false
83+
foreach ($baseUrl in @(
84+
'https://downloads.php.net/~windows/releases',
85+
'https://downloads.php.net/~windows/releases/archives'
86+
)) {
87+
try {
88+
Invoke-WebRequest -Uri "$baseUrl/$archiveName" -OutFile $archive
89+
$downloaded = $true
90+
break
91+
} catch {
92+
Remove-Item $archive -Force -ErrorAction SilentlyContinue
93+
}
94+
}
95+
if (-not $downloaded) {
96+
throw "Unable to download the PHP $phpVersion NTS development pack"
6797
}
68-
}
69-
if (-not $downloaded) {
70-
throw "Unable to download the PHP $phpVersion NTS development pack"
7198
}
7299
73100
Expand-Archive -Path $archive -DestinationPath $extractDir -Force
@@ -118,9 +145,6 @@ jobs:
118145
}
119146
}
120147
121-
"PHP_HOME=$phpHome" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
122-
"PHPX_HOME=${{ github.workspace }}\vendor\swoole\phpx" |
123-
Out-File $env:GITHUB_ENV -Append -Encoding utf8
124148
Write-Host "Using PHP $phpVersion from $phpHome"
125149
126150
- name: Install Composer dependencies
@@ -162,7 +186,15 @@ jobs:
162186
with:
163187
arch: x64
164188

189+
- name: Cache GMP and MPFR
190+
id: cache-gmp-mpfr
191+
uses: actions/cache@v4
192+
with:
193+
path: ${{ runner.temp }}\typephp-cache\vcpkg-x64-windows
194+
key: windows-2022-msvc-vcpkg-gmp-mpfr-x64-v1
195+
165196
- name: Install GMP and MPFR
197+
if: steps.cache-gmp-mpfr.outputs.cache-hit != 'true'
166198
shell: pwsh
167199
run: |
168200
$ErrorActionPreference = 'Stop'
@@ -175,20 +207,48 @@ jobs:
175207
}
176208
177209
$installed = Join-Path $env:VCPKG_INSTALLATION_ROOT "installed\$triplet"
178-
$sdkInclude = Join-Path $env:PHP_HOME 'SDK\include'
179-
$sdkLib = Join-Path $env:PHP_HOME 'SDK\lib'
180-
Copy-Item (Join-Path $installed 'include\*') $sdkInclude -Recurse -Force
210+
$cache = Join-Path $env:RUNNER_TEMP 'typephp-cache\vcpkg-x64-windows'
211+
New-Item "$cache\include", "$cache\lib", "$cache\bin" -ItemType Directory -Force |
212+
Out-Null
213+
Copy-Item (Join-Path $installed 'include\*') "$cache\include" -Recurse -Force
181214
182215
foreach ($library in @('gmp.lib', 'gmpxx.lib', 'mpfr.lib')) {
183216
$source = Join-Path $installed "lib\$library"
184217
if (-not (Test-Path $source)) {
185218
throw "vcpkg did not install $library"
186219
}
220+
Copy-Item $source "$cache\lib" -Force
221+
}
222+
Copy-Item (Join-Path $installed 'bin\*.dll') "$cache\bin" -Force
223+
224+
- name: Stage GMP and MPFR
225+
shell: pwsh
226+
run: |
227+
$ErrorActionPreference = 'Stop'
228+
229+
$cache = Join-Path $env:RUNNER_TEMP 'typephp-cache\vcpkg-x64-windows'
230+
$sdkInclude = Join-Path $env:PHP_HOME 'SDK\include'
231+
$sdkLib = Join-Path $env:PHP_HOME 'SDK\lib'
232+
Copy-Item "$cache\include\*" $sdkInclude -Recurse -Force
233+
234+
foreach ($library in @('gmp.lib', 'gmpxx.lib', 'mpfr.lib')) {
235+
$source = Join-Path $cache "lib\$library"
236+
if (-not (Test-Path $source)) {
237+
throw "The dependency cache does not contain $library"
238+
}
187239
Copy-Item $source $sdkLib -Force
188240
}
189-
Copy-Item (Join-Path $installed 'bin\*.dll') $env:PHP_HOME -Force
241+
Copy-Item "$cache\bin\*.dll" $env:PHP_HOME -Force
242+
243+
- name: Cache mpdecimal
244+
id: cache-mpdecimal
245+
uses: actions/cache@v4
246+
with:
247+
path: ${{ env.PHPX_HOME }}\thirdparty\mpdecimal\vcbuild\dist64
248+
key: windows-2022-msvc-mpdecimal-x64-${{ hashFiles('vendor/swoole/phpx/thirdparty/mpdecimal/**') }}
190249

191250
- name: Build mpdecimal
251+
if: steps.cache-mpdecimal.outputs.cache-hit != 'true'
192252
shell: pwsh
193253
run: |
194254
$ErrorActionPreference = 'Stop'
@@ -199,6 +259,11 @@ jobs:
199259
throw "mpdecimal build failed with exit code $LASTEXITCODE"
200260
}
201261
262+
- name: Stage mpdecimal
263+
shell: pwsh
264+
run: |
265+
$ErrorActionPreference = 'Stop'
266+
202267
$dist = Join-Path $env:PHPX_HOME 'thirdparty\mpdecimal\vcbuild\dist64'
203268
$sdkInclude = Join-Path $env:PHP_HOME 'SDK\include'
204269
$sdkLib = Join-Path $env:PHP_HOME 'SDK\lib'

0 commit comments

Comments
 (0)