Skip to content

Commit e534458

Browse files
committed
Refactor musl detection logic in TailwindBinary
1 parent 2d59fa8 commit e534458

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/TailwindBinary.php

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,27 @@ private static function getBinarySystem(string $version, string $platform): stri
195195

196196
// Detect MUSL only when version >= 4.0.0
197197
if ('linux' === $system && version_compare($version, '4.0.0', '>=')) {
198-
$isMusl = false;
199-
if (is_executable('/usr/bin/ldd') || is_executable('/bin/ldd')) {
200-
$ldd = shell_exec('ldd --version 2>&1');
201-
if (null !== $ldd && str_contains($ldd, 'musl')) {
202-
$isMusl = true;
203-
}
204-
}
205-
206-
return "{$system}-{$arch}".($isMusl ? '-musl' : '');
198+
return "{$system}-{$arch}".(self::isMusl() ? '-musl' : '');
207199
}
208200

209201
return "{$system}-{$arch}";
210202
}
203+
204+
private static function isMusl(): bool
205+
{
206+
static $isMusl = null;
207+
208+
if (null !== $isMusl) {
209+
return $isMusl;
210+
}
211+
212+
if (!\function_exists('phpinfo')) {
213+
return $isMusl = false;
214+
}
215+
216+
ob_start();
217+
phpinfo(\INFO_GENERAL);
218+
219+
return $isMusl = 1 === preg_match('/--build=.*?-linux-musl/', ob_get_clean() ?: '');
220+
}
211221
}

0 commit comments

Comments
 (0)