feat: install LLVM via brew on Mac if possible

This commit is contained in:
Amin Yahyaabadi 2025-03-09 15:15:31 -07:00
parent 15f3a89bc3
commit eab64e395d
6 changed files with 40 additions and 17 deletions

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -18,29 +18,26 @@ import { quoteIfHasSpace } from "../utils/std/index.js"
import { getVersion } from "../versions/versions.js"
import { LLVMPackages, trySetupLLVMApt } from "./llvm_apt_installer.js"
import { setupLLVMBin } from "./llvm_bin.js"
import { trySetupLLVMBrew } from "./llvm_brew_installer.js"
import { majorLLVMVersion } from "./utils.js"
const dirname = typeof __dirname === "string" ? __dirname : path.dirname(fileURLToPath(import.meta.url))
export async function setupLLVM(version: string, setupDir: string, arch: string): Promise<InstallationInfo> {
const installationInfo = await setupLLVMWithoutActivation(version, setupDir, arch)
await activateLLVM(installationInfo.installDir ?? setupDir, version)
return installationInfo
}
const installationInfo = await setupLLVMOnly(version, setupDir, arch)
async function setupLLVMWithoutActivation_(version: string, setupDir: string, arch: string) {
// install LLVM
const [installationInfo, _1] = await Promise.all([
setupLLVMOnly(version, setupDir, arch),
addLLVMLoggingMatcher(),
])
// install LLVM dependencies
// install gcc for LLVM (for ld, libstdc++, etc.)
await setupGccForLLVM(arch)
// add the logging matcher
await addLLVMLoggingMatcher()
// activate LLVM in the end
if (installationInfo.installDir !== undefined) {
await activateLLVM(installationInfo.installDir, version)
}
return installationInfo
}
const setupLLVMWithoutActivation = memoize(setupLLVMWithoutActivation_, { promise: true })
async function setupLLVMOnly(
version: string,
@ -53,6 +50,11 @@ async function setupLLVMOnly(
return aptInstallInfo
}
const brewInstallInfo = await trySetupLLVMBrew(version, setupDir, arch)
if (brewInstallInfo !== undefined) {
return brewInstallInfo
}
return setupLLVMBin(version, setupDir, arch)
}

View File

@ -0,0 +1,21 @@
import { warning } from "ci-log"
import { installBrewPack } from "setup-brew"
import { majorLLVMVersion } from "./utils.ts"
export function trySetupLLVMBrew(version: string, _setupDir: string, _arch: string) {
if (process.platform !== "darwin") {
return Promise.resolve(undefined)
}
try {
return setupLLVMBrew(version, _setupDir, _arch)
} catch (err) {
warning(`Failed to install llvm via brew: ${err}`)
return undefined
}
}
export function setupLLVMBrew(version: string, _setupDir: string, _arch: string) {
const majorVersion = majorLLVMVersion(version)
return installBrewPack("llvm", `${majorVersion}`)
}