Skip to content

Commit c1c377d

Browse files
committed
Read libraries from config.w32
1 parent 108c57a commit c1c377d

File tree

5 files changed

+167
-23
lines changed

5 files changed

+167
-23
lines changed

.github/workflows/pecl.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ jobs:
8383
env:
8484
artifact-naming-scheme: pecl
8585
auto-detect-args: true
86+
auto-detect-libs: true
8687

8788
artifacts:
8889
runs-on: ubuntu-latest

extension/BuildPhpExtension/BuildPhpExtension.psd1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
'Get-Extension',
8282
'Get-ExtensionConfig',
8383
'Get-ExtensionSource',
84+
'Get-LibrariesFromConfig',
8485
'Get-OlderVsVersion',
8586
'Get-PeclLibraryZip',
8687
'Get-PhpBuild',

extension/BuildPhpExtension/private/Get-ExtensionConfig.ps1

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,42 @@ Function Get-ExtensionConfig {
124124
}
125125
}
126126

127+
$configW32Content = [string](Get-Content -Path "config.w32")
128+
if($configW32Content.contains('PATH_PROG')) {
129+
[regex]::Matches($configW32Content, 'PATH_PROG\(([''"])([^''"]+)\1') | ForEach-Object {
130+
$config.build_tools += $_.Groups[2].Value
131+
}
132+
}
133+
if($configW32Content.contains('PYTHONHOME')) {
134+
$config.build_tools += "python"
135+
}
136+
137+
if($env:AUTO_DETECT_ARGS -eq 'true') {
138+
$argument = Get-ArgumentFromConfig $Extension $configW32Content
139+
$argumentKey = $argument.Split("=")[0]
140+
if($null -ne $argument -and -not($config.options.contains($argumentKey))) {
141+
$config.options += " $argument"
142+
}
143+
}
144+
145+
if($env:AUTO_DETECT_LIBS -eq 'true') {
146+
$detectedLibraries = Get-LibrariesFromConfig $Extension $VsVersion $Arch $configW32Content
147+
if($null -ne $detectedLibraries) {
148+
$LibrariesList = $Libraries
149+
$Libraries = $detectedLibraries.Split(" ")
150+
$LibrariesList | ForEach-Object {
151+
$libraryName = $_
152+
$_ -Match '^(.+?)-\d|' | Out-Null
153+
if($Matches.Count -gt 1) {
154+
$libraryName = $Matches[1]
155+
}
156+
if (-not(($Libraries -Join ' ').Contains($libraryName))) {
157+
$Libraries += $_
158+
}
159+
}
160+
}
161+
}
162+
127163
if($Libraries.Count -gt 0) {
128164
$phpSeries = Invoke-WebRequest -Uri "https://downloads.php.net/~windows/php-sdk/deps/$VsVersion/$Arch"
129165
$extensionSeries = Invoke-WebRequest -Uri "https://downloads.php.net/~windows/pecl/deps"
@@ -172,29 +208,6 @@ Function Get-ExtensionConfig {
172208
}
173209
}
174210

175-
$configW32Content = [string](Get-Content -Path "config.w32")
176-
if($configW32Content.contains('PATH_PROG')) {
177-
[regex]::Matches($configW32Content, 'PATH_PROG\(([''"])([^''"]+)\1') | ForEach-Object {
178-
$config.build_tools += $_.Groups[2].Value
179-
}
180-
}
181-
if($configW32Content.contains('PYTHONHOME')) {
182-
$config.build_tools += "python"
183-
}
184-
185-
if($env:AUTO_DETECT_ARGS -eq 'true') {
186-
$buildArgPrefix = $null;
187-
$dashedExtension = $Extension -replace "_", "-"
188-
if($configW32Content.contains("ARG_ENABLE(`"$dashedExtension`"")) {
189-
$buildArgPrefix = "enable"
190-
} elseif($configW32Content.contains("ARG_WITH(`"$dashedExtension`"")) {
191-
$buildArgPrefix = "with"
192-
}
193-
if(-not($config.options.contains("--$buildArgPrefix-$dashedExtension"))) {
194-
$config.options += " --$buildArgPrefix-$dashedExtension"
195-
}
196-
}
197-
198211
$config.build_directory = if ($Arch -eq "x64") { "x64\" } else { "" }
199212
$config.build_directory += "Release"
200213
if ($Ts -eq "ts") { $config.build_directory += "_TS" }
Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
Function Get-LibrariesFromConfig {
2+
<#
3+
.SYNOPSIS
4+
Get the Libraries from the config.w32 file
5+
.PARAMETER Extension
6+
Extension
7+
.PARAMETER VsVersion
8+
Visual Studio Version
9+
.PARAMETER Arch
10+
Architecture
11+
.PARAMETER ConfigW32Content
12+
config.w32 content
13+
#>
14+
[OutputType()]
15+
param (
16+
[Parameter(Mandatory = $true, Position=0, HelpMessage='Extension')]
17+
[string] $Extension,
18+
[Parameter(Mandatory = $true, Position=1, HelpMessage='Visual Studio Version')]
19+
[string] $VsVersion,
20+
[Parameter(Mandatory = $true, Position=2, HelpMessage='Architecture')]
21+
[string] $Arch,
22+
[Parameter(Mandatory = $true, Position=3, HelpMessage='config.w32 content')]
23+
[string] $ConfigW32Content
24+
)
25+
begin {
26+
$jsonPath = [System.IO.Path]::Combine($PSScriptRoot, '..\config\vs.json')
27+
}
28+
process {
29+
$jsonData = (
30+
Invoke-WebRequest -Uri "https://downloads.php.net/~windows/pecl/deps/libmapping.json"
31+
).Content | ConvertFrom-Json
32+
33+
$phpSeries = (Invoke-WebRequest -Uri "https://downloads.php.net/~windows/php-sdk/deps/$VsVersion/$Arch").Content.ToLower()
34+
35+
Function Find-Library {
36+
param (
37+
[Parameter(Mandatory=$true, Position=0)]
38+
[string]$MatchString,
39+
[Parameter(Mandatory=$true, Position=1)]
40+
[string[]]$VsVersions
41+
)
42+
foreach ($vsVersion in $VsVersions) {
43+
foreach ($vsVersionData in $JsonData.PSObject.Properties) {
44+
if($vsVersionData.Name -eq $VsVersion) {
45+
foreach ($archData in $vsVersionData.Value.PSObject.Properties) {
46+
if($archData.Name -eq $Arch) {
47+
foreach ($libs in $archData.Value.PSObject.Properties) {
48+
if ($libs.Value -match ($MatchString.Replace('*', '.*'))) {
49+
$libs.Name -Match '^(.+?)-\d' | Out-Null
50+
if(!$phpSeries.contains($matches[1].ToLower())) {
51+
$libs.Name -Match '^(.+?-\d)' | Out-Null
52+
}
53+
return $matches[1]
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}
60+
}
61+
return $null
62+
}
63+
64+
$jsonContent = Get-Content -Path $jsonPath -Raw
65+
$VsConfig = ConvertFrom-Json -InputObject $jsonContent
66+
$VsVersions = @($VsVersion)
67+
$VsVersions += $($VsConfig.vs | Get-Member -MemberType *Property).Name | Where-Object {
68+
# vs15 and above builds are compatible.
69+
($_ -lt $VsVersion -and $_ -ge "vc15")
70+
}
71+
72+
$foundItems = @()
73+
$libraryFilesFound = @()
74+
[regex]::Matches($ConfigW32Content, 'CHECK_LIB\(["'']([^"'']+)["'']|["'']([^"'']+.lib)["'']|(\w+\.lib)') | ForEach-Object {
75+
$_.Groups[1].Value.Split(';') + ($_.Groups[2].Value -Split '[^\w\.]') + ($_.Groups[3].Value -Split '[^\w\.]') | ForEach-Object {
76+
$libraryFilesFound += $_
77+
}
78+
}
79+
$libraryFilesFound | Select-Object -Unique | ForEach-Object {
80+
if($_) {
81+
switch ($_) {
82+
libeay32.lib { $library = "openssl" }
83+
ssleay32.lib { $library = "openssl" }
84+
Default { $library = Find-Library $_ $VsVersions }
85+
}
86+
if($library -and (-not($foundItems.Contains($library)))) {
87+
$foundItems += $library.ToLower()
88+
}
89+
}
90+
}
91+
92+
# Exceptions
93+
# Remove libsasl if the extension is mongodb
94+
if($Extension -eq "mongodb") {
95+
$foundItems = $foundItems | Where-Object {$_ -notmatch "libsasl.*"}
96+
}
97+
# Add zlib if the extension is memcached
98+
if($Extension -eq "memcached") {
99+
$foundItems += "zlib"
100+
}
101+
102+
$highestVersions = @{}
103+
104+
foreach ($item in $foundItems) {
105+
if ($item -match '^(.*?)-(\d+)$') {
106+
$libraryName, $version = $matches[1], $matches[2]
107+
if (-not $highestVersions.ContainsKey($libraryName) -or $highestVersions[$libraryName] -lt $version) {
108+
$highestVersions[$libraryName] = $version
109+
}
110+
} else {
111+
$highestVersions[$item] = -1
112+
}
113+
}
114+
115+
$finalItems = @()
116+
foreach ($library in $highestVersions.Keys) {
117+
if ($highestVersions[$library] -eq -1) {
118+
$finalItems += $library
119+
} else {
120+
$finalItems += "$library-" + $highestVersions[$library]
121+
}
122+
}
123+
124+
return $finalItems
125+
}
126+
end {
127+
}
128+
}

extension/action.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ runs:
6767
BUILD_DIRECTORY: ${{inputs.build-directory}}
6868
AUTH_TOKEN: ${{inputs.auth-token}}
6969
AUTO_DETECT_ARGS: ${{env.auto-detect-args}}
70+
AUTO_DETECT_LIBS: ${{env.auto-detect-libs}}
7071
run: |
7172
Import-Module ${{ github.action_path }}\BuildPhpExtension -Force
7273
Invoke-PhpBuildExtension -ExtensionUrl "${{inputs.extension-url}}" `

0 commit comments

Comments
 (0)