forked from crispy-computing-machine/Winbinder-PHP8
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbuild_all.ps1
More file actions
169 lines (141 loc) · 7.26 KB
/
build_all.ps1
File metadata and controls
169 lines (141 loc) · 7.26 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
param(
[string]$PhpVersion = "8.4.16",
[string]$DevPackVersion = $null,
[string]$VcVersion = "vs17"
)
# If DevPackVersion is not specified, use PhpVersion
if ([string]::IsNullOrEmpty($DevPackVersion)) {
$DevPackVersion = $PhpVersion
}
$ErrorActionPreference = "Stop"
$archs = @("x64", "x86")
$ts_options = @("1", "0")
$projectRoot = "c:\projects\winbinder"
$buildCache = "c:\build-cache"
foreach ($arch in $archs) {
foreach ($ts in $ts_options) {
Write-Host "`n============================================================"
Write-Host "Building Variant: ARCH=$arch, TS=$ts"
Write-Host "============================================================`n"
$ts_part = if ($ts -eq "0") { "-nts" } else { "" }
$develPackName = "php-devel-pack-$DevPackVersion$ts_part-Win32-$VcVersion-$arch.zip"
$develPackPath = "$buildCache\$develPackName"
Write-Host "Looking for dev pack: $develPackName"
Write-Host "Arch: $arch, TS: $ts, TS_part: $ts_part"
$url_releases = "https://windows.php.net/downloads/releases/$develPackName"
$url_archives = "https://windows.php.net/downloads/releases/archives/$develPackName"
# 1. Download PHP Development Pack
if (-not (Test-Path $develPackPath)) {
Write-Host "Downloading PHP development pack from: $url_releases"
try {
Invoke-WebRequest $url_releases -OutFile $develPackPath -UserAgent 'Mozilla/5.0'
Write-Host "Successfully downloaded from releases"
} catch {
Write-Host "Failed to download from releases, trying archives..."
try {
Invoke-WebRequest $url_archives -OutFile $develPackPath -UserAgent 'Mozilla/5.0'
Write-Host "Successfully downloaded from archives"
} catch {
Write-Host "Failed to download from both locations"
Write-Host "Releases URL: $url_releases"
Write-Host "Archives URL: $url_archives"
Write-Error "Could not download PHP development pack"
}
}
} else {
Write-Host "Dev pack already cached at: $develPackPath"
}
# 2. Extract Devel Pack
$develDirName = "php-$PhpVersion$ts_part-devel-$VcVersion-$arch"
$develDirPath = "$buildCache\$develDirName"
# Clean up any potentially conflicting directories first
$possibleDirNames = @(
"php-$DevPackVersion-devel-$VcVersion-$arch",
"php-$DevPackVersion-nts-devel-$VcVersion-$arch",
"php-$PhpVersion-devel-$VcVersion-$arch",
"php-$PhpVersion-nts-devel-$VcVersion-$arch"
)
foreach ($pDir in $possibleDirNames) {
$pPath = "$buildCache\$pDir"
if (Test-Path $pPath) {
Remove-Item -Recurse -Force $pPath
}
}
Write-Host "Extracting $develPackName..."
& 7z x $develPackPath "-o$buildCache" -y | Out-Null
# Find which directory was actually extracted
$foundDir = $null
foreach ($pDir in $possibleDirNames) {
$pPath = "$buildCache\$pDir"
if (Test-Path $pPath) {
$foundDir = $pPath
break
}
}
if (-not $foundDir) {
Write-Host "Extracted directory not found. Checking build cache content..."
Get-ChildItem $buildCache | ForEach-Object { Write-Host $_.FullName }
Write-Error "Error: Extracted directory for $develPackName not found."
}
Write-Host "Using PHP development pack at: $foundDir"
$develDirPath = $foundDir
$phpizePath = Join-Path $develDirPath "phpize.bat"
if (-not (Test-Path $phpizePath)) {
Write-Host "phpize.bat not found in $develDirPath. Checking directory content..."
Get-ChildItem $develDirPath -Recurse | ForEach-Object { Write-Host $_.FullName }
Write-Error "Error: phpize.bat not found."
}
# 3. Prepare Build Environment
Set-Location $projectRoot
# Explicitly set VS path for PHP SDK (VS 2022 for vs17, VS 2019 for vs16)
if ($VcVersion -eq "vs17") {
$env:PHP_SDK_VS17_DIR = "C:\Program Files\Microsoft Visual Studio\2022\Community"
$env:PHP_SDK_VC_DIR = "C:\Program Files\Microsoft Visual Studio\2022\Community"
} else {
$env:PHP_SDK_VS16_DIR = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"
$env:PHP_SDK_VC_DIR = "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"
}
# Update PATH
$oldPath = $env:PATH
$env:PATH = "$develDirPath\bin;$develDirPath;$oldPath"
# Create task script
$taskFile = "$projectRoot\task.bat"
$conf_cmd = "call configure --with-winbinder=shared --disable-debug 2>&1"
@("cd $projectRoot",
"set PATH=$develDirPath\bin;$develDirPath;%PATH%",
"call `"$phpizePath`" 2>&1",
"if exist configure.bat (call configure.bat --with-winbinder=shared --disable-debug 2>&1) else (echo configure.bat not found & exit 1)",
"nmake /nologo 2>&1",
"exit %errorlevel%"
) | Out-File -Encoding "ASCII" $taskFile
# 4. Run Build
$runner = "$buildCache\php-sdk\phpsdk-$VcVersion-$arch.bat"
Write-Host "Running build via $runner..."
& cmd /c "$runner -t $taskFile"
if ($LASTEXITCODE -ne 0) {
Write-Error "Build failed for ARCH=$arch, TS=$ts with exit code $LASTEXITCODE"
}
# 5. Package and Save Artifact
$ts_label = if ($ts -eq "1") { "ts" } else { "nts" }
$zipName = "php-winbinder-$PhpVersion-$arch-$ts_label.7z"
$outputDir = if ($arch -eq "x64") { "$projectRoot\x64" } else { $projectRoot }
$releaseFolder = if ($ts -eq "1") { "Release_TS" } else { "Release" }
$outputDir = Join-Path $outputDir $releaseFolder
$dllPath = Join-Path $outputDir "php_winbinder.dll"
if (Test-Path $dllPath) {
Write-Host "DLL found at $dllPath. Creating archive $zipName..."
& 7z a "$buildCache\$zipName" $dllPath -t7z | Out-Null
Push-AppveyorArtifact "$buildCache\$zipName"
} else {
Write-Error "Error: DLL not found at $dllPath"
}
# Cleanup for next variant
$env:PATH = $oldPath
Remove-Item $taskFile -ErrorAction SilentlyContinue
Get-ChildItem -Path $projectRoot -Include "config.h", "config.nice.bat", "config.log", "config.status", "Makefile", "php_winbinder.res" -Recurse | Remove-Item -Force
Get-ChildItem -Path $projectRoot -Include "*.obj", "*.pdb", "*.exp", "*.lib" -Recurse | Remove-Item -Force
if (Test-Path "$projectRoot\x64") { Remove-Item -Recurse -Force "$projectRoot\x64" }
if (Test-Path "$projectRoot\Release") { Remove-Item -Recurse -Force "$projectRoot\Release" }
if (Test-Path "$projectRoot\Release_TS") { Remove-Item -Recurse -Force "$projectRoot\Release_TS" }
}
}