Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/linux/libcxx-fetcher.ts
3520 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
// Can be removed once https://github.com/electron/electron-rebuild/pull/703 is available.
7
8
import fs from 'fs';
9
import path from 'path';
10
import debug from 'debug';
11
import extract from 'extract-zip';
12
import { downloadArtifact } from '@electron/get';
13
14
const root = path.dirname(path.dirname(__dirname));
15
16
const d = debug('libcxx-fetcher');
17
18
export async function downloadLibcxxHeaders(outDir: string, electronVersion: string, lib_name: string): Promise<void> {
19
if (await fs.existsSync(path.resolve(outDir, 'include'))) {
20
return;
21
}
22
if (!await fs.existsSync(outDir)) {
23
await fs.mkdirSync(outDir, { recursive: true });
24
}
25
26
d(`downloading ${lib_name}_headers`);
27
const headers = await downloadArtifact({
28
version: electronVersion,
29
isGeneric: true,
30
artifactName: `${lib_name}_headers.zip`,
31
});
32
33
d(`unpacking ${lib_name}_headers from ${headers}`);
34
await extract(headers, { dir: outDir });
35
}
36
37
export async function downloadLibcxxObjects(outDir: string, electronVersion: string, targetArch: string = 'x64'): Promise<void> {
38
if (await fs.existsSync(path.resolve(outDir, 'libc++.a'))) {
39
return;
40
}
41
if (!await fs.existsSync(outDir)) {
42
await fs.mkdirSync(outDir, { recursive: true });
43
}
44
45
d(`downloading libcxx-objects-linux-${targetArch}`);
46
const objects = await downloadArtifact({
47
version: electronVersion,
48
platform: 'linux',
49
artifactName: 'libcxx-objects',
50
arch: targetArch,
51
});
52
53
d(`unpacking libcxx-objects from ${objects}`);
54
await extract(objects, { dir: outDir });
55
}
56
57
async function main(): Promise<void> {
58
const libcxxObjectsDirPath = process.env['VSCODE_LIBCXX_OBJECTS_DIR'];
59
const libcxxHeadersDownloadDir = process.env['VSCODE_LIBCXX_HEADERS_DIR'];
60
const libcxxabiHeadersDownloadDir = process.env['VSCODE_LIBCXXABI_HEADERS_DIR'];
61
const arch = process.env['VSCODE_ARCH'];
62
const packageJSON = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
63
const electronVersion = packageJSON.devDependencies.electron;
64
65
if (!libcxxObjectsDirPath || !libcxxHeadersDownloadDir || !libcxxabiHeadersDownloadDir) {
66
throw new Error('Required build env not set');
67
}
68
69
await downloadLibcxxObjects(libcxxObjectsDirPath, electronVersion, arch);
70
await downloadLibcxxHeaders(libcxxHeadersDownloadDir, electronVersion, 'libcxx');
71
await downloadLibcxxHeaders(libcxxabiHeadersDownloadDir, electronVersion, 'libcxxabi');
72
}
73
74
if (require.main === module) {
75
main().catch(err => {
76
console.error(err);
77
process.exit(1);
78
});
79
}
80
81