Skip to content

Commit eab64e3

Browse files
committed
feat: install LLVM via brew on Mac if possible
1 parent 15f3a89 commit eab64e3

File tree

6 files changed

+40
-17
lines changed

6 files changed

+40
-17
lines changed

dist/legacy/setup-cpp.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/legacy/setup-cpp.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/modern/setup-cpp.mjs

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

dist/modern/setup-cpp.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/llvm/llvm.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,26 @@ import { quoteIfHasSpace } from "../utils/std/index.js"
1818
import { getVersion } from "../versions/versions.js"
1919
import { LLVMPackages, trySetupLLVMApt } from "./llvm_apt_installer.js"
2020
import { setupLLVMBin } from "./llvm_bin.js"
21+
import { trySetupLLVMBrew } from "./llvm_brew_installer.js"
2122
import { majorLLVMVersion } from "./utils.js"
2223

2324
const dirname = typeof __dirname === "string" ? __dirname : path.dirname(fileURLToPath(import.meta.url))
2425

2526
export async function setupLLVM(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
26-
const installationInfo = await setupLLVMWithoutActivation(version, setupDir, arch)
27-
await activateLLVM(installationInfo.installDir ?? setupDir, version)
28-
return installationInfo
29-
}
27+
const installationInfo = await setupLLVMOnly(version, setupDir, arch)
3028

31-
async function setupLLVMWithoutActivation_(version: string, setupDir: string, arch: string) {
32-
// install LLVM
33-
const [installationInfo, _1] = await Promise.all([
34-
setupLLVMOnly(version, setupDir, arch),
35-
addLLVMLoggingMatcher(),
36-
])
37-
38-
// install LLVM dependencies
29+
// install gcc for LLVM (for ld, libstdc++, etc.)
3930
await setupGccForLLVM(arch)
4031

32+
// add the logging matcher
33+
await addLLVMLoggingMatcher()
34+
35+
// activate LLVM in the end
36+
if (installationInfo.installDir !== undefined) {
37+
await activateLLVM(installationInfo.installDir, version)
38+
}
4139
return installationInfo
4240
}
43-
const setupLLVMWithoutActivation = memoize(setupLLVMWithoutActivation_, { promise: true })
4441

4542
async function setupLLVMOnly(
4643
version: string,
@@ -53,6 +50,11 @@ async function setupLLVMOnly(
5350
return aptInstallInfo
5451
}
5552

53+
const brewInstallInfo = await trySetupLLVMBrew(version, setupDir, arch)
54+
if (brewInstallInfo !== undefined) {
55+
return brewInstallInfo
56+
}
57+
5658
return setupLLVMBin(version, setupDir, arch)
5759
}
5860

src/llvm/llvm_brew_installer.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { warning } from "ci-log"
2+
import { installBrewPack } from "setup-brew"
3+
import { majorLLVMVersion } from "./utils.ts"
4+
5+
export function trySetupLLVMBrew(version: string, _setupDir: string, _arch: string) {
6+
if (process.platform !== "darwin") {
7+
return Promise.resolve(undefined)
8+
}
9+
10+
try {
11+
return setupLLVMBrew(version, _setupDir, _arch)
12+
} catch (err) {
13+
warning(`Failed to install llvm via brew: ${err}`)
14+
return undefined
15+
}
16+
}
17+
18+
export function setupLLVMBrew(version: string, _setupDir: string, _arch: string) {
19+
const majorVersion = majorLLVMVersion(version)
20+
return installBrewPack("llvm", `${majorVersion}`)
21+
}

0 commit comments

Comments
 (0)