Skip to content

Commit 54268fb

Browse files
committed
build: compile with C++20 support
1 parent f1019c2 commit 54268fb

File tree

3 files changed

+47
-3
lines changed

3 files changed

+47
-3
lines changed

patches/node/.patches

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,4 @@ src_account_for_openssl_unexpected_version.patch
5252
src_stop_using_deprecated_fields_of_fastapicallbackoptions.patch
5353
src_use_supported_api_to_get_stalled_tla_messages.patch
5454
build_don_t_redefine_win32_lean_and_mean.patch
55+
build_compile_with_c_20_support.patch
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Shelley Vohr <[email protected]>
3+
Date: Wed, 4 Sep 2024 16:39:23 +0200
4+
Subject: build: compile with C++20 support
5+
6+
Refs https://github.com/nodejs/node/pull/45427
7+
8+
V8 requires C++20 support as of https://chromium-review.googlesource.com/c/v8/v8/+/5587859.
9+
10+
This can be removed when Electron upgrades to a version of Node.js containing the required V8 version.
11+
12+
diff --git a/common.gypi b/common.gypi
13+
index 8736ad12eec294070a5160a64248044cd16347c9..216200c279c599f6dee228120ff5f3943fa52ffd 100644
14+
--- a/common.gypi
15+
+++ b/common.gypi
16+
@@ -307,7 +307,7 @@
17+
'VCCLCompilerTool': {
18+
'AdditionalOptions': [
19+
'/Zc:__cplusplus',
20+
- '-std:c++17'
21+
+ '-std:c++20'
22+
],
23+
'BufferSecurityCheck': 'true',
24+
'DebugInformationFormat': 1, # /Z7 embed info in .obj files
25+
@@ -489,7 +489,7 @@
26+
}],
27+
[ 'OS in "linux freebsd openbsd solaris android aix os400 cloudabi"', {
28+
'cflags': [ '-Wall', '-Wextra', '-Wno-unused-parameter', ],
29+
- 'cflags_cc': [ '-fno-rtti', '-fno-exceptions', '-std=gnu++17' ],
30+
+ 'cflags_cc': [ '-fno-rtti', '-fno-exceptions', '-std=gnu++20' ],
31+
'defines': [ '__STDC_FORMAT_MACROS' ],
32+
'ldflags': [ '-rdynamic' ],
33+
'target_conditions': [
34+
@@ -660,7 +660,7 @@
35+
['clang==1', {
36+
'xcode_settings': {
37+
'GCC_VERSION': 'com.apple.compilers.llvm.clang.1_0',
38+
- 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++17', # -std=gnu++17
39+
+ 'CLANG_CXX_LANGUAGE_STANDARD': 'gnu++20', # -std=gnu++20
40+
'CLANG_CXX_LIBRARY': 'libc++',
41+
},
42+
}],

script/spec-runner.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,10 @@ async function runMainProcessElectronTests () {
186186
}
187187

188188
async function installSpecModules (dir) {
189-
// v8 headers use c++17 so override the gyp default of -std=c++14,
190-
// but don't clobber any other CXXFLAGS that were passed into spec-runner.js
191-
const CXXFLAGS = ['-std=c++17', process.env.CXXFLAGS].filter(x => !!x).join(' ');
189+
// v8 headers use c++20 so override the gyp default of -std=c++14.
190+
const gccVersion = childProcess.execSync('g++ -dumpversion').toString();
191+
const cppFlag = parseFloat(gccVersion) <= 9 ? '-std=gnu++2a' : '-std=c++20';
192+
const CXXFLAGS = [cppFlag, process.env.CXXFLAGS].filter(x => !!x).join(' ');
192193

193194
const env = {
194195
...process.env,

0 commit comments

Comments
 (0)