-
-
Notifications
You must be signed in to change notification settings - Fork 133
Expand file tree
/
Copy pathvcpkg-setup.js
More file actions
85 lines (73 loc) · 2.57 KB
/
vcpkg-setup.js
File metadata and controls
85 lines (73 loc) · 2.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// this should not use any third party dependencies! Only native Node.js modules!
const { execSync: exec } = require('child_process')
const fs = require('fs')
const path = require('path')
const { triplet, moduleRoot, vcpkgRoot } = require('./vcpkg-common')
const modulePackageJson = require('../package.json')
async function setupVcpkg() {
try {
let vcpkgExe
// Check for global vcpkg
if (process.env.VCPKG_ROOT) {
vcpkgExe = path.join(process.env.VCPKG_ROOT, 'vcpkg.exe')
if (!fs.existsSync(vcpkgExe)) {
console.error('VCPKG_ROOT set but vcpkg.exe not found')
process.exit(1)
}
console.log(`Using global vcpkg at ${process.env.VCPKG_ROOT}`)
} else {
// Bootstrap local vcpkg
if (!fs.existsSync(vcpkgRoot)) {
console.log('Cloning vcpkg locally...')
exec(
`git clone https://github.com/microsoft/vcpkg.git "${vcpkgRoot}"`,
{
cwd: path.dirname(vcpkgRoot),
maxBuffer: 10 * 1024 * 1024,
stdio: 'inherit',
},
)
} else {
console.log(`Using local vcpkg at ${vcpkgRoot}`)
}
vcpkgExe = path.join(vcpkgRoot, 'vcpkg.exe')
if (!fs.existsSync(vcpkgExe)) {
console.log('Bootstrapping vcpkg...')
exec(`"${path.join(vcpkgRoot, 'bootstrap-vcpkg.bat')}"`, {
cwd: vcpkgRoot,
maxBuffer: 10 * 1024 * 1024,
stdio: 'inherit',
})
}
}
await createVcpkgJson()
// Install dependencies
console.log(`Installing curl with ${triplet}...`)
const installCmd = `"${vcpkgExe}" install --triplet ${triplet}`
exec(installCmd, {
cwd: moduleRoot,
maxBuffer: 20 * 1024 * 1024,
stdio: 'inherit',
})
const installedRoot = path.join(moduleRoot, 'vcpkg_installed', triplet)
console.log(`✓ vcpkg setup complete`)
console.log(` Installed to: ${installedRoot}`)
} catch (error) {
console.error('vcpkg setup failed:', error.message)
if (error.stdout) console.error('stdout:', error.stdout)
if (error.stderr) console.error('stderr:', error.stderr)
process.exit(1)
}
}
async function createVcpkgJson() {
const vcpkgJsonTemplate = fs.readFileSync(
path.join(moduleRoot, 'vcpkg.template.json'),
'utf8',
)
const nodeOpenSSLVersion = process.versions.openssl.replace('+quic', '')
const vcpkgJson = vcpkgJsonTemplate
.replace('$$OPENSSL_VERSION$$', nodeOpenSSLVersion)
.replace('$$NODE_LIBCURL_VERSION$$', modulePackageJson.version)
fs.writeFileSync(path.join(moduleRoot, 'vcpkg.json'), vcpkgJson)
}
setupVcpkg()