|
4 | 4 |
|
5 | 5 | namespace Package\Artifact; |
6 | 6 |
|
| 7 | +use StaticPHP\Artifact\Artifact; |
7 | 8 | use StaticPHP\Artifact\ArtifactDownloader; |
8 | 9 | use StaticPHP\Artifact\Downloader\DownloadResult; |
9 | 10 | use StaticPHP\Artifact\Downloader\Type\CheckUpdateResult; |
10 | | -use StaticPHP\Artifact\Downloader\Type\GitHubRelease; |
11 | 11 | use StaticPHP\Artifact\Downloader\Type\GitHubTokenSetupTrait; |
12 | 12 | use StaticPHP\Attribute\Artifact\CustomBinary; |
13 | 13 | use StaticPHP\Attribute\Artifact\CustomSource; |
@@ -39,15 +39,32 @@ public function downSource(ArtifactDownloader $downloader): DownloadResult |
39 | 39 | 'linux-x86_64', |
40 | 40 | 'linux-aarch64', |
41 | 41 | ])] |
42 | | - public function downBinary(ArtifactDownloader $downloader): DownloadResult |
| 42 | + public function downBinary(ArtifactDownloader $downloader, Artifact $artifact): DownloadResult |
43 | 43 | { |
44 | | - $asset = 'llvm-tools-' . SystemTarget::getTargetArch() . '-linux-musl-' . $this->clangVersion() . '.txz'; |
45 | | - return new GitHubRelease()->download('llvm-tools', [ |
46 | | - 'type' => 'ghrel', |
47 | | - 'repo' => 'static-php/hosted', |
48 | | - 'match' => preg_quote($asset, '|'), |
49 | | - 'extract' => '{pkg_root_path}/llvm-tools', |
50 | | - ], $downloader); |
| 44 | + // The tools run on the build host, so the host architecture selects the archive, not |
| 45 | + // SPC_TARGET; they are static musl executables and run on any Linux distribution. |
| 46 | + $clang = $this->clangVersion(); |
| 47 | + // Pre-built archives: llvm-tools-{host-arch}-linux-musl-{clang-version}.txz plus a .sha256 sidecar. |
| 48 | + $filename = 'llvm-tools-' . GNU_ARCH . "-linux-musl-{$clang}.txz"; |
| 49 | + $base_url = $artifact->getBinaryDownloadConfig()['base-url'] ?? null; |
| 50 | + if (!is_string($base_url) || $base_url === '') { |
| 51 | + throw new DownloaderException('llvm-tools: binary config for ' . SystemTarget::getCurrentPlatformString() . ' does not define a base-url'); |
| 52 | + } |
| 53 | + $url = $base_url . $filename; |
| 54 | + $path = DOWNLOAD_PATH . DIRECTORY_SEPARATOR . $filename; |
| 55 | + default_shell()->executeCurlDownload($url, $path, retries: $downloader->getRetry()); |
| 56 | + |
| 57 | + // Published next to the archive by the llvm-tools workflow of static-php/hosted. |
| 58 | + $checksum = default_shell()->executeCurl("{$url}.sha256", retries: $downloader->getRetry()); |
| 59 | + $expected = is_string($checksum) ? strtolower((string) strtok(trim($checksum), " \t")) : ''; |
| 60 | + if (preg_match('/^[0-9a-f]{64}$/', $expected) !== 1) { |
| 61 | + throw new DownloaderException("Cannot fetch the checksum of {$filename} from {$url}.sha256"); |
| 62 | + } |
| 63 | + if (($actual = hash_file('sha256', $path)) !== $expected) { |
| 64 | + unlink($path); |
| 65 | + throw new DownloaderException("Hash mismatch for downloaded {$filename}. Expected {$expected}, got {$actual}"); |
| 66 | + } |
| 67 | + return DownloadResult::archive($filename, ['url' => $url], extract: '{pkg_root_path}/llvm-tools', verified: true, version: $clang); |
51 | 68 | } |
52 | 69 |
|
53 | 70 | #[CustomSourceCheckUpdate('llvm-tools')] |
|
0 commit comments