Skip to content

Commit

Permalink
fix: add std=c++17 flag for e20+
Browse files Browse the repository at this point in the history
  • Loading branch information
VerteDinde committed Jul 6, 2022
1 parent 20107a8 commit 979361d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/clang-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as cp from 'child_process';
import debug from 'debug';
import * as fs from 'fs-extra';
import * as path from 'path';
import semver from 'semver';
import * as tar from 'tar';
import * as zlib from 'zlib';
import { ELECTRON_GYP_DIR } from './constants';
Expand Down Expand Up @@ -36,10 +37,14 @@ export async function getClangEnvironmentVars(electronVersion: string, targetArc
const clangDownloadDir = await downloadClangVersion(electronVersion);

const clangDir = path.resolve(clangDownloadDir, 'bin');
const cxxflags = [];
const clangArgs: string[] = [];
if (process.platform === 'darwin') {
clangArgs.push('-isysroot', getSDKRoot());
}
if (semver.major(electronVersion) >= 20) {
cxxflags.push('-std=c++17');
}

const gypArgs = [];
if (process.platform === 'win32') {
Expand All @@ -56,6 +61,8 @@ export async function getClangEnvironmentVars(electronVersion: string, targetArc
env: {
CC: `"${path.resolve(clangDir, 'clang')}" ${clangArgs.join(' ')}`,
CXX: `"${path.resolve(clangDir, 'clang++')}" ${clangArgs.join(' ')}`,
CFLAGS: `${cxxflags.join(' ')}`,
CXXFLAGS: `${cxxflags.join(' ')}`
},
args: gypArgs,
}
Expand Down
4 changes: 4 additions & 0 deletions src/module-type/node-gyp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ export class NodeGyp extends NativeModule {
let env: Record<string, string | undefined>;
const extraNodeGypArgs: string[] = [];

if (semver.major(this.rebuilder.electronVersion) >= 20) {
process.env.CXXFLAGS = '-std=c++17';
}

if (this.rebuilder.useElectronClang) {
env = { ...process.env };
const { env: clangEnv, args: clangArgs } = await getClangEnvironmentVars(this.rebuilder.electronVersion, this.rebuilder.arch);
Expand Down

0 comments on commit 979361d

Please sign in to comment.