Skip to content

Commit

Permalink
fix: use clang and libcxx from chromium
Browse files Browse the repository at this point in the history
  • Loading branch information
deepak1556 committed Aug 5, 2021
1 parent 808f222 commit ee4aaaa
Show file tree
Hide file tree
Showing 8 changed files with 489 additions and 15 deletions.
22 changes: 20 additions & 2 deletions build/azure-pipelines/linux/product-build-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,32 @@ steps:
condition: and(succeeded(), ne(variables.NODE_MODULES_RESTORED, 'true'), eq(variables['ENABLE_TERRAPIN'], 'true'))
displayName: Switch to Terrapin packages
- script: |
set -e
yarn --cwd build
yarn --cwd build compile
displayName: Compile build tools
- script: |
set -e
export npm_config_arch=$(NPM_ARCH)
export npm_config_build_from_source=true
if [ -z "$CC" ] || [ -z "$CXX" ]; then
export CC=$(which gcc-5)
export CXX=$(which g++-5)
# Download clang based on chromium revision used by vscode
curl -s https://raw.githubusercontent.com/chromium/chromium/91.0.4472.124/tools/clang/scripts/update.py | python - --output-dir=$PWD/.build/CR_Clang --host-os=linux
# Download libcxx headers and objects from upstream electron releases
DEBUG=libcxx-fetcher \
VSCODE_LIBCXX_OBJECTS_DIR=$PWD/.build/libcxx-objects \
VSCODE_LIBCXX_HEADERS_DIR=$PWD/.build/libcxx_headers \
VSCODE_LIBCXXABI_HEADERS_DIR=$PWD/.build/libcxxabi_headers \
VSCODE_ARCH="$(NPM_ARCH)" \
node build/linux/libcxx-fetcher.js
# Set compiler toolchain
export CC=$PWD/.build/CR_Clang/bin/clang
export CXX=$PWD/.build/CR_Clang/bin/clang++
export CXXFLAGS="-nostdinc++ -D_LIBCPP_HAS_NO_VENDOR_AVAILABILITY_ANNOTATIONS -isystem$PWD/.build/libcxx_headers/include -isystem$PWD/.build/libcxxabi_headers/include -fPIC"
export LDFLAGS="-stdlib=libc++ -fuse-ld=lld -L$PWD/.build/libcxx-objects -lc++abi"
fi
if [ "$VSCODE_ARCH" == "x64" ]; then
Expand Down
3 changes: 2 additions & 1 deletion build/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ module.exports.indentationFilter = [
'!src/typings/**/*.d.ts',
'!extensions/**/*.d.ts',
'!**/*.{svg,exe,png,bmp,jpg,scpt,bat,cmd,cur,ttf,woff,eot,md,ps1,template,yaml,yml,d.ts.recipe,ico,icns,plist}',
'!build/{lib,download,darwin}/**/*.js',
'!build/{lib,download,linux,darwin}/**/*.js',
'!build/**/*.sh',
'!build/azure-pipelines/**/*.js',
'!build/azure-pipelines/**/*.config',
Expand Down Expand Up @@ -113,6 +113,7 @@ module.exports.copyrightFilter = [
'!**/*.code-workspace',
'!**/*.js.map',
'!build/**/*.init',
'!build/linux/libcxx-fetcher.*',
'!resources/linux/snap/snapcraft.yaml',
'!resources/win32/bin/code.js',
'!resources/web/code-web.js',
Expand Down
61 changes: 61 additions & 0 deletions build/linux/libcxx-fetcher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Can be removed once https://github.com/electron/electron-rebuild/pull/703 is available.
'use strict';
Object.defineProperty(exports, "__esModule", { value: true });
exports.downloadLibcxxObjects = exports.downloadLibcxxHeaders = void 0;
const debug = require("debug");
const extract = require("extract-zip");
const fs = require("fs-extra");
const path = require("path");
const packageJSON = require("../../package.json");
const get_1 = require("@electron/get");
const d = debug('libcxx-fetcher');
async function downloadLibcxxHeaders(outDir, electronVersion, lib_name) {
if (await fs.pathExists(path.resolve(outDir, 'include')))
return;
if (!await fs.pathExists(outDir))
await fs.mkdirp(outDir);
d(`downloading ${lib_name}_headers`);
const headers = await (0, get_1.downloadArtifact)({
version: electronVersion,
isGeneric: true,
artifactName: `${lib_name}_headers.zip`,
});
d(`unpacking ${lib_name}_headers from ${headers}`);
await extract(headers, { dir: outDir });
}
exports.downloadLibcxxHeaders = downloadLibcxxHeaders;
async function downloadLibcxxObjects(outDir, electronVersion, targetArch = 'x64') {
if (await fs.pathExists(path.resolve(outDir, 'libc++.a')))
return;
if (!await fs.pathExists(outDir))
await fs.mkdirp(outDir);
d(`downloading libcxx-objects-linux-${targetArch}`);
const objects = await (0, get_1.downloadArtifact)({
version: electronVersion,
platform: 'linux',
artifactName: 'libcxx-objects',
arch: targetArch,
});
d(`unpacking libcxx-objects from ${objects}`);
await extract(objects, { dir: outDir });
}
exports.downloadLibcxxObjects = downloadLibcxxObjects;
async function main() {
const libcxxObjectsDirPath = process.env['VSCODE_LIBCXX_OBJECTS_DIR'];
const libcxxHeadersDownloadDir = process.env['VSCODE_LIBCXX_HEADERS_DIR'];
const libcxxabiHeadersDownloadDir = process.env['VSCODE_LIBCXXABI_HEADERS_DIR'];
const arch = process.env['VSCODE_ARCH'];
const electronVersion = packageJSON.devDependencies.electron;
if (!libcxxObjectsDirPath || !libcxxHeadersDownloadDir || !libcxxabiHeadersDownloadDir) {
throw new Error('Required build env not set');
}
await downloadLibcxxObjects(libcxxObjectsDirPath, electronVersion, arch);
await downloadLibcxxHeaders(libcxxHeadersDownloadDir, electronVersion, 'libcxx');
await downloadLibcxxHeaders(libcxxabiHeadersDownloadDir, electronVersion, 'libcxxabi');
}
if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
66 changes: 66 additions & 0 deletions build/linux/libcxx-fetcher.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// Can be removed once https://github.com/electron/electron-rebuild/pull/703 is available.

'use strict';

import * as debug from 'debug';
import * as extract from 'extract-zip';
import * as fs from 'fs-extra';
import * as path from 'path';
import * as packageJSON from '../../package.json';
import { downloadArtifact } from '@electron/get';

const d = debug('libcxx-fetcher');

export async function downloadLibcxxHeaders(outDir: string, electronVersion: string, lib_name: string): Promise<void> {
if (await fs.pathExists(path.resolve(outDir, 'include'))) return;
if (!await fs.pathExists(outDir)) await fs.mkdirp(outDir);

d(`downloading ${lib_name}_headers`);
const headers = await downloadArtifact({
version: electronVersion,
isGeneric: true,
artifactName: `${lib_name}_headers.zip`,
});

d(`unpacking ${lib_name}_headers from ${headers}`);
await extract(headers, { dir: outDir });
}

export async function downloadLibcxxObjects(outDir: string, electronVersion: string, targetArch: string = 'x64'): Promise<void> {
if (await fs.pathExists(path.resolve(outDir, 'libc++.a'))) return;
if (!await fs.pathExists(outDir)) await fs.mkdirp(outDir);

d(`downloading libcxx-objects-linux-${targetArch}`);
const objects = await downloadArtifact({
version: electronVersion,
platform: 'linux',
artifactName: 'libcxx-objects',
arch: targetArch,
});

d(`unpacking libcxx-objects from ${objects}`);
await extract(objects, { dir: outDir });
}

async function main(): Promise<void> {
const libcxxObjectsDirPath = process.env['VSCODE_LIBCXX_OBJECTS_DIR'];
const libcxxHeadersDownloadDir = process.env['VSCODE_LIBCXX_HEADERS_DIR'];
const libcxxabiHeadersDownloadDir = process.env['VSCODE_LIBCXXABI_HEADERS_DIR'];
const arch = process.env['VSCODE_ARCH'];
const electronVersion = packageJSON.devDependencies.electron;

if (!libcxxObjectsDirPath || !libcxxHeadersDownloadDir || !libcxxabiHeadersDownloadDir) {
throw new Error('Required build env not set');
}

await downloadLibcxxObjects(libcxxObjectsDirPath, electronVersion, arch);
await downloadLibcxxHeaders(libcxxHeadersDownloadDir, electronVersion, 'libcxx');
await downloadLibcxxHeaders(libcxxabiHeadersDownloadDir, electronVersion, 'libcxxabi');
}

if (require.main === module) {
main().catch(err => {
console.error(err);
process.exit(1);
});
}
2 changes: 2 additions & 0 deletions build/npm/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ for (let dir of dirs) {
const env = { ...process.env };
if (process.env['VSCODE_REMOTE_CC']) { env['CC'] = process.env['VSCODE_REMOTE_CC']; }
if (process.env['VSCODE_REMOTE_CXX']) { env['CXX'] = process.env['VSCODE_REMOTE_CXX']; }
if (process.env['CXXFLAGS']) { delete env['CXXFLAGS']; }
if (process.env['LDFLAGS']) { delete env['LDFLAGS']; }
if (process.env['VSCODE_REMOTE_NODE_GYP']) { env['npm_config_node_gyp'] = process.env['VSCODE_REMOTE_NODE_GYP']; }
opts = { env };
} else if (/^extensions\//.test(dir)) {
Expand Down
3 changes: 3 additions & 0 deletions build/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"devDependencies": {
"@azure/cosmos": "^3.9.3",
"@azure/storage-blob": "^12.4.0",
"@electron/get": "^1.12.4",
"@types/ansi-colors": "^3.2.0",
"@types/azure": "0.9.19",
"@types/byline": "^4.2.32",
Expand Down Expand Up @@ -46,8 +47,10 @@
"byline": "^5.0.0",
"colors": "^1.4.0",
"commander": "^7.0.0",
"debug": "^4.3.2",
"electron-osx-sign": "^0.4.16",
"esbuild": "^0.12.6",
"extract-zip": "^2.0.1",
"fs-extra": "^9.1.0",
"got": "11.8.1",
"iconv-lite-umd": "0.6.8",
Expand Down
Loading

0 comments on commit ee4aaaa

Please sign in to comment.