Skip to content

Commit 8797348

Browse files
committed
Build php in source directory for local sources
1 parent 4abd2d2 commit 8797348

2 files changed

Lines changed: 58 additions & 35 deletions

File tree

.github/workflows/local-test.yml

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
3232
$phpVersion = $phpRelease.version
3333
$phpMinorVersion = ($phpVersion -split '\.')[0..1] -join '.'
34+
$phpTag = "php-$phpVersion"
3435
3536
$headers = @{
3637
Accept = 'application/vnd.github+json'
@@ -48,12 +49,21 @@ jobs:
4849
4950
"php-version=$phpVersion" | Add-Content -Path $env:GITHUB_OUTPUT
5051
"php-version-minor=$phpMinorVersion" | Add-Content -Path $env:GITHUB_OUTPUT
52+
"php-tag=$phpTag" | Add-Content -Path $env:GITHUB_OUTPUT
5153
"xdebug-version=$xdebugVersion" | Add-Content -Path $env:GITHUB_OUTPUT
5254
5355
$xdebugPublishedAt = [DateTimeOffset]::Parse($xdebugRelease.published_at).ToString('yyyy-MM-dd')
5456
Write-Host "PHP 8.5 release: $phpVersion ($($phpRelease.date))"
5557
Write-Host "Xdebug release: $xdebugVersion ($xdebugPublishedAt)"
5658
59+
- name: Checkout php-src for local-source build
60+
uses: actions/checkout@v6
61+
with:
62+
repository: php/php-src
63+
ref: ${{ steps.versions.outputs.php-tag }}
64+
path: php-src
65+
fetch-depth: 1
66+
5767
- name: Install local modules into Program Files with Install-Module
5868
shell: powershell
5969
run: |
@@ -121,18 +131,19 @@ jobs:
121131
- name: Build PHP
122132
shell: pwsh
123133
run: |
124-
$phpBuildRoot = Join-Path $env:RUNNER_TEMP 'php-build'
125-
Remove-Item -Path $phpBuildRoot -Recurse -Force -ErrorAction SilentlyContinue
126-
New-Item -Path $phpBuildRoot -ItemType Directory -Force | Out-Null
127-
128134
$buildPhpManifest = Join-Path $env:BUILDPHP_MODULE_BASE 'BuildPhp.psd1'
135+
$phpSourceRoot = Join-Path $env:GITHUB_WORKSPACE 'php-src'
136+
137+
if (-not (Test-Path (Join-Path $phpSourceRoot 'main\php_version.h'))) {
138+
throw "Could not find a local php-src checkout in $phpSourceRoot."
139+
}
140+
129141
Write-Host "Importing BuildPhp from $buildPhpManifest"
130142
Import-Module $buildPhpManifest -Force
131143
132-
Push-Location $phpBuildRoot
144+
Push-Location $phpSourceRoot
133145
try {
134-
Invoke-PhpBuild -PhpVersion '${{ steps.versions.outputs.php-version }}' `
135-
-Arch $env:BUILD_ARCH `
146+
Invoke-PhpBuild -Arch $env:BUILD_ARCH `
136147
-Ts $env:BUILD_TS
137148
} finally {
138149
Pop-Location
@@ -170,7 +181,7 @@ jobs:
170181
PHP_VERSION: ${{ steps.versions.outputs.php-version }}
171182
XDEBUG_VERSION: ${{ steps.versions.outputs.xdebug-version }}
172183
run: |
173-
$phpArtifacts = Join-Path $env:RUNNER_TEMP 'php-build\artifacts'
184+
$phpArtifacts = Join-Path $env:GITHUB_WORKSPACE 'php-src\artifacts'
174185
$xdebugArtifacts = Join-Path $env:RUNNER_TEMP 'xdebug-build\artifacts'
175186
$smokeRoot = Join-Path $env:RUNNER_TEMP 'smoke'
176187
$phpExtract = Join-Path $smokeRoot 'php'
@@ -251,6 +262,6 @@ jobs:
251262
name: program-files-smoke-artifacts
252263
if-no-files-found: ignore
253264
path: |
254-
${{ runner.temp }}\php-build\artifacts\*
265+
${{ github.workspace }}\php-src\artifacts\*
255266
${{ runner.temp }}\xdebug-build\artifacts\*
256267
${{ runner.temp }}\smoke\*

php/BuildPhp/public/Invoke-PhpBuild.ps1

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -44,39 +44,51 @@ function Invoke-PhpBuild {
4444

4545
New-Item "$buildDirectory" -ItemType "directory" -Force > $null 2>&1
4646

47-
Set-Location "$buildDirectory"
47+
try {
48+
Set-Location "$buildDirectory"
4849

49-
Add-BuildRequirements -PhpVersion $PhpVersion -Arch $Arch -FetchSrc:$fetchSrc
50+
Add-BuildRequirements -PhpVersion $PhpVersion -Arch $Arch -FetchSrc:$fetchSrc
5051

51-
Copy-Item -Path $PSScriptRoot\..\config -Destination . -Recurse
52-
$buildPath = "$buildDirectory\config\$($VsConfig.vs)\$Arch\php-$PhpVersion"
53-
$sourcePath = "$buildDirectory\php-$PhpVersion-src"
54-
if(-not($fetchSrc)) {
55-
$sourcePath = $currentDirectory
56-
}
57-
Move-Item $sourcePath $buildPath
58-
Set-Location "$buildPath"
59-
New-Item "..\obj" -ItemType "directory" > $null 2>&1
60-
Copy-Item "..\config.$Ts.bat"
52+
$configDirectory = Join-Path $PSScriptRoot "..\config\$($VsConfig.vs)\$Arch"
53+
$configBatch = Join-Path $configDirectory "config.$Ts.bat"
6154

62-
if(-not [string]::IsNullOrWhiteSpace($env:LIBS_BUILD_RUNS)) {
63-
Add-PhpDeps -PhpVersion $PhpVersion -VsVersion $VsConfig.vs -Arch $Arch -Destination "$buildPath\..\deps"
64-
$taskTemplate = Join-Path $PSScriptRoot "..\runner\task-$Ts.bat"
65-
} else {
66-
$taskTemplate = Join-Path $PSScriptRoot "..\runner\task-$Ts-with-deps.bat"
67-
}
55+
if($fetchSrc) {
56+
Copy-Item -Path $PSScriptRoot\..\config -Destination . -Recurse
57+
$buildPath = "$buildDirectory\config\$($VsConfig.vs)\$Arch\php-$PhpVersion"
58+
$sourcePath = "$buildDirectory\php-$PhpVersion-src"
59+
Move-Item $sourcePath $buildPath
60+
} else {
61+
$buildPath = $currentDirectory
62+
}
63+
64+
$buildParent = Split-Path -Path $buildPath -Parent
65+
$artifactsDirectory = Join-Path $currentDirectory 'artifacts'
6866

69-
$task = [System.IO.Path]::GetFileName($taskTemplate)
70-
Copy-Item -Path $taskTemplate -Destination $task -Force
67+
Set-Location "$buildPath"
68+
New-Item (Join-Path $buildParent 'obj') -ItemType "directory" -Force > $null 2>&1
69+
Copy-Item -Path $configBatch -Destination (Join-Path $buildPath "config.$Ts.bat") -Force
7170

72-
Invoke-PhpSdkStarter -BuildDirectory $buildDirectory -VsConfig $VsConfig -Arch $Arch -Task $task
71+
if(-not [string]::IsNullOrWhiteSpace($env:LIBS_BUILD_RUNS)) {
72+
Add-PhpDeps -PhpVersion $PhpVersion -VsVersion $VsConfig.vs -Arch $Arch -Destination (Join-Path $buildParent 'deps')
73+
$taskTemplate = Join-Path $PSScriptRoot "..\runner\task-$Ts.bat"
74+
} else {
75+
$taskTemplate = Join-Path $PSScriptRoot "..\runner\task-$Ts-with-deps.bat"
76+
}
7377

74-
$artifacts = if ($Ts -eq "ts") {"..\obj\Release_TS\php-*.zip"} else {"..\obj\Release\php-*.zip"}
75-
New-Item "$currentDirectory\artifacts" -ItemType "directory" -Force > $null 2>&1
76-
xcopy $artifacts "$currentDirectory\artifacts\*"
77-
Move-Item "$buildDirectory\php-$PhpVersion-src.zip" "$currentDirectory\artifacts\"
78+
$task = [System.IO.Path]::GetFileName($taskTemplate)
79+
Copy-Item -Path $taskTemplate -Destination $task -Force
7880

79-
Set-Location "$currentDirectory"
81+
Invoke-PhpSdkStarter -BuildDirectory $buildDirectory -VsConfig $VsConfig -Arch $Arch -Task $task
82+
83+
$artifacts = if ($Ts -eq "ts") {"..\obj\Release_TS\php-*.zip"} else {"..\obj\Release\php-*.zip"}
84+
New-Item "$artifactsDirectory" -ItemType "directory" -Force > $null 2>&1
85+
xcopy $artifacts "$artifactsDirectory\*"
86+
if($fetchSrc) {
87+
Move-Item "$buildDirectory\php-$PhpVersion-src.zip" "$artifactsDirectory\"
88+
}
89+
} finally {
90+
Set-Location "$currentDirectory"
91+
}
8092
}
8193
end {
8294
}

0 commit comments

Comments
 (0)