@@ -8,6 +8,7 @@ import { addShExt, addShRelativePrefix } from "patha"
88import { installAptPack } from "setup-apt"
99import which from "which"
1010import { rcOptions } from "../cli-options.js"
11+ import { setupGit } from "../git/git.js"
1112import { arm64 } from "../utils/env/arch.js"
1213import { hasDnf } from "../utils/env/hasDnf.js"
1314import { isArch } from "../utils/env/isArch.js"
@@ -19,74 +20,77 @@ import { setupPacmanPack } from "../utils/setup/setupPacmanPack.js"
1920let hasVCPKG = false
2021
2122export async function setupVcpkg ( version : string , setupDir : string , arch : string ) : Promise < InstallationInfo > {
22- if ( ! hasVCPKG || which . sync ( "vcpkg" , { nothrow : true } ) === null ) {
23- if ( process . platform === "linux" ) {
24- // vcpkg download and extraction dependencies
25- if ( isArch ( ) ) {
26- await Promise . all ( [
27- setupPacmanPack ( "curl" ) ,
28- setupPacmanPack ( "zip" ) ,
29- setupPacmanPack ( "unzip" ) ,
30- setupPacmanPack ( "tar" ) ,
31- setupPacmanPack ( "git" ) ,
32- setupPacmanPack ( "pkg-config" ) ,
33- ] )
34- } else if ( hasDnf ( ) ) {
35- await setupDnfPack ( [
36- { name : "curl" } ,
37- { name : "zip" } ,
38- { name : "unzip" } ,
39- { name : "tar" } ,
40- { name : "git" } ,
41- { name : "pkg-config" } ,
42- ] )
43- } else if ( isUbuntu ( ) ) {
44- await installAptPack ( [
45- { name : "curl" } ,
46- { name : "zip" } ,
47- { name : "unzip" } ,
48- { name : "tar" } ,
49- { name : "git" } ,
50- { name : "pkg-config" } ,
51- ] )
52- }
53- }
23+ const vcpkg = await which ( "vcpkg" , { nothrow : true } )
5424
55- // clone if not already exists
56- if ( ! ( await pathExists ( join ( setupDir , addShExt ( "bootstrap-vcpkg" , ".bat" ) ) ) ) ) {
57- execaSync ( "git" , [ "clone" , "https://github.com/microsoft/vcpkg" ] , { cwd : dirname ( setupDir ) , stdio : "inherit" } )
58- } else {
59- notice ( `Vcpkg folder already exists at ${ setupDir } . Skipping the clone` )
60- }
25+ if ( hasVCPKG && vcpkg !== null ) {
26+ return { binDir : dirname ( vcpkg ) }
27+ }
6128
62- // if version specified, checkout the version
63- if ( version !== "" && version !== "true" ) {
64- info ( `Checking out vcpkg version ${ version } ` )
65- execaSync ( "git" , [ "checkout" , version ] , {
66- cwd : setupDir ,
67- stdio : "inherit" ,
68- } )
69- }
29+ // vcpkg dependencies
30+ await setupGit ( "" , setupDir , arch )
7031
71- // Add VCPKG_FORCE_SYSTEM_BINARIES=1 for Linux arm64
72- if ( process . platform === "linux" && arch in arm64 ) {
73- await addEnv ( "VCPKG_FORCE_SYSTEM_BINARIES" , "1" )
32+ if ( process . platform === "linux" ) {
33+ if ( isArch ( ) ) {
34+ await Promise . all ( [
35+ setupPacmanPack ( "curl" ) ,
36+ setupPacmanPack ( "zip" ) ,
37+ setupPacmanPack ( "unzip" ) ,
38+ setupPacmanPack ( "tar" ) ,
39+ setupPacmanPack ( "pkg-config" ) ,
40+ ] )
41+ } else if ( hasDnf ( ) ) {
42+ await setupDnfPack ( [
43+ { name : "curl" } ,
44+ { name : "zip" } ,
45+ { name : "unzip" } ,
46+ { name : "tar" } ,
47+ { name : "pkg-config" } ,
48+ ] )
49+ } else if ( isUbuntu ( ) ) {
50+ await installAptPack ( [
51+ { name : "curl" } ,
52+ { name : "zip" } ,
53+ { name : "unzip" } ,
54+ { name : "tar" } ,
55+ { name : "pkg-config" } ,
56+ ] )
7457 }
58+ }
59+
60+ // clone if not already exists
61+ if ( ! ( await pathExists ( join ( setupDir , addShExt ( "bootstrap-vcpkg" , ".bat" ) ) ) ) ) {
62+ execaSync ( "git" , [ "clone" , "https://github.com/microsoft/vcpkg" ] , { cwd : dirname ( setupDir ) , stdio : "inherit" } )
63+ } else {
64+ notice ( `Vcpkg folder already exists at ${ setupDir } . Skipping the clone` )
65+ }
7566
76- // bootstrap vcpkg
77- execaSync ( addShExt ( addShRelativePrefix ( "bootstrap-vcpkg" ) , ".bat" ) , {
67+ // if version specified, checkout the version
68+ if ( version !== "" && version !== "true" ) {
69+ info ( `Checking out vcpkg version ${ version } ` )
70+ execaSync ( "git" , [ "checkout" , version ] , {
7871 cwd : setupDir ,
79- shell : true ,
8072 stdio : "inherit" ,
8173 } )
74+ }
8275
83- await grantUserWriteAccess ( setupDir )
84-
85- await addPath ( setupDir , rcOptions )
86- // eslint-disable-next-line require-atomic-updates
87- hasVCPKG = true
88- return { binDir : setupDir }
76+ // Add VCPKG_FORCE_SYSTEM_BINARIES=1 for Linux arm64
77+ if ( process . platform === "linux" && arch in arm64 ) {
78+ await addEnv ( "VCPKG_FORCE_SYSTEM_BINARIES" , "1" )
8979 }
9080
91- return { binDir : dirname ( which . sync ( "vcpkg" ) ) }
81+ // bootstrap vcpkg
82+ execaSync ( addShExt ( addShRelativePrefix ( "bootstrap-vcpkg" ) , ".bat" ) , {
83+ cwd : setupDir ,
84+ shell : true ,
85+ stdio : "inherit" ,
86+ } )
87+
88+ await grantUserWriteAccess ( setupDir )
89+
90+ await addPath ( setupDir , rcOptions )
91+
92+ // eslint-disable-next-line require-atomic-updates
93+ hasVCPKG = true
94+
95+ return { binDir : setupDir }
9296}
0 commit comments