diff --git a/src/Platform/PrePackagedBinaryAssetName.php b/src/Platform/PrePackagedBinaryAssetName.php index eda3f947..0b25db8a 100644 --- a/src/Platform/PrePackagedBinaryAssetName.php +++ b/src/Platform/PrePackagedBinaryAssetName.php @@ -21,51 +21,32 @@ private function __construct() /** @return non-empty-list */ public static function packageNames(TargetPlatform $targetPlatform, Package $package): array { - return array_values(array_unique([ - strtolower(sprintf( - 'php_%s-%s_php%s-%s-%s-%s%s%s.zip', - $package->extensionName()->name(), - $package->version(), - $targetPlatform->phpBinaryPath->majorMinorVersion(), - $targetPlatform->architecture->name, - $targetPlatform->operatingSystemFamily->value, - $targetPlatform->libcFlavour()->value, - $targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '', - $targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '', - )), - strtolower(sprintf( - 'php_%s-%s_php%s-%s-%s-%s%s%s.tgz', - $package->extensionName()->name(), - $package->version(), - $targetPlatform->phpBinaryPath->majorMinorVersion(), - $targetPlatform->architecture->name, - $targetPlatform->operatingSystemFamily->value, - $targetPlatform->libcFlavour()->value, - $targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '', - $targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '', - )), - strtolower(sprintf( - 'php_%s-%s_php%s-%s-%s-%s%s%s.zip', - $package->extensionName()->name(), - $package->version(), - $targetPlatform->phpBinaryPath->majorMinorVersion(), - $targetPlatform->architecture->name, - $targetPlatform->operatingSystemFamily->value, - $targetPlatform->libcFlavour()->value, - $targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '', - $targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts', - )), - strtolower(sprintf( - 'php_%s-%s_php%s-%s-%s-%s%s%s.tgz', - $package->extensionName()->name(), - $package->version(), - $targetPlatform->phpBinaryPath->majorMinorVersion(), - $targetPlatform->architecture->name, - $targetPlatform->operatingSystemFamily->value, - $targetPlatform->libcFlavour()->value, - $targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '', - $targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts', - )), - ])); + $debug = $targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : ''; + $tsNoSuffix = $targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : ''; + $tsWithSuffix = $targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts'; + $libc = $targetPlatform->libcFlavour()->value; + + $name = $package->extensionName()->name(); + $version = $package->version(); + $phpVer = $targetPlatform->phpBinaryPath->majorMinorVersion(); + $arch = $targetPlatform->architecture->name; + $os = $targetPlatform->operatingSystemFamily->value; + + $names = [ + strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.zip', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsNoSuffix)), + strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.tgz', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsNoSuffix)), + strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.zip', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsWithSuffix)), + strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.tgz', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsWithSuffix)), + ]; + + // Fallbacks with anylibc suffix, for unified binaries compatible with both glibc and musl (Linux only) + if ($targetPlatform->operatingSystemFamily === OperatingSystemFamily::Linux) { + $names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.zip', $name, $version, $phpVer, $arch, $os, $debug, $tsNoSuffix)); + $names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.tgz', $name, $version, $phpVer, $arch, $os, $debug, $tsNoSuffix)); + $names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.zip', $name, $version, $phpVer, $arch, $os, $debug, $tsWithSuffix)); + $names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.tgz', $name, $version, $phpVer, $arch, $os, $debug, $tsWithSuffix)); + } + + return array_values(array_unique($names)); } } diff --git a/test/unit/Downloading/DownloadUrlMethodTest.php b/test/unit/Downloading/DownloadUrlMethodTest.php index 442f4be1..8b1dc698 100644 --- a/test/unit/Downloading/DownloadUrlMethodTest.php +++ b/test/unit/Downloading/DownloadUrlMethodTest.php @@ -145,10 +145,15 @@ public function testPrePackagedBinaryDownloads(): void self::assertSame(DownloadUrlMethod::PrePackagedBinary, $downloadUrlMethod); + // TargetPlatform doesn't have the libc specified, so the assertion needs to be made + // against the test machine's libc + $libc = $targetPlatform->libcFlavour()->value; self::assertSame( [ - '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-x86_64-linux-' . $libc . '-debug-zts.zip', + 'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-zts.tgz', + 'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-zts.zip', + 'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-zts.tgz', ], $downloadUrlMethod->possibleAssetNames($package, $targetPlatform), ); @@ -221,12 +226,19 @@ public function testMultipleDownloadUrlMethods(): void $firstMethod = $downloadUrlMethods[0]; self::assertSame(DownloadUrlMethod::PrePackagedBinary, $firstMethod); + // TargetPlatform doesn't have the libc specified, so the assertion needs to be made + // against the test machine's libc + $libc = $targetPlatform->libcFlavour()->value; self::assertSame( [ - 'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug.zip', - '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-x86_64-linux-' . $libc . '-debug.zip', + 'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug.tgz', + 'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-nts.zip', + 'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-nts.tgz', + 'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug.zip', + 'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug.tgz', + 'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-nts.zip', + 'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-nts.tgz', ], $firstMethod->possibleAssetNames($package, $targetPlatform), ); diff --git a/test/unit/Platform/PrePackagedBinaryAssetNameTest.php b/test/unit/Platform/PrePackagedBinaryAssetNameTest.php index 66f70781..4110220a 100644 --- a/test/unit/Platform/PrePackagedBinaryAssetNameTest.php +++ b/test/unit/Platform/PrePackagedBinaryAssetNameTest.php @@ -46,6 +46,10 @@ public function testPackageNamesNts(): void 'php_foobar-1.2.3_php8.2-x86_64-linux-' . $libc->value . '.tgz', 'php_foobar-1.2.3_php8.2-x86_64-linux-' . $libc->value . '-nts.zip', 'php_foobar-1.2.3_php8.2-x86_64-linux-' . $libc->value . '-nts.tgz', + 'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc.zip', + 'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc.tgz', + 'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc-nts.zip', + 'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc-nts.tgz', ], PrePackagedBinaryAssetName::packageNames( $targetPlatform, @@ -83,6 +87,8 @@ public function testPackageNamesZts(): void [ 'php_foobar-1.2.3_php8.3-x86_64-linux-' . $libc->value . '-zts.zip', 'php_foobar-1.2.3_php8.3-x86_64-linux-' . $libc->value . '-zts.tgz', + 'php_foobar-1.2.3_php8.3-x86_64-linux-anylibc-zts.zip', + 'php_foobar-1.2.3_php8.3-x86_64-linux-anylibc-zts.tgz', ], PrePackagedBinaryAssetName::packageNames( $targetPlatform,