-
Notifications
You must be signed in to change notification settings - Fork 60
425 lines (369 loc) · 16 KB
/
Copy pathwindows-build.yml
File metadata and controls
425 lines (369 loc) · 16 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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
name: Windows x64
on:
push:
pull_request:
workflow_dispatch:
permissions:
contents: read
concurrency:
group: windows-tpc-${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
COMPOSER_NO_INTERACTION: 1
COMPOSER_PROCESS_TIMEOUT: 0
jobs:
build-tpc:
name: Build - PHP ${{ matrix.php }} ZTS
runs-on: windows-2022
timeout-minutes: 90
strategy:
fail-fast: false
matrix:
php: ["8.4", "8.5"]
steps:
- name: Checkout TypePHP
uses: actions/checkout@v4
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
coverage: none
extensions: zip
tools: composer:v2
env:
fail-fast: true
phpts: ts
update: true
- name: Show PHP environment
shell: pwsh
run: |
php -v
php --ini
php -r 'printf("PHP_ZTS=%d\nopcache.enable=%s\nopcache.enable_cli=%s\nopcache.jit=%s\nopcache.jit_buffer_size=%s\npcre.jit=%s\n", PHP_ZTS, ini_get("opcache.enable"), ini_get("opcache.enable_cli"), ini_get("opcache.jit"), ini_get("opcache.jit_buffer_size"), ini_get("pcre.jit"));'
- name: Resolve PHP build environment
id: php-build-env
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$phpVersion = php -r 'echo PHP_VERSION;'
if (-not $phpVersion.StartsWith('${{ matrix.php }}.')) {
throw "setup-php installed PHP $phpVersion, expected ${{ matrix.php }}.x"
}
$threadSafety = php -r 'echo PHP_ZTS ? "zts" : "nts";'
if ($threadSafety -ne 'zts') {
throw "setup-php installed $threadSafety PHP, expected zts"
}
$zipAvailable = php -r 'echo class_exists("ZipArchive") ? "yes" : "no";'
if ($zipAvailable -ne 'yes') {
throw 'setup-php did not enable the ZipArchive extension required by package.php'
}
$phpExe = (Get-Command php).Source
$phpHome = Split-Path -Parent $phpExe
$archiveName = "php-devel-pack-$phpVersion-Win32-vs17-x64.zip"
$archive = Join-Path $env:RUNNER_TEMP $archiveName
"PHP_VERSION=$phpVersion" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
"PHP_THREAD_SAFETY=$threadSafety" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
"PHP_HOME=$phpHome" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
"PHPX_HOME=${{ github.workspace }}\vendor\swoole\phpx" |
Out-File $env:GITHUB_ENV -Append -Encoding utf8
"PHP_DEVEL_ARCHIVE=$archive" | Out-File $env:GITHUB_ENV -Append -Encoding utf8
"version=$phpVersion" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8
"thread_safety=$threadSafety" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8
"archive=$archive" | Out-File $env:GITHUB_OUTPUT -Append -Encoding utf8
- name: Cache PHP development package
id: cache-php-devel
uses: actions/cache/restore@v4
with:
path: ${{ steps.php-build-env.outputs.archive }}
key: windows-2022-php-devel-${{ steps.php-build-env.outputs.version }}-${{ steps.php-build-env.outputs.thread_safety }}-vs17-x64
- name: Install matching PHP development SDK
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$phpVersion = $env:PHP_VERSION
$phpHome = $env:PHP_HOME
$threadSafety = $env:PHP_THREAD_SAFETY
$archive = $env:PHP_DEVEL_ARCHIVE
$archiveName = Split-Path -Leaf $archive
$extractDir = Join-Path $env:RUNNER_TEMP "php-devel-$phpVersion"
if (-not (Test-Path $archive)) {
$downloaded = $false
foreach ($baseUrl in @(
'https://downloads.php.net/~windows/releases',
'https://downloads.php.net/~windows/releases/archives'
)) {
try {
Invoke-WebRequest -Uri "$baseUrl/$archiveName" -OutFile $archive
$downloaded = $true
break
} catch {
Remove-Item $archive -Force -ErrorAction SilentlyContinue
}
}
if (-not $downloaded) {
throw "Unable to download the PHP $phpVersion ZTS development pack"
}
}
Expand-Archive -Path $archive -DestinationPath $extractDir -Force
$sdkSource = Get-ChildItem $extractDir -Directory |
Where-Object { Test-Path (Join-Path $_.FullName 'include\main\php.h') } |
Select-Object -First 1
if ($null -eq $sdkSource) {
throw "The PHP development archive has an unexpected layout: $archiveName"
}
$sdk = Join-Path $phpHome 'SDK'
$sdkInclude = Join-Path $sdk 'include'
$sdkLib = Join-Path $sdk 'lib'
New-Item $sdkInclude, $sdkLib -ItemType Directory -Force | Out-Null
Copy-Item (Join-Path $sdkSource.FullName 'include\*') $sdkInclude -Recurse -Force
Copy-Item (Join-Path $sdkSource.FullName 'lib\*') $sdkLib -Force
$embedLibrary = Join-Path $phpHome 'php8embed.lib'
if (-not (Test-Path $embedLibrary)) {
throw "setup-php did not install php8embed.lib in $phpHome"
}
Copy-Item $embedLibrary $sdkLib -Force
$coreLibrary = 'php8ts.lib'
$runtimeLibrary = 'php8ts.dll'
# Temporary compatibility fix for PHP packages predating php/php-src#22940.
$hashHeader = Join-Path $sdkInclude 'ext\hash\php_hash.h'
$hashSource = [IO.File]::ReadAllText($hashHeader)
$invalidAllocation = 'char *base = ecalloc('
if ($hashSource.Contains($invalidAllocation)) {
$hashSource = $hashSource.Replace(
$invalidAllocation,
'char *base = (char *) ecalloc('
)
[IO.File]::WriteAllText(
$hashHeader,
$hashSource,
[Text.UTF8Encoding]::new($false)
)
}
foreach ($required in @(
(Join-Path $sdkInclude 'main\php.h'),
(Join-Path $sdkLib $coreLibrary),
(Join-Path $sdkLib 'php8embed.lib'),
(Join-Path $phpHome $runtimeLibrary)
)) {
if (-not (Test-Path $required)) {
throw "Required PHP SDK file is missing: $required"
}
}
Write-Host "Using PHP $phpVersion from $phpHome"
- name: Save PHP development package
if: steps.cache-php-devel.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ steps.php-build-env.outputs.archive }}
key: ${{ steps.cache-php-devel.outputs.cache-primary-key }}
- name: Install Composer dependencies
run: composer install --prefer-dist --no-progress
- name: Configure MSVC
uses: ilammy/msvc-dev-cmd@v1
with:
arch: x64
- name: Cache GMP and MPFR
id: cache-gmp-mpfr
uses: actions/cache/restore@v4
with:
path: ${{ runner.temp }}\typephp-cache\vcpkg-x64-windows
key: windows-2022-msvc-vcpkg-gmp-mpfr-x64-v1
- name: Install GMP and MPFR
if: steps.cache-gmp-mpfr.outputs.cache-hit != 'true'
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$triplet = 'x64-windows'
$vcpkg = Join-Path $env:VCPKG_INSTALLATION_ROOT 'vcpkg.exe'
& $vcpkg install "gmp:$triplet" "mpfr:$triplet"
if ($LASTEXITCODE -ne 0) {
throw "vcpkg failed with exit code $LASTEXITCODE"
}
$installed = Join-Path $env:VCPKG_INSTALLATION_ROOT "installed\$triplet"
$cache = Join-Path $env:RUNNER_TEMP 'typephp-cache\vcpkg-x64-windows'
New-Item "$cache\include", "$cache\lib", "$cache\bin" -ItemType Directory -Force |
Out-Null
Copy-Item (Join-Path $installed 'include\*') "$cache\include" -Recurse -Force
foreach ($library in @('gmp.lib', 'gmpxx.lib', 'mpfr.lib')) {
$source = Join-Path $installed "lib\$library"
if (-not (Test-Path $source)) {
throw "vcpkg did not install $library"
}
Copy-Item $source "$cache\lib" -Force
}
Copy-Item (Join-Path $installed 'bin\*.dll') "$cache\bin" -Force
- name: Save GMP and MPFR
if: steps.cache-gmp-mpfr.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ runner.temp }}\typephp-cache\vcpkg-x64-windows
key: ${{ steps.cache-gmp-mpfr.outputs.cache-primary-key }}
- name: Stage GMP and MPFR
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$cache = Join-Path $env:RUNNER_TEMP 'typephp-cache\vcpkg-x64-windows'
$sdkInclude = Join-Path $env:PHP_HOME 'SDK\include'
$sdkLib = Join-Path $env:PHP_HOME 'SDK\lib'
Copy-Item "$cache\include\*" $sdkInclude -Recurse -Force
foreach ($library in @('gmp.lib', 'gmpxx.lib', 'mpfr.lib')) {
$source = Join-Path $cache "lib\$library"
if (-not (Test-Path $source)) {
throw "The dependency cache does not contain $library"
}
Copy-Item $source $sdkLib -Force
}
Copy-Item "$cache\bin\*.dll" $env:PHP_HOME -Force
- name: Cache mpdecimal
id: cache-mpdecimal
uses: actions/cache/restore@v4
with:
path: ${{ env.PHPX_HOME }}\thirdparty\mpdecimal\vcbuild\dist64
key: windows-2022-msvc-mpdecimal-x64-${{ hashFiles('vendor/swoole/phpx/thirdparty/mpdecimal/**') }}
- name: Build mpdecimal
if: steps.cache-mpdecimal.outputs.cache-hit != 'true'
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$buildScript = Join-Path $env:PHPX_HOME 'thirdparty\mpdecimal\vcbuild\vcbuild64.bat'
$buildDirectory = Split-Path -Parent $buildScript
Push-Location $buildDirectory
try {
& cmd.exe /d /s /c vcbuild64.bat
if ($LASTEXITCODE -ne 0) {
throw "mpdecimal build failed with exit code $LASTEXITCODE"
}
} finally {
Pop-Location
}
- name: Save mpdecimal
if: steps.cache-mpdecimal.outputs.cache-hit != 'true'
uses: actions/cache/save@v4
with:
path: ${{ env.PHPX_HOME }}\thirdparty\mpdecimal\vcbuild\dist64
key: ${{ steps.cache-mpdecimal.outputs.cache-primary-key }}
- name: Stage mpdecimal
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$dist = Join-Path $env:PHPX_HOME 'thirdparty\mpdecimal\vcbuild\dist64'
$sdkInclude = Join-Path $env:PHP_HOME 'SDK\include'
$sdkLib = Join-Path $env:PHP_HOME 'SDK\lib'
Copy-Item (Join-Path $dist '*.lib') $sdkLib -Force
Copy-Item (Join-Path $dist '*.dll') $sdkLib -Force
Copy-Item (Join-Path $dist '*.dll') $env:PHP_HOME -Force
Copy-Item (Join-Path $dist 'mpdecimal.h') $sdkInclude -Force
Copy-Item (Join-Path $dist 'decimal.hh') $sdkInclude -Force
- name: Build PHPX
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$phpxBuild = Join-Path $env:PHPX_HOME 'build'
$sdkLib = Join-Path $env:PHP_HOME 'SDK\lib'
cmake -S $env:PHPX_HOME -B $phpxBuild -G Ninja `
-D CMAKE_BUILD_TYPE=Release `
-D BUILD_TESTS=OFF `
-D BUILD_EXT=OFF `
-D GITHUB_ACTION=ON `
-D MPDECIMAL_LIBRARY="$sdkLib\libmpdec-4.0.1.dll.lib" `
-D MPDECIMALXX_LIBRARY="$sdkLib\libmpdec++-4.0.1.dll.lib"
if ($LASTEXITCODE -ne 0) {
throw "PHPX configuration failed with exit code $LASTEXITCODE"
}
cmake --build $phpxBuild --target phpx --parallel 2
if ($LASTEXITCODE -ne 0) {
throw "PHPX build failed with exit code $LASTEXITCODE"
}
foreach ($required in @(
(Join-Path $env:PHPX_HOME 'lib\phpx.lib'),
(Join-Path $phpxBuild 'phpx.dll')
)) {
if (-not (Test-Path $required)) {
throw "Required PHPX build output is missing: $required"
}
}
- name: Build tpc.exe
shell: pwsh
run: |
php bin\tpc.php project.yml --job 1 --no-progress
if ($LASTEXITCODE -ne 0) {
throw "TypePHP build failed with exit code $LASTEXITCODE"
}
if (-not (Test-Path 'tpc.exe')) {
throw 'The compiler did not produce tpc.exe'
}
- name: Run Windows smoke tests
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$env:PATH = "$env:PHPX_HOME\build;$env:PATH"
& .\tpc.exe tests\windows\smoke\project.yml --job 1 --no-progress
if ($LASTEXITCODE -ne 0) {
throw "Windows smoke project compilation failed with exit code $LASTEXITCODE"
}
$smokeExe = Join-Path '${{ github.workspace }}' 'tests\windows\smoke\windows_smoke.exe'
if (-not (Test-Path $smokeExe)) {
throw "Windows smoke executable was not generated: $smokeExe"
}
$processInfo = [Diagnostics.ProcessStartInfo]::new()
$processInfo.FileName = $smokeExe
$processInfo.ArgumentList.Add('zts')
$processInfo.UseShellExecute = $false
$processInfo.RedirectStandardOutput = $true
$processInfo.RedirectStandardError = $true
$process = [Diagnostics.Process]::new()
$process.StartInfo = $processInfo
if (-not $process.Start()) {
throw 'Unable to start the Windows smoke executable'
}
$stdout = $process.StandardOutput.ReadToEnd()
$stderr = $process.StandardError.ReadToEnd()
$process.WaitForExit()
Write-Host "Windows smoke stdout: $stdout"
Write-Host "Windows smoke stderr: $stderr"
Write-Host "Windows smoke exit code: $($process.ExitCode)"
if ($process.ExitCode -ne 0) {
throw "Windows smoke executable failed with exit code $($process.ExitCode)"
}
if ($stdout.Trim() -ne 'windows-smoke-ok:zts') {
throw "Unexpected Windows smoke output: $stdout"
}
- name: Package tested Windows compiler
if: startsWith(github.ref, 'refs/tags/') && matrix.php == '8.5'
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
composer install --no-dev --prefer-dist --no-progress --classmap-authoritative
if ($LASTEXITCODE -ne 0) {
throw "Production Composer install failed with exit code $LASTEXITCODE"
}
$env:TYPEPHP_PACKAGE_VERSION = $env:GITHUB_REF_NAME
php package.php
if ($LASTEXITCODE -ne 0) {
throw "Windows packaging failed with exit code $LASTEXITCODE"
}
$packages = @(Get-ChildItem 'tpc_v*_windows_*.zip' -File)
if ($packages.Count -ne 1) {
throw "Expected one Windows release package, found $($packages.Count)"
}
- name: Upload Windows release package
if: startsWith(github.ref, 'refs/tags/') && matrix.php == '8.5'
uses: actions/upload-artifact@v4
with:
name: release-windows-x64-php-${{ matrix.php }}-zts
if-no-files-found: error
retention-days: 1
path: tpc_v*_windows_*.zip
- name: Upload Windows build outputs
if: always()
uses: actions/upload-artifact@v4
with:
name: tpc-windows-x64-php-${{ matrix.php }}-zts
if-no-files-found: warn
retention-days: 7
path: |
tpc.exe
tests/windows/smoke/windows_smoke.exe
tests/windows/smoke/build/**/*.cc
tests/windows/smoke/build/**/*.h
tests/windows/smoke/build/**/*.rsp