Skip to content

Commit

Permalink
Add support to install extensions from shivammathur/php-extensions-wi…
Browse files Browse the repository at this point in the history
…ndows
  • Loading branch information
shivammathur committed Dec 23, 2022
1 parent 5afd8a1 commit e51e662
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/configs/windows_extensions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xdebug
pcov
74 changes: 56 additions & 18 deletions src/scripts/extensions/add_extensions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@ Function Set-ExtensionPrerequisites
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$deps_dir
$extension
)
$deps_dir = "$ext_dir\$extension-vc$($installed.VCVersion)-$arch"
$deps = Get-ChildItem -Recurse -Path $deps_dir
if ($deps.Count -ne 0) {
# Symlink dependencies instead of adding the directory to PATH ...
Expand All @@ -20,6 +21,41 @@ Function Set-ExtensionPrerequisites
}
}

# Function to enable extension.
Function Enable-Extension() {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension
)
Enable-ExtensionDependencies $extension
Enable-PhpExtension -Extension $extension -Path $php_dir
Set-ExtensionPrerequisites $extension
Add-Log $tick $extension "Enabled"
}

# Function to add custom built PHP extension for nightly builds.
Function Add-NightlyExtension {
Param (
[Parameter(Position = 0, Mandatory = $true)]
[ValidateNotNull()]
[ValidateLength(1, [int]::MaxValue)]
[string]
$extension
)
if($ts) { $ts_part = 'ts' } else { $ts_part = 'nts' }
$repo = "$github/shivammathur/php-extensions-windows"
$url = "$repo/releases/download/builds/php$version`_$ts_part`_$arch`_$extension.dll"
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile "$ext_dir\php_$extension.dll"
if(Test-Path "$ext_dir\php_$extension.dll") {
Enable-Extension $extension > $null
} else {
throw "Failed to download the $extension"
}
}

# Function to add PHP extensions.
Function Add-Extension {
Param (
Expand Down Expand Up @@ -52,31 +88,33 @@ Function Add-Extension {
Add-Log $tick $extension "Enabled"
}
default {
Enable-ExtensionDependencies $extension
Enable-PhpExtension -Extension $extension_info.Handle -Path $php_dir
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Enabled"
Enable-Extension $extension_info.Handle
}
}
}
else {
# Patch till PHP 8.2 DLLs are released as stable.
$minimumStability = $stability
if($version -eq '8.2' -and $stability -eq 'stable') {
$minimumStability = 'snapshot'
}
if(($version -match $nightly_versions) -and (Select-String -Path $src\configs\windows_extensions -Pattern $extension -SimpleMatch -Quiet)) {
Add-NightlyExtension $extension
} else {
# Patch till PHP 8.2 DLLs are released as stable.
$minimumStability = $stability
if ($version -eq '8.2' -and $stability -eq 'stable')
{
$minimumStability = 'snapshot'
}

$params = @{ Extension = $extension; MinimumStability = $minimumStability; MaximumStability = $stability; Path = $php_dir; AdditionalFilesPath = $deps_dir; NoDependencies = $true }
if($extension_version -ne '') {
$params["Version"] = $extension_version
$params = @{ Extension = $extension; MinimumStability = $minimumStability; MaximumStability = $stability; Path = $php_dir; AdditionalFilesPath = $deps_dir; NoDependencies = $true }
if ($extension_version -ne '')
{
$params["Version"] = $extension_version
}
Install-PhpExtension @params
Set-ExtensionPrerequisites $extension
}
Install-PhpExtension @params
Set-ExtensionPrerequisites $deps_dir
Add-Log $tick $extension "Installed and enabled"
}
}
catch {
Add-Log $cross $extension "Could not install $extension on PHP $($installed.FullVersion)"
} catch {
Add-Log $cross $extension "Could not install $extension on PHP $( $installed.FullVersion )"
}
}

Expand Down

0 comments on commit e51e662

Please # to comment.