Skip to content

Commit 02e42dc

Browse files
committed
Allow distribution of musl+glibc binaries
Search for binaries with the anylibc suffix as a fallback candidate. This allows shipping binaries that work both on glibc and musl without copying the same binary with two separate names.
1 parent 2f8517f commit 02e42dc

3 files changed

Lines changed: 39 additions & 46 deletions

File tree

src/Platform/PrePackagedBinaryAssetName.php

Lines changed: 27 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,32 @@ private function __construct()
2121
/** @return non-empty-list<non-empty-string> */
2222
public static function packageNames(TargetPlatform $targetPlatform, Package $package): array
2323
{
24-
return array_values(array_unique([
25-
strtolower(sprintf(
26-
'php_%s-%s_php%s-%s-%s-%s%s%s.zip',
27-
$package->extensionName()->name(),
28-
$package->version(),
29-
$targetPlatform->phpBinaryPath->majorMinorVersion(),
30-
$targetPlatform->architecture->name,
31-
$targetPlatform->operatingSystemFamily->value,
32-
$targetPlatform->libcFlavour()->value,
33-
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
34-
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '',
35-
)),
36-
strtolower(sprintf(
37-
'php_%s-%s_php%s-%s-%s-%s%s%s.tgz',
38-
$package->extensionName()->name(),
39-
$package->version(),
40-
$targetPlatform->phpBinaryPath->majorMinorVersion(),
41-
$targetPlatform->architecture->name,
42-
$targetPlatform->operatingSystemFamily->value,
43-
$targetPlatform->libcFlavour()->value,
44-
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
45-
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '',
46-
)),
47-
strtolower(sprintf(
48-
'php_%s-%s_php%s-%s-%s-%s%s%s.zip',
49-
$package->extensionName()->name(),
50-
$package->version(),
51-
$targetPlatform->phpBinaryPath->majorMinorVersion(),
52-
$targetPlatform->architecture->name,
53-
$targetPlatform->operatingSystemFamily->value,
54-
$targetPlatform->libcFlavour()->value,
55-
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
56-
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts',
57-
)),
58-
strtolower(sprintf(
59-
'php_%s-%s_php%s-%s-%s-%s%s%s.tgz',
60-
$package->extensionName()->name(),
61-
$package->version(),
62-
$targetPlatform->phpBinaryPath->majorMinorVersion(),
63-
$targetPlatform->architecture->name,
64-
$targetPlatform->operatingSystemFamily->value,
65-
$targetPlatform->libcFlavour()->value,
66-
$targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '',
67-
$targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts',
68-
)),
69-
]));
24+
$debug = $targetPlatform->phpBinaryPath->debugMode() === DebugBuild::Debug ? '-debug' : '';
25+
$tsNoSuffix = $targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '';
26+
$tsWithSuffix = $targetPlatform->threadSafety === ThreadSafetyMode::ThreadSafe ? '-zts' : '-nts';
27+
$libc = $targetPlatform->libcFlavour()->value;
28+
29+
$name = $package->extensionName()->name();
30+
$version = $package->version();
31+
$phpVer = $targetPlatform->phpBinaryPath->majorMinorVersion();
32+
$arch = $targetPlatform->architecture->name;
33+
$os = $targetPlatform->operatingSystemFamily->value;
34+
35+
$names = [
36+
strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.zip', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsNoSuffix)),
37+
strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.tgz', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsNoSuffix)),
38+
strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.zip', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsWithSuffix)),
39+
strtolower(sprintf('php_%s-%s_php%s-%s-%s-%s%s%s.tgz', $name, $version, $phpVer, $arch, $os, $libc, $debug, $tsWithSuffix)),
40+
];
41+
42+
// Fallbacks with anylibc suffix, for unified binaries compatible with both glibc and musl (Linux only)
43+
if ($targetPlatform->operatingSystemFamily === OperatingSystemFamily::Linux) {
44+
$names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.zip', $name, $version, $phpVer, $arch, $os, $debug, $tsNoSuffix));
45+
$names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.tgz', $name, $version, $phpVer, $arch, $os, $debug, $tsNoSuffix));
46+
$names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.zip', $name, $version, $phpVer, $arch, $os, $debug, $tsWithSuffix));
47+
$names[] = strtolower(sprintf('php_%s-%s_php%s-%s-%s-anylibc%s%s.tgz', $name, $version, $phpVer, $arch, $os, $debug, $tsWithSuffix));
48+
}
49+
50+
return array_values(array_unique($names));
7051
}
7152
}

test/unit/Downloading/DownloadUrlMethodTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ public function testPrePackagedBinaryDownloads(): void
149149
[
150150
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-zts.zip',
151151
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-zts.tgz',
152+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-zts.zip',
153+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-zts.tgz',
152154
],
153155
$downloadUrlMethod->possibleAssetNames($package, $targetPlatform),
154156
);
@@ -227,6 +229,10 @@ public function testMultipleDownloadUrlMethods(): void
227229
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug.tgz',
228230
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-nts.zip',
229231
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-nts.tgz',
232+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug.zip',
233+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug.tgz',
234+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-nts.zip',
235+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-nts.tgz',
230236
],
231237
$firstMethod->possibleAssetNames($package, $targetPlatform),
232238
);

test/unit/Platform/PrePackagedBinaryAssetNameTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ public function testPackageNamesNts(): void
4646
'php_foobar-1.2.3_php8.2-x86_64-linux-' . $libc->value . '.tgz',
4747
'php_foobar-1.2.3_php8.2-x86_64-linux-' . $libc->value . '-nts.zip',
4848
'php_foobar-1.2.3_php8.2-x86_64-linux-' . $libc->value . '-nts.tgz',
49+
'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc.zip',
50+
'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc.tgz',
51+
'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc-nts.zip',
52+
'php_foobar-1.2.3_php8.2-x86_64-linux-anylibc-nts.tgz',
4953
],
5054
PrePackagedBinaryAssetName::packageNames(
5155
$targetPlatform,
@@ -83,6 +87,8 @@ public function testPackageNamesZts(): void
8387
[
8488
'php_foobar-1.2.3_php8.3-x86_64-linux-' . $libc->value . '-zts.zip',
8589
'php_foobar-1.2.3_php8.3-x86_64-linux-' . $libc->value . '-zts.tgz',
90+
'php_foobar-1.2.3_php8.3-x86_64-linux-anylibc-zts.zip',
91+
'php_foobar-1.2.3_php8.3-x86_64-linux-anylibc-zts.tgz',
8692
],
8793
PrePackagedBinaryAssetName::packageNames(
8894
$targetPlatform,

0 commit comments

Comments
 (0)