Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 41 additions & 1 deletion .github/workflows/build-assets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,49 @@ jobs:
name: pie-${{ github.sha }}.phar

- name: Build for ${{ runner.os }} ${{ runner.arch }} on ${{ matrix.operating-system }}
run: ${{ env.SPC_BINARY }} craft resources/spc/craft.yml
if: runner.os != 'Windows'
run: ${{ env.SPC_BINARY }} craft resources/spc/craft.yml --debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build for Windows (initial attempt, may fail due to zlib)
if: runner.os == 'Windows'
continue-on-error: true
run: ${{ env.SPC_BINARY }} craft resources/spc/craft.yml --debug
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: "Workaround: fix zlib 1.3.2 library naming on Windows"
if: runner.os == 'Windows'
shell: pwsh
run: |
# zlib 1.3.2 changed cmake output file names:
# zlibstatic.lib -> zs.lib, zlib.lib -> z.lib, zlib.dll -> z.dll
# PHP configure expects zlib_a.lib or zlib.lib, and SPC expects zlibstatic.lib.
# None of these exist, so zlib never gets linked.
if (Test-Path "buildroot\lib\zs.lib") {
Write-Host "Renaming zlib artifacts to expected names..."
Copy-Item "buildroot\lib\zs.lib" "buildroot\lib\zlibstatic.lib" -Force
Copy-Item "buildroot\lib\zs.lib" "buildroot\lib\zlib_a.lib" -Force
Remove-Item "buildroot\bin\z.dll" -Force -ErrorAction SilentlyContinue
Remove-Item "buildroot\lib\z.lib" -Force -ErrorAction SilentlyContinue
} else {
Write-Host "zs.lib not found, skipping workaround"
}

- name: "Retry configure + nmake after zlib fix (Windows)"
if: runner.os == 'Windows'
shell: pwsh
run: |
Push-Location source\php-src
# Re-run configure so it picks up zlib_a.lib this time
& "$env:GITHUB_WORKSPACE\php-sdk-binary-tools\phpsdk-vs17-x64.bat" -t configure.bat --task-args "--disable-all --with-php-build=$env:GITHUB_WORKSPACE\buildroot --with-extra-includes=$env:GITHUB_WORKSPACE\buildroot\include --with-extra-libs=$env:GITHUB_WORKSPACE\buildroot\lib --disable-cli --enable-micro --disable-embed --disable-cgi --enable-opcache-jit=yes --enable-zlib --with-openssl --with-openssl-argon2 --with-curl --enable-filter --with-iconv --enable-phar --enable-zts=no"
# Clean and rebuild
& "$env:GITHUB_WORKSPACE\php-sdk-binary-tools\phpsdk-vs17-x64.bat" -t nmake_clean_wrapper.bat --task-args "clean"
& "$env:GITHUB_WORKSPACE\php-sdk-binary-tools\phpsdk-vs17-x64.bat" -t nmake_micro_wrapper.bat --task-args micro
# Copy micro.sfx to where SPC expects it
Copy-Item "x64\Release\micro.sfx" "$env:GITHUB_WORKSPACE\buildroot\bin\micro.sfx" -Force
Pop-Location
- name: Bundle pie.phar into executable PIE binary
run: ${{ env.SPC_BINARY }} micro:combine pie.phar --output=${{ env.PIE_BINARY_OUTPUT }}

Expand Down
70 changes: 62 additions & 8 deletions src/Downloading/GithubPackageReleaseAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use function array_map;
use function in_array;
use function ltrim;
use function strtolower;

/** @internal This is not public API for PIE, so should not be depended upon unless you accept the risk of BC breaks */
Expand All @@ -34,15 +35,28 @@ public function findMatchingReleaseAssetUrl(
DownloadUrlMethod $downloadUrlMethod,
array $possibleReleaseAssetNames,
): string {
$releaseAsset = $this->selectMatchingReleaseAsset(
$targetPlatform,
$package,
$this->getReleaseAssetsForPackage($package, $httpDownloader, $downloadUrlMethod),
$downloadUrlMethod,
$possibleReleaseAssetNames,
);
try {
$releaseAsset = $this->selectMatchingReleaseAsset(
$targetPlatform,
$package,
$this->getReleaseAssetsForPackage($package, $httpDownloader, $downloadUrlMethod),
$downloadUrlMethod,
$possibleReleaseAssetNames,
);

return $releaseAsset['browser_download_url'];
} catch (Exception\CouldNotFindReleaseAsset $githubException) {
// GitHub release had no matching asset — try downloads.php.net as a fallback
// for Windows binaries, since many PECL extensions publish prebuilt DLLs there.
if ($downloadUrlMethod === DownloadUrlMethod::WindowsBinaryDownload) {
$fallbackUrl = $this->tryPhpNetWindowsDownload($package, $httpDownloader, $possibleReleaseAssetNames);
if ($fallbackUrl !== null) {
return $fallbackUrl;
}
}

return $releaseAsset['browser_download_url'];
throw $githubException;
}
}

/** @link https://github.com/squizlabs/PHP_CodeSniffer/issues/3734 */
Expand Down Expand Up @@ -114,4 +128,44 @@ static function (array $asset): array {
$decodedResponse['assets'],
);
}

/**
* Fallback: attempt to find a prebuilt Windows extension archive on
* downloads.php.net, which hosts PECL binaries that may not be attached
* to GitHub releases.
*
* URL pattern: https://downloads.php.net/~windows/pecl/releases/{ext}/{version}/{asset}
*
* @param non-empty-list<non-empty-string> $possibleReleaseAssetNames
*
* @return non-empty-string|null
*/
private function tryPhpNetWindowsDownload(
Package $package,
HttpDownloader $httpDownloader,
array $possibleReleaseAssetNames,
): string|null {
$extName = $package->extensionName()->name();
$versionWithoutV = ltrim($package->version(), 'vV');

foreach ($possibleReleaseAssetNames as $assetName) {
$url = 'https://downloads.php.net/~windows/pecl/releases/'
. $extName . '/' . $versionWithoutV . '/' . $assetName;

try {
$response = $httpDownloader->get($url, [
'http' => ['method' => 'HEAD'],
]);

if ($response->getStatusCode() === 200) {
return $url;
}
} catch (TransportException) {
// Asset not found at this URL, try next variant
continue;
}
}

return null;
}
}
17 changes: 17 additions & 0 deletions src/Platform/Architecture.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@ public static function parseArchitecture(string $architecture): self
default => self::x86,
};
}

/**
* Returns all known name variants for this architecture, with the
* canonical (enum case) name first. Used when matching asset filenames
* that may use platform-specific conventions (e.g. "x64" on Windows,
* "aarch64" on Linux).
*
* @return non-empty-list<non-empty-string>
*/
public function allNames(): array
{
return match ($this) {
self::x86_64 => ['x86_64', 'x64'],
self::arm64 => ['arm64', 'aarch64'],
self::x86 => ['x86'],
};
}
}
31 changes: 17 additions & 14 deletions src/Platform/PrePackagedBinaryAssetName.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,51 +21,54 @@ private function __construct()
/** @return non-empty-list<non-empty-string> */
public static function packageNames(TargetPlatform $targetPlatform, Package $package): array
{
return array_values(array_unique([
strtolower(sprintf(
$names = [];
foreach ($targetPlatform->architecture->allNames() as $arch) {
$names[] = strtolower(sprintf(
'php_%s-%s_php%s-%s-%s-%s%s%s.zip',
$package->extensionName()->name(),
$package->version(),
$targetPlatform->phpBinaryPath->majorMinorVersion(),
$targetPlatform->architecture->name,
$arch,
$targetPlatform->operatingSystemFamily->value,
$targetPlatform->libcFlavour()->value,
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '',
)),
strtolower(sprintf(
));
$names[] = strtolower(sprintf(
'php_%s-%s_php%s-%s-%s-%s%s%s.tgz',
$package->extensionName()->name(),
$package->version(),
$targetPlatform->phpBinaryPath->majorMinorVersion(),
$targetPlatform->architecture->name,
$arch,
$targetPlatform->operatingSystemFamily->value,
$targetPlatform->libcFlavour()->value,
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '',
)),
strtolower(sprintf(
));
$names[] = strtolower(sprintf(
'php_%s-%s_php%s-%s-%s-%s%s%s.zip',
$package->extensionName()->name(),
$package->version(),
$targetPlatform->phpBinaryPath->majorMinorVersion(),
$targetPlatform->architecture->name,
$arch,
$targetPlatform->operatingSystemFamily->value,
$targetPlatform->libcFlavour()->value,
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts',
)),
strtolower(sprintf(
));
$names[] = strtolower(sprintf(
'php_%s-%s_php%s-%s-%s-%s%s%s.tgz',
$package->extensionName()->name(),
$package->version(),
$targetPlatform->phpBinaryPath->majorMinorVersion(),
$targetPlatform->architecture->name,
$arch,
$targetPlatform->operatingSystemFamily->value,
$targetPlatform->libcFlavour()->value,
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts',
)),
]));
));
}

return array_values(array_unique($names));
}
}
73 changes: 51 additions & 22 deletions src/Platform/WindowsExtensionAssetName.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
use Php\Pie\Downloading\Exception\CouldNotFindReleaseAsset;
use RuntimeException;

use function array_unique;
use function array_values;
use function file_exists;
use function implode;
use function ltrim;
use function sprintf;
use function strtolower;

Expand All @@ -31,29 +34,45 @@ private static function assetNames(TargetPlatform $targetPlatform, Package $pack
/**
* During development, we swapped compiler/ts around. It is fairly trivial to support both, so we can check
* both formats pretty easily, just to avoid confusion for package maintainers...
*
* Additionally, some distributions (notably downloads.php.net) use alternative architecture labels
* (e.g. "x64" instead of "x86_64"), and version strings without the "v" prefix (e.g. "5.1.28" instead
* of "v5.1.28"). We generate variants covering all combinations to match either convention.
*/
return [
strtolower(sprintf(
'php_%s-%s-%s-%s-%s-%s.%s',
$package->extensionName()->name(),
$package->version(),
$targetPlatform->phpBinaryPath->majorMinorVersion(),
$targetPlatform->threadSafety->asShort(),
strtolower($targetPlatform->windowsCompiler->name),
$targetPlatform->architecture->name,
$fileExtension,
)),
strtolower(sprintf(
'php_%s-%s-%s-%s-%s-%s.%s',
$package->extensionName()->name(),
$package->version(),
$targetPlatform->phpBinaryPath->majorMinorVersion(),
strtolower($targetPlatform->windowsCompiler->name),
$targetPlatform->threadSafety->asShort(),
$targetPlatform->architecture->name,
$fileExtension,
)),
];
$version = $package->version();
$versionNoV = ltrim($version, 'vV');
$versions = array_unique([$version, $versionNoV]);
$architectures = $targetPlatform->architecture->allNames();

$names = [];
foreach ($versions as $ver) {
foreach ($architectures as $arch) {
// Format: {ts}-{compiler} (e.g. ts-vs17)
$names[] = strtolower(sprintf(
'php_%s-%s-%s-%s-%s-%s.%s',
$package->extensionName()->name(),
$ver,
$targetPlatform->phpBinaryPath->majorMinorVersion(),
$targetPlatform->threadSafety->asShort(),
strtolower($targetPlatform->windowsCompiler->name),
$arch,
$fileExtension,
));
// Format: {compiler}-{ts} (e.g. vs17-ts) — legacy/swapped ordering
$names[] = strtolower(sprintf(
'php_%s-%s-%s-%s-%s-%s.%s',
$package->extensionName()->name(),
$ver,
$targetPlatform->phpBinaryPath->majorMinorVersion(),
strtolower($targetPlatform->windowsCompiler->name),
$targetPlatform->threadSafety->asShort(),
$arch,
$fileExtension,
));
}
}

return array_values(array_unique($names));
}

/** @return non-empty-list<non-empty-string> */
Expand All @@ -79,6 +98,16 @@ public static function determineDllName(TargetPlatform $targetPlatform, Download
}
}

// Zips from downloads.php.net use a simple naming convention (e.g. "php_apcu.dll")
// without version/platform suffixes, so check for that as a fallback.
$simpleDllName = 'php_' . $package->package->extensionName()->name() . '.dll';
$fullSimpleDllName = $package->extractedSourcePath . '/' . $simpleDllName;
if (file_exists($fullSimpleDllName)) {
return $fullSimpleDllName;
}

$possibleDllNames[] = $simpleDllName;

throw new RuntimeException('Unable to find DLL for package, checked: ' . implode(', ', $possibleDllNames));
}
}
8 changes: 8 additions & 0 deletions test/unit/Downloading/DownloadUrlMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public function testWindowsPackages(): void
[
'php_foo-1.2.3-8.1-nts-vc15-x86_64.zip',
'php_foo-1.2.3-8.1-vc15-nts-x86_64.zip',
'php_foo-1.2.3-8.1-nts-vc15-x64.zip',
'php_foo-1.2.3-8.1-vc15-nts-x64.zip',
],
$downloadUrlMethod->possibleAssetNames($package, $targetPlatform),
);
Expand Down Expand Up @@ -146,6 +148,8 @@ public function testPrePackagedBinaryDownloads(): void
[
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-zts.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-zts.tgz',
'php_bar-1.2.3_php8.3-x64-linux-glibc-debug-zts.zip',
'php_bar-1.2.3_php8.3-x64-linux-glibc-debug-zts.tgz',
],
$downloadUrlMethod->possibleAssetNames($package, $targetPlatform),
);
Expand Down Expand Up @@ -222,6 +226,10 @@ public function testMultipleDownloadUrlMethods(): void
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug.tgz',
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-nts.zip',
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-nts.tgz',
'php_bar-1.2.3_php8.3-x64-linux-glibc-debug.zip',
'php_bar-1.2.3_php8.3-x64-linux-glibc-debug.tgz',
'php_bar-1.2.3_php8.3-x64-linux-glibc-debug-nts.zip',
'php_bar-1.2.3_php8.3-x64-linux-glibc-debug-nts.tgz',
],
$firstMethod->possibleAssetNames($package, $targetPlatform),
);
Expand Down
Loading