Skip to content

Commit 2b6e2f4

Browse files
committed
Add flags for curl with brotli and zstd for PHP 8.4+
1 parent 131e6b1 commit 2b6e2f4

File tree

4 files changed

+108
-3
lines changed

4 files changed

+108
-3
lines changed

extension/BuildPhpExtension/private/Add-Extension.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ Function Add-Extension {
4242
}
4343
}
4444
}
45+
Update-CurlDependencyConfig -PhpVersion $Config.php_version | Out-Null
4546
$configW32Content = [string](Get-Content -Path "config.w32")
4647
$arguments = Get-ArgumentsFromConfig $Extension $configW32Content
4748
$argumentString = ''
@@ -86,4 +87,4 @@ Function Add-Extension {
8687
}
8788
end {
8889
}
89-
}
90+
}

extension/BuildPhpExtension/private/Get-ExtensionConfig.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ Function Get-ExtensionConfig {
139139
}
140140
}
141141

142+
Update-CurlDependencyConfig -PhpVersion $PhpVersion | Out-Null
142143
$configW32Content = [string](Get-Content -Path "config.w32")
143144
if($configW32Content.contains('PATH_PROG')) {
144145
[regex]::Matches($configW32Content, 'PATH_PROG\(([''"])([^''"]+)\1') | ForEach-Object {

extension/BuildPhpExtension/private/Invoke-Build.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ Function Invoke-Build {
1616
Add-StepLog "Building $($Config.name) extension"
1717
try {
1818
Set-GAGroup start
19+
Update-CurlDependencyConfig -PhpVersion $Config.php_version | Out-Null
1920

2021
$builder = "php-sdk\phpsdk-starter.bat"
2122
$task = [System.IO.Path]::Combine($PSScriptRoot, '..\config\task.bat')
22-
2323
$options = $Config.options
2424
if ($Config.debug_symbols) {
2525
$options += " --enable-debug-pack"
@@ -51,4 +51,4 @@ Function Invoke-Build {
5151
}
5252
end {
5353
}
54-
}
54+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
Function Update-CurlDependencyConfig {
2+
<#
3+
.SYNOPSIS
4+
Add curl brotli/zstd CHECK_LIB calls to config.w32 when required.
5+
.PARAMETER PhpVersion
6+
PHP Version
7+
.PARAMETER ConfigW32Path
8+
Path to config.w32
9+
#>
10+
[OutputType([bool])]
11+
param (
12+
[Parameter(Mandatory = $true, Position=0, HelpMessage='PHP Version')]
13+
[string] $PhpVersion,
14+
[Parameter(Mandatory = $false, Position=1, HelpMessage='Path to config.w32')]
15+
[string] $ConfigW32Path = 'config.w32'
16+
)
17+
begin {
18+
}
19+
process {
20+
if (-not (Test-Path -LiteralPath $ConfigW32Path -PathType Leaf)) {
21+
return $false
22+
}
23+
24+
if ($PhpVersion -ne 'master') {
25+
if ($PhpVersion -notmatch '^(\d+\.\d+(?:\.\d+)?)') {
26+
return $false
27+
}
28+
29+
if ([version] $matches[1] -lt [version] '8.4') {
30+
return $false
31+
}
32+
}
33+
34+
$configLines = Get-Content -Path $ConfigW32Path
35+
$configW32Content = $configLines -join "`r`n"
36+
if ($configW32Content -notmatch 'libcurl') {
37+
return $false
38+
}
39+
40+
$curlLibraries = @('brotlidec.lib', 'brotlicommon.lib', 'libzstd.lib')
41+
$missingLibraries = @($curlLibraries | Where-Object {
42+
$configW32Content -notmatch ("CHECK_LIB\((['""])" + [regex]::Escape($_) + '\1')
43+
})
44+
if ($missingLibraries.Count -eq 0) {
45+
return $false
46+
}
47+
48+
$updatedLines = New-Object 'System.Collections.Generic.List[string]'
49+
$updated = $false
50+
51+
foreach ($line in $configLines) {
52+
if (-not $updated) {
53+
$negatedPattern = '^(?<indent>\s*)if\s*\(\s*!\s*CHECK_LIB\((?<quote>[''"])(?<lib>[^''"]*nghttp2[^''"]*)\k<quote>(?<signature>\s*,\s*[^)]*)\)(?<suffix>.*)$'
54+
$negatedMatch = [regex]::Match($line, $negatedPattern)
55+
if ($negatedMatch.Success) {
56+
$indent = $negatedMatch.Groups['indent'].Value
57+
$quote = $negatedMatch.Groups['quote'].Value
58+
$library = $negatedMatch.Groups['lib'].Value
59+
$signature = $negatedMatch.Groups['signature'].Value
60+
$suffix = $negatedMatch.Groups['suffix'].Value
61+
$continuationIndent = $indent + ' '
62+
$updatedLines.Add("${indent}if(!CHECK_LIB($quote$library$quote$signature) ||")
63+
for ($i = 0; $i -lt $missingLibraries.Count; $i++) {
64+
$lineSuffix = if ($i -eq ($missingLibraries.Count - 1)) { $suffix } else { ' ||' }
65+
$updatedLines.Add("${continuationIndent}!CHECK_LIB($quote$($missingLibraries[$i])$quote$signature)$lineSuffix")
66+
}
67+
$updated = $true
68+
continue
69+
}
70+
71+
$chainPattern = '^(?<indent>\s*)(?<prefix>&&\s*)?CHECK_LIB\((?<quote>[''"])(?<lib>[^''"]*nghttp2[^''"]*)\k<quote>(?<signature>\s*,\s*[^)]*)\)(?<suffix>.*)$'
72+
$chainMatch = [regex]::Match($line, $chainPattern)
73+
if ($chainMatch.Success) {
74+
$indent = $chainMatch.Groups['indent'].Value
75+
$prefix = $chainMatch.Groups['prefix'].Value
76+
$quote = $chainMatch.Groups['quote'].Value
77+
$library = $chainMatch.Groups['lib'].Value
78+
$signature = $chainMatch.Groups['signature'].Value
79+
$suffix = $chainMatch.Groups['suffix'].Value
80+
$updatedLines.Add("${indent}${prefix}CHECK_LIB($quote$library$quote$signature)")
81+
for ($i = 0; $i -lt $missingLibraries.Count; $i++) {
82+
$lineSuffix = if ($i -eq ($missingLibraries.Count - 1)) { $suffix } else { '' }
83+
$updatedLines.Add("${indent}&& CHECK_LIB($quote$($missingLibraries[$i])$quote$signature)$lineSuffix")
84+
}
85+
$updated = $true
86+
continue
87+
}
88+
}
89+
90+
$updatedLines.Add($line)
91+
}
92+
93+
$updatedContent = $updatedLines -join "`r`n"
94+
if (-not $updated -or $updatedContent -eq $configW32Content) {
95+
return $false
96+
}
97+
98+
Set-Content -Path $ConfigW32Path -Value $updatedContent -Encoding ASCII
99+
return $true
100+
}
101+
end {
102+
}
103+
}

0 commit comments

Comments
 (0)