@@ -20,7 +20,6 @@ import { existsSync } from "fs"
2020import ciDetect from "@npmcli/ci-detect"
2121import { setupGcc } from "../gcc/gcc"
2222import { getVersion } from "../versions/versions"
23- import { isArch } from "../utils/env/isArch"
2423import { isUbuntu } from "../utils/env/isUbuntu"
2524
2625//================================================
@@ -291,31 +290,45 @@ async function getLLVMPackageInfo(version: string, platform: NodeJS.Platform, _a
291290}
292291
293292export async function setupLLVM ( version : string , setupDir : string , arch : string ) : Promise < InstallationInfo > {
294- const installationInfo = await _setupLLVM ( version , setupDir , arch )
293+ const installationInfo = await setupLLVMWithoutActivation ( version , setupDir , arch )
295294 await activateLLVM ( installationInfo . installDir ?? setupDir , version )
296295 return installationInfo
297296}
298297
299- let didInit = false
300- async function _setupLLVM ( version : string , setupDir : string , arch : string ) {
301- const installationInfo = await setupBin ( "llvm" , version , getLLVMPackageInfo , setupDir , arch )
302- if ( ! didInit ) {
303- if ( process . platform === "linux" ) {
304- // install llvm build dependencies
305- await setupGcc ( getVersion ( "gcc" , undefined ) , "" , arch ) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
306- if ( isArch ( ) ) {
307- // setupPacmanPack("ncurses")
308- // TODO: install libtinfo ?
309- } else if ( isUbuntu ( ) ) {
310- await setupAptPack ( "libtinfo-dev" )
311- }
312- }
298+ let installedDeps = false
299+
300+ async function setupLLVMWithoutActivation ( version : string , setupDir : string , arch : string ) {
301+ const installationInfoPromise = setupBin ( "llvm" , version , getLLVMPackageInfo , setupDir , arch )
302+
303+ let depsPromise : Promise < void >
304+ if ( ! installedDeps ) {
305+ depsPromise = setupLLVMDeps ( arch )
313306 // eslint-disable-next-line require-atomic-updates
314- didInit = true
307+ installedDeps = true
308+ } else {
309+ depsPromise = Promise . resolve ( )
315310 }
311+
312+ // install LLVM and its dependencies in parallel
313+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
314+ const [ installationInfo , _ ] = await Promise . all ( [ installationInfoPromise , depsPromise ] )
315+
316316 return installationInfo
317317}
318318
319+ async function setupLLVMDeps ( arch : string ) {
320+ if ( process . platform === "linux" ) {
321+ // install llvm build dependencies
322+ await setupGcc ( getVersion ( "gcc" , undefined ) , "" , arch ) // using llvm requires ld, an up to date libstdc++, etc. So, install gcc first
323+
324+ if ( isUbuntu ( ) ) {
325+ await setupAptPack ( "libtinfo-dev" )
326+ }
327+ // TODO: install libtinfo on other distros
328+ // setupPacmanPack("ncurses")
329+ }
330+ }
331+
319332export async function activateLLVM ( directory : string , versionGiven : string ) {
320333 const version = semverCoerceIfInvalid ( versionGiven )
321334
@@ -378,7 +391,7 @@ export function setupClangTools(version: string, setupDir: string, arch: string)
378391 if ( ciDetect ( ) === "github-actions" ) {
379392 addLLVMLoggingMatcher ( )
380393 }
381- return _setupLLVM ( version , setupDir , arch )
394+ return setupLLVMWithoutActivation ( version , setupDir , arch )
382395}
383396
384397function addLLVMLoggingMatcher ( ) {
0 commit comments