Skip to content

Commit

Permalink
Merge pull request #16 from ralauge-aramis/15-download-right-biomejs-…
Browse files Browse the repository at this point in the history
…when-libc-is-musl
  • Loading branch information
Kocal committed Sep 25, 2024
2 parents d675081 + 43de09a commit 78de28a
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/BiomeJsBinary.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ public static function getBinaryName(): string
default => throw new \Exception(sprintf('No matching machine found for Darwin platform (Machine: %s).', $machine)),
},
str_contains($os, 'linux') => match ($machine) {
'arm64', 'aarch64' => 'biome-linux-arm64',
'x86_64' => 'biome-linux-x64',
'arm64', 'aarch64' => self::isMusl() ? 'biome-linux-arm64-musl' : 'biome-linux-arm64',
'x86_64' => self::isMusl() ? 'biome-linux-x64-musl' : 'biome-linux-x64',
default => throw new \Exception(sprintf('No matching machine found for Linux platform (Machine: %s).', $machine)),
},
str_contains($os, 'win') => match ($machine) {
Expand All @@ -173,4 +173,26 @@ public static function getBinaryName(): string
default => throw new \Exception(sprintf('Unknown platform or architecture (OS: %s, Machine: %s).', $os, $machine)),
};
}

/**
* Whether the current PHP environment is using musl libc.
* This is used to determine the correct Biome.js binary to download.
*/
private static function isMusl(): bool
{
static $isMusl = null;

if (null !== $isMusl) {
return $isMusl;
}

if (!\function_exists('phpinfo')) {
return $isMusl = false;
}

ob_start();
phpinfo(\INFO_GENERAL);

return $isMusl = 1 === preg_match('/--build=.*?-linux-musl/', ob_get_clean() ?: '');
}
}

0 comments on commit 78de28a

Please # to comment.