|
1 | 1 | import { join, addExeExt } from "patha" |
2 | 2 | import { delimiter } from "path" |
3 | | -import semverLte from "semver/functions/lte" |
4 | 3 | import semverMajor from "semver/functions/major" |
5 | | -import { isUrlOnline } from "is-url-online" |
6 | | -import { InstallationInfo, PackageInfo, setupBin } from "../utils/setup/setupBin" |
7 | | -import { extractExe, extractTarByExe } from "../utils/setup/extract" |
8 | | -import { |
9 | | - getSpecificVersionAndUrl, |
10 | | - getSpecificVersions, |
11 | | - getVersions, |
12 | | - semverCoerceIfInvalid, |
13 | | -} from "../utils/setup/version" |
| 4 | +import { InstallationInfo, setupBin } from "../utils/setup/setupBin" |
| 5 | +import { semverCoerceIfInvalid } from "../utils/setup/version" |
14 | 6 | import { setupMacOSSDK } from "../macos-sdk/macos-sdk" |
15 | 7 | import { addEnv } from "../utils/env/addEnv" |
16 | | -import { setOutput } from "@actions/core" |
17 | 8 | import { setupAptPack, updateAptAlternatives } from "../utils/setup/setupAptPack" |
18 | 9 | import { info, warning } from "ci-log" |
19 | 10 | import { existsSync } from "fs" |
20 | 11 | import ciDetect from "@npmcli/ci-detect" |
21 | 12 | import { setupGcc } from "../gcc/gcc" |
22 | 13 | import { getVersion } from "../versions/versions" |
23 | 14 | import { isUbuntu } from "../utils/env/isUbuntu" |
24 | | - |
25 | | -//================================================ |
26 | | -// Version |
27 | | -//================================================ |
28 | | - |
29 | | -/** The specific and minimum LLVM versions supported by this action. */ |
30 | | -export const VERSIONS: Set<string> = getVersions([ |
31 | | - "3.5.0", |
32 | | - "3.5.1", |
33 | | - "3.5.2", |
34 | | - "3.6.0", |
35 | | - "3.6.1", |
36 | | - "3.6.2", |
37 | | - "3.7.0", |
38 | | - "3.7.1", |
39 | | - "3.8.0", |
40 | | - "3.8.1", |
41 | | - "3.9.0", |
42 | | - "3.9.1", |
43 | | - "4.0.0", |
44 | | - "4.0.1", |
45 | | - "5.0.0", |
46 | | - "5.0.1", |
47 | | - "5.0.2", |
48 | | - "6.0.0", |
49 | | - "6.0.1", |
50 | | - "7.0.0", |
51 | | - "7.0.1", |
52 | | - "7.1.0", |
53 | | - "8.0.0", |
54 | | - "8.0.1", |
55 | | - "9.0.0", |
56 | | - "9.0.1", |
57 | | - "10.0.0", |
58 | | - "10.0.1", |
59 | | - "11.0.0", |
60 | | - "11.0.1", |
61 | | - "11.1.0", |
62 | | - "12.0.0", |
63 | | - "12.0.1", |
64 | | - "13.0.0", |
65 | | - "13.0.1", |
66 | | - "14.0.0", |
67 | | - "14.0.1", |
68 | | - "14.0.2", |
69 | | - "14.0.3", |
70 | | - "14.0.4", |
71 | | - "14.0.5", |
72 | | - "14.0.6", |
73 | | - "15.0.0", |
74 | | - "15.0.1", |
75 | | - "15.0.2", |
76 | | -]) |
77 | | - |
78 | | -//================================================ |
79 | | -// URL |
80 | | -//================================================ |
81 | | - |
82 | | -/** Gets a LLVM download URL for GitHub. */ |
83 | | -function getGitHubUrl(version: string, prefix: string, suffix: string): string { |
84 | | - const file = `${prefix}${version}${suffix}` |
85 | | - return `https://github.com/llvm/llvm-project/releases/download/llvmorg-${version}/${file}` |
86 | | -} |
87 | | - |
88 | | -/** Gets a LLVM download URL for https://releases.llvm.org. */ |
89 | | -function getReleaseUrl(version: string, prefix: string, suffix: string): string { |
90 | | - const file = `${prefix}${version}${suffix}` |
91 | | - return `https://releases.llvm.org/${version}/${file}` |
92 | | -} |
93 | | - |
94 | | -/** The LLVM versions that were never released for the Darwin platform. */ |
95 | | -const DARWIN_MISSING: Set<string> = new Set([ |
96 | | - "3.5.1", |
97 | | - "3.6.1", |
98 | | - "3.6.2", |
99 | | - "3.7.1", |
100 | | - "3.8.1", |
101 | | - "3.9.1", |
102 | | - "6.0.1", |
103 | | - "7.0.1", |
104 | | - "7.1.0", |
105 | | - "8.0.1", |
106 | | - "11.0.1", |
107 | | - "11.1.0", |
108 | | - "12.0.1", |
109 | | -]) |
110 | | - |
111 | | -/** Gets an LLVM download URL for the Darwin platform. */ |
112 | | -function getDarwinUrl(version: string): string | null { |
113 | | - if (DARWIN_MISSING.has(version)) { |
114 | | - return null |
115 | | - } |
116 | | - |
117 | | - const darwin = version === "9.0.0" ? "-darwin-apple" : "-apple-darwin" |
118 | | - const prefix = "clang+llvm-" |
119 | | - const suffix = `-x86_64${darwin}.tar.xz` |
120 | | - if (semverLte(version, "9.0.1")) { |
121 | | - return getReleaseUrl(version, prefix, suffix) |
122 | | - } else { |
123 | | - return getGitHubUrl(version, prefix, suffix) |
124 | | - } |
125 | | -} |
126 | | - |
127 | | -/** |
128 | | - * The LLVM versions that should use the last RC version instead of the release version for the Linux (Ubuntu) platform. |
129 | | - * This is useful when there were binaries released for the Linux (Ubuntu) platform for the last RC version but not for |
130 | | - * the actual release version. |
131 | | - */ |
132 | | -const UBUNTU_RC: Map<string, string> = new Map() |
133 | | - |
134 | | -/** |
135 | | - * The (latest) Ubuntu versions for each LLVM version. |
136 | | - * |
137 | | - * https://github.com/llvm/llvm-project/releases/tag/llvmorg-14.0.1 or https://releases.llvm.org/14.0.1 |
138 | | - */ |
139 | | -// TODO change based on ubuntu version |
140 | | -const UBUNTU_SUFFIX_MAP: { [key: string]: string } = { |
141 | | - "3.5.0": "-ubuntu-14.04", |
142 | | - "3.5.1": "", |
143 | | - "3.5.2": "-ubuntu-14.04", |
144 | | - "3.6.0": "-ubuntu-14.04", |
145 | | - "3.6.1": "-ubuntu-14.04", |
146 | | - "3.6.2": "-ubuntu-14.04", |
147 | | - "3.7.0": "-ubuntu-14.04", |
148 | | - "3.7.1": "-ubuntu-14.04", |
149 | | - "3.8.0": "-ubuntu-16.04", |
150 | | - "3.8.1": "-ubuntu-16.04", |
151 | | - "3.9.0": "-ubuntu-16.04", |
152 | | - "3.9.1": "-ubuntu-16.04", |
153 | | - "4.0.0": "-ubuntu-16.04", |
154 | | - "5.0.0": "-ubuntu16.04", |
155 | | - "5.0.1": "-ubuntu-16.04", |
156 | | - "5.0.2": "-ubuntu-16.04", |
157 | | - "6.0.0": "-ubuntu-16.04", |
158 | | - "6.0.1": "-ubuntu-16.04", |
159 | | - "7.0.0": "-ubuntu-16.04", |
160 | | - "7.0.1": "-ubuntu-18.04", |
161 | | - "7.1.0": "-ubuntu-14.04", |
162 | | - "8.0.0": "-ubuntu-18.04", |
163 | | - "9.0.0": "-ubuntu-18.04", |
164 | | - "9.0.1": "-ubuntu-16.04", |
165 | | - "10.0.0": "-ubuntu-18.04", |
166 | | - "10.0.1": "-ubuntu-16.04", |
167 | | - "11.0.0": "-ubuntu-20.04", |
168 | | - "11.0.1": "-ubuntu-16.04", |
169 | | - "11.1.0": "-ubuntu-16.04", |
170 | | - "12.0.0": "-ubuntu-20.04", |
171 | | - "12.0.1": "-ubuntu-16.04", |
172 | | - "13.0.0": "-ubuntu-20.04", |
173 | | - "13.0.0-ubuntu-16.04": "-ubuntu-16.04", |
174 | | - "13.0.0-ubuntu-20.04": "-ubuntu-20.04", |
175 | | - "13.0.1": "-ubuntu-18.04", |
176 | | - "13.0.1-ubuntu-18.04": "-ubuntu-18.04", |
177 | | - "14.0.0": "-ubuntu-18.04", |
178 | | - // "14.0.1": "-ubuntu-18.04", // only available for powerpc64le |
179 | | - "15.0.2": "-rhel86", |
180 | | -} |
181 | | - |
182 | | -/** The latest supported LLVM version for the Linux (Ubuntu) platform. */ |
183 | | -const MAX_UBUNTU: string = "15.0.2" |
184 | | - |
185 | | -/** Gets an LLVM download URL for the Linux (Ubuntu) platform. */ |
186 | | -export function getLinuxUrl(versionGiven: string): string { |
187 | | - let version = versionGiven |
188 | | - |
189 | | - const rc = UBUNTU_RC.get(version) |
190 | | - if (rc !== undefined) { |
191 | | - version = rc |
192 | | - } |
193 | | - |
194 | | - let linuxVersion: string |
195 | | - // ubuntu-version is specified |
196 | | - if (version.includes("ubuntu")) { |
197 | | - const givenUbuntuVersion = version.replace(/-ubuntu-.*/, "") |
198 | | - if (!VERSIONS.has(givenUbuntuVersion)) { |
199 | | - throw new Error(`Unsupported Ubuntu version: ${givenUbuntuVersion}`) |
200 | | - } |
201 | | - linuxVersion = version.replace(givenUbuntuVersion, "") |
202 | | - version = getSpecificVersions(VERSIONS, givenUbuntuVersion)[0] |
203 | | - } else if (version !== "" && version in UBUNTU_SUFFIX_MAP) { |
204 | | - linuxVersion = UBUNTU_SUFFIX_MAP[version] |
205 | | - } else { |
206 | | - // default to the maximum version |
207 | | - linuxVersion = UBUNTU_SUFFIX_MAP[MAX_UBUNTU] |
208 | | - warning(`Falling back to LLVM version ${MAX_UBUNTU} ${linuxVersion} for the Ubuntu.`) |
209 | | - } |
210 | | - |
211 | | - const prefix = "clang+llvm-" |
212 | | - |
213 | | - let suffix: string |
214 | | - if (version === "5.0.0") { |
215 | | - suffix = `-linux-x86_64${linuxVersion}.tar.xz` |
216 | | - } else if (linuxVersion.includes("-rhel86")) { |
217 | | - suffix = `-x86_64-unknown-linux-gnu${linuxVersion}.tar.xz` |
218 | | - } else { |
219 | | - suffix = `-x86_64-linux-gnu${linuxVersion}.tar.xz` |
220 | | - } |
221 | | - |
222 | | - if (semverLte(version, "9.0.1")) { |
223 | | - return getReleaseUrl(version, prefix, suffix) |
224 | | - } else { |
225 | | - return getGitHubUrl(version, prefix, suffix) |
226 | | - } |
227 | | -} |
228 | | - |
229 | | -/** The LLVM versions that were never released for the Windows platform. */ |
230 | | -const WIN32_MISSING: Set<string> = new Set(["10.0.1"]) |
231 | | - |
232 | | -/** Gets an LLVM download URL for the Windows platform. */ |
233 | | -async function getWin32Url(version: string): Promise<string | null> { |
234 | | - if (WIN32_MISSING.has(version)) { |
235 | | - return null |
236 | | - } |
237 | | - |
238 | | - const prefix = "LLVM-" |
239 | | - const suffix = semverLte(version, "3.7.0") ? "-win32.exe" : "-win64.exe" |
240 | | - |
241 | | - const olderThan9_1 = semverLte(version, "9.0.1") |
242 | | - let url: string |
243 | | - let fallback = false |
244 | | - if (olderThan9_1) { |
245 | | - url = getReleaseUrl(version, prefix, suffix) |
246 | | - if (!(await isUrlOnline(url))) { |
247 | | - fallback = true // fallback to github |
248 | | - } |
249 | | - } |
250 | | - if (fallback || !olderThan9_1) { |
251 | | - url = getGitHubUrl(version, prefix, suffix) |
252 | | - } |
253 | | - |
254 | | - return url! |
255 | | -} |
256 | | - |
257 | | -/** Gets an LLVM download URL. */ |
258 | | -export function getUrl(platform: string, version: string): string | null | Promise<string | null> { |
259 | | - switch (platform) { |
260 | | - case "darwin": |
261 | | - return getDarwinUrl(version) |
262 | | - case "linux": |
263 | | - return getLinuxUrl(version) |
264 | | - case "win32": |
265 | | - return getWin32Url(version) |
266 | | - default: |
267 | | - return null |
268 | | - } |
269 | | -} |
270 | | - |
271 | | -//================================================ |
272 | | -// Exports |
273 | | -//================================================ |
274 | | -// eslint-disable-next-line @typescript-eslint/no-unused-vars |
275 | | -async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform, _arch: string): Promise<PackageInfo> { |
276 | | - const [specificVersion, url] = await getSpecificVersionAndUrl(VERSIONS, platform, version, getUrl) |
277 | | - setOutput("version", specificVersion) |
278 | | - return { |
279 | | - url, |
280 | | - extractedFolderName: "", |
281 | | - binRelativeDir: "bin", |
282 | | - binFileName: addExeExt("clang"), |
283 | | - extractFunction: |
284 | | - platform === "win32" |
285 | | - ? extractExe |
286 | | - : (file: string, dest: string) => { |
287 | | - return extractTarByExe(file, dest, ["--strip-components=1"]) |
288 | | - }, |
289 | | - } |
290 | | -} |
| 15 | +import { getLLVMPackageInfo } from "./llvm_url" |
291 | 16 |
|
292 | 17 | export async function setupLLVM(version: string, setupDir: string, arch: string): Promise<InstallationInfo> { |
293 | 18 | const installationInfo = await setupLLVMWithoutActivation(version, setupDir, arch) |
|
0 commit comments