Skip to content

Commit 09b665b

Browse files
authored
Merge pull request #545 from cataphract/glibc+musl
Allow distribution of musl + glibc binaries
2 parents 2f8517f + 4690ae1 commit 09b665b

File tree

3 files changed

+51
-52
lines changed

3 files changed

+51
-52
lines changed

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: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,10 +145,15 @@ public function testPrePackagedBinaryDownloads(): void
145145

146146
self::assertSame(DownloadUrlMethod::PrePackagedBinary, $downloadUrlMethod);
147147

148+
// TargetPlatform doesn't have the libc specified, so the assertion needs to be made
149+
// against the test machine's libc
150+
$libc = $targetPlatform->libcFlavour()->value;
148151
self::assertSame(
149152
[
150-
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-zts.zip',
151-
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-zts.tgz',
153+
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-zts.zip',
154+
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-zts.tgz',
155+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-zts.zip',
156+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-zts.tgz',
152157
],
153158
$downloadUrlMethod->possibleAssetNames($package, $targetPlatform),
154159
);
@@ -221,12 +226,19 @@ public function testMultipleDownloadUrlMethods(): void
221226

222227
$firstMethod = $downloadUrlMethods[0];
223228
self::assertSame(DownloadUrlMethod::PrePackagedBinary, $firstMethod);
229+
// TargetPlatform doesn't have the libc specified, so the assertion needs to be made
230+
// against the test machine's libc
231+
$libc = $targetPlatform->libcFlavour()->value;
224232
self::assertSame(
225233
[
226-
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug.zip',
227-
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug.tgz',
228-
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-nts.zip',
229-
'php_bar-1.2.3_php8.3-x86_64-linux-glibc-debug-nts.tgz',
234+
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug.zip',
235+
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug.tgz',
236+
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-nts.zip',
237+
'php_bar-1.2.3_php8.3-x86_64-linux-' . $libc . '-debug-nts.tgz',
238+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug.zip',
239+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug.tgz',
240+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-nts.zip',
241+
'php_bar-1.2.3_php8.3-x86_64-linux-anylibc-debug-nts.tgz',
230242
],
231243
$firstMethod->possibleAssetNames($package, $targetPlatform),
232244
);

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)