Skip to content

Commit 1a0ad04

Browse files
committed
v8,tools: expose necessary V8 defines
1 parent 5b73da0 commit 1a0ad04

File tree

5 files changed

+176
-48
lines changed

5 files changed

+176
-48
lines changed

common.gypi

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,16 @@
7575

7676
'v8_win64_unwinding_info': 1,
7777

78-
# TODO(refack): make v8-perfetto happen
78+
# Variables controlling external defines exposed in public headers.
79+
'v8_enable_conservative_stack_scanning%': 0,
80+
'v8_enable_direct_local%': 0,
81+
'v8_enable_map_packing%': 0,
82+
'v8_enable_pointer_compression_shared_cage%': 0,
83+
'v8_enable_sandbox%': 0,
84+
'v8_enable_v8_checks%': 0,
85+
'v8_enable_zone_compression%': 0,
7986
'v8_use_perfetto': 0,
87+
'tsan%': 0,
8088

8189
##### end V8 defaults #####
8290

@@ -134,7 +142,7 @@
134142
}],
135143
],
136144
},
137-
'defines': [ 'DEBUG', '_DEBUG', 'V8_ENABLE_CHECKS' ],
145+
'defines': [ 'DEBUG', '_DEBUG' ],
138146
'cflags': [ '-g', '-O0' ],
139147
'conditions': [
140148
['OS in "aix os400"', {
@@ -257,11 +265,8 @@
257265
}
258266
},
259267

260-
# Defines these mostly for node-gyp to pickup, and warn addon authors of
261-
# imminent V8 deprecations, also to sync how dependencies are configured.
268+
# Defines these mostly for node-gyp to pickup.
262269
'defines': [
263-
'V8_DEPRECATION_WARNINGS',
264-
'V8_IMMINENT_DEPRECATION_WARNINGS',
265270
'_GLIBCXX_USE_CXX11_ABI=1',
266271
],
267272

@@ -369,15 +374,50 @@
369374
}],
370375
],
371376
}],
377+
# The defines bellow must include all things from the external_v8_defines
378+
# list in v8/BUILD.gn.
379+
['v8_enable_v8_checks == 1', {
380+
'defines': ['V8_ENABLE_CHECKS'],
381+
}],
372382
['v8_enable_pointer_compression == 1', {
373-
'defines': [
374-
'V8_COMPRESS_POINTERS',
375-
'V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE',
376-
],
383+
'defines': ['V8_COMPRESS_POINTERS'],
384+
}],
385+
['v8_enable_pointer_compression_shared_cage == 1', {
386+
'defines': ['V8_COMPRESS_POINTERS_IN_SHARED_CAGE'],
387+
}],
388+
['v8_enable_pointer_compression == 1 and v8_enable_pointer_compression_shared_cage != 1', {
389+
'defines': ['V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE'],
377390
}],
378391
['v8_enable_pointer_compression == 1 or v8_enable_31bit_smis_on_64bit_arch == 1', {
379392
'defines': ['V8_31BIT_SMIS_ON_64BIT_ARCH'],
380393
}],
394+
['v8_enable_zone_compression == 1', {
395+
'defines': ['V8_COMPRESS_ZONES',],
396+
}],
397+
['v8_enable_sandbox == 1', {
398+
'defines': ['V8_ENABLE_SANDBOX',],
399+
}],
400+
['v8_deprecation_warnings == 1', {
401+
'defines': ['V8_DEPRECATION_WARNINGS',],
402+
}],
403+
['v8_imminent_deprecation_warnings == 1', {
404+
'defines': ['V8_IMMINENT_DEPRECATION_WARNINGS',],
405+
}],
406+
['v8_use_perfetto == 1', {
407+
'defines': ['V8_USE_PERFETTO',],
408+
}],
409+
['v8_enable_map_packing == 1', {
410+
'defines': ['V8_MAP_PACKING',],
411+
}],
412+
['tsan == 1', {
413+
'defines': ['V8_IS_TSAN',],
414+
}],
415+
['v8_enable_conservative_stack_scanning == 1', {
416+
'defines': ['V8_ENABLE_CONSERVATIVE_STACK_SCANNING',],
417+
}],
418+
['v8_enable_direct_local == 1', {
419+
'defines': ['V8_ENABLE_DIRECT_LOCAL',],
420+
}],
381421
['OS == "win"', {
382422
'defines': [
383423
'WIN32',

configure.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,7 @@ def configure_v8(o):
15051505
o['variables']['v8_enable_31bit_smis_on_64bit_arch'] = 1 if options.enable_pointer_compression else 0
15061506
o['variables']['v8_enable_shared_ro_heap'] = 0 if options.enable_pointer_compression or options.disable_shared_ro_heap else 1
15071507
o['variables']['v8_enable_extensible_ro_snapshot'] = 0
1508+
o['variables']['v8_enable_v8_checks'] = 1 if options.debug else 0
15081509
o['variables']['v8_trace_maps'] = 1 if options.trace_maps else 0
15091510
o['variables']['node_use_v8_platform'] = b(not options.without_v8_platform)
15101511
o['variables']['node_use_bundled_v8'] = b(not options.without_bundled_v8)

tools/generate_config_gypi.py

Lines changed: 91 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,134 @@
77
# This script reads the configurations of GN and outputs a config.gypi file that
88
# will be used to populate process.config.variables.
99

10+
import argparse
1011
import re
1112
import os
1213
import subprocess
1314
import sys
1415

15-
root_dir = os.path.dirname(os.path.dirname(__file__))
16-
sys.path.append(os.path.join(root_dir, 'node', 'tools'))
16+
sys.path.append(os.path.dirname(__file__))
1717
import getmoduleversion
1818
import getnapibuildversion
1919

20+
# The defines bellow must include all things from the external_v8_defines list
21+
# in v8/BUILD.gn.
22+
# TODO(zcbenz): Import from v8_features.json once this change gets into Node:
23+
# https://chromium-review.googlesource.com/c/v8/v8/+/5040612
24+
V8_FEATURE_DEFINES = {
25+
'v8_enable_v8_checks': 'V8_ENABLE_CHECKS',
26+
'v8_enable_pointer_compression': 'V8_COMPRESS_POINTERS',
27+
'v8_enable_pointer_compression_shared_cage': 'V8_COMPRESS_POINTERS_IN_SHARED_CAGE',
28+
'v8_enable_31bit_smis_on_64bit_arch': 'V8_31BIT_SMIS_ON_64BIT_ARCH',
29+
'v8_enable_zone_compression': 'V8_COMPRESS_ZONES',
30+
'v8_enable_sandbox': 'V8_ENABLE_SANDBOX',
31+
'v8_deprecation_warnings': 'V8_DEPRECATION_WARNINGS',
32+
'v8_imminent_deprecation_warnings': 'V8_IMMINENT_DEPRECATION_WARNINGS',
33+
'v8_use_perfetto': 'V8_USE_PERFETTO',
34+
'v8_enable_map_packing': 'V8_MAP_PACKING',
35+
'tsan': 'V8_IS_TSAN',
36+
'v8_enable_conservative_stack_scanning': 'V8_ENABLE_CONSERVATIVE_STACK_SCANNING',
37+
'v8_enable_direct_local': 'V8_ENABLE_DIRECT_LOCAL',
38+
}
39+
40+
# Regex used for parsing results of "gn args".
2041
GN_RE = re.compile(r'(\w+)\s+=\s+(.*?)$', re.MULTILINE)
2142

43+
if sys.platform == 'win32':
44+
GN = 'gn.exe'
45+
else:
46+
GN = 'gn'
47+
48+
def bool_to_number(v):
49+
return 1 if v else 0
50+
2251
def bool_string_to_number(v):
23-
return 1 if v == 'true' else 0
52+
return bool_to_number(v == 'true')
53+
54+
def get_gn_config(out_dir):
55+
# Read args from GN configurations.
56+
gn_args = subprocess.check_output(
57+
[GN, 'args', '--list', '--short', '-C', out_dir])
58+
config = dict(re.findall(GN_RE, gn_args.decode()))
59+
# Get napi_build_version from Node, which is not part of GN args.
60+
config['napi_build_version'] = getnapibuildversion.get_napi_version()
61+
return config
62+
63+
def get_v8_config(out_dir, node_gn_path):
64+
# For args that have default values in V8's GN configurations, we can not rely
65+
# on the values printed by "gn args", because most of them would be empty
66+
# strings, and the actual value would depend on the logics in v8/BUILD.gn.
67+
# So we print out the defines and deduce the feature from them instead.
68+
node_defines = subprocess.check_output(
69+
[GN, 'desc', '-C', out_dir, node_gn_path + ":libnode", 'defines']).decode().split('\n')
70+
v8_config = {}
71+
for feature, define in V8_FEATURE_DEFINES.items():
72+
v8_config[feature] = bool_to_number(define in node_defines)
73+
return v8_config
2474

25-
def translate_config(config):
26-
return {
75+
def translate_config(out_dir, config, v8_config):
76+
config_gypi = {
2777
'target_defaults': {
2878
'default_configuration':
2979
'Debug' if config['is_debug'] == 'true' else 'Release',
3080
},
3181
'variables': {
3282
'asan': bool_string_to_number(config['is_asan']),
83+
'enable_lto': config['use_thin_lto'],
84+
'is_debug': bool_string_to_number(config['is_debug']),
3385
'llvm_version': 13,
3486
'napi_build_version': config['napi_build_version'],
3587
'node_builtin_shareable_builtins':
3688
eval(config['node_builtin_shareable_builtins']),
3789
'node_module_version': int(config['node_module_version']),
38-
'node_shared': bool_string_to_number(config['is_component_build']),
3990
'node_use_openssl': config['node_use_openssl'],
4091
'node_use_node_code_cache': config['node_use_node_code_cache'],
4192
'node_use_node_snapshot': config['node_use_node_snapshot'],
42-
'v8_enable_31bit_smis_on_64bit_arch':
43-
bool_string_to_number(config['v8_enable_31bit_smis_on_64bit_arch']),
44-
'v8_enable_pointer_compression':
45-
bool_string_to_number(config['v8_enable_pointer_compression']),
4693
'v8_enable_i18n_support':
4794
bool_string_to_number(config['v8_enable_i18n_support']),
4895
'v8_enable_inspector': # this is actually a node misnomer
4996
bool_string_to_number(config['node_enable_inspector']),
5097
'shlib_suffix': 'dylib' if sys.platform == 'darwin' else 'so',
98+
'tsan': bool_string_to_number(config['is_tsan']),
99+
# TODO(zcbenz): Shared components are not supported in GN config yet.
100+
'node_shared': 'false',
101+
'node_shared_brotli': 'false',
102+
'node_shared_cares': 'false',
103+
'node_shared_http_parser': 'false',
104+
'node_shared_libuv': 'false',
105+
'node_shared_nghttp2': 'false',
106+
'node_shared_nghttp3': 'false',
107+
'node_shared_ngtcp2': 'false',
108+
'node_shared_openssl': 'false',
109+
'node_shared_zlib': 'false',
51110
}
52111
}
112+
config_gypi['variables'].update(v8_config)
113+
return config_gypi
53114

54-
def main(gn_out_dir, output_file, depfile):
55-
# Get GN config and parse into a dictionary.
56-
if sys.platform == 'win32':
57-
gn = 'gn.exe'
58-
else:
59-
gn = 'gn'
60-
gnconfig = subprocess.check_output(
61-
[gn, 'args', '--list', '--short', '-C', gn_out_dir])
62-
config = dict(re.findall(GN_RE, gnconfig.decode('utf-8')))
63-
config['node_module_version'] = getmoduleversion.get_version()
64-
config['napi_build_version'] = getnapibuildversion.get_napi_version()
115+
def main():
116+
parser = argparse.ArgumentParser(
117+
description='Generate config.gypi file from GN configurations')
118+
parser.add_argument('target', help='path to generated config.gypi file')
119+
parser.add_argument('--out-dir', help='path to the output directory',
120+
default='out/Release')
121+
parser.add_argument('--node-gn-path', help='path of the node target in GN',
122+
default='//node')
123+
parser.add_argument('--dep-file', help='path to an optional dep file',
124+
default=None)
125+
args, unknown_args = parser.parse_known_args()
126+
127+
config = get_gn_config(args.out_dir)
128+
v8_config = get_v8_config(args.out_dir, args.node_gn_path)
65129

66130
# Write output.
67-
with open(output_file, 'w') as f:
68-
f.write(repr(translate_config(config)))
131+
with open(args.target, 'w') as f:
132+
f.write(repr(translate_config(args.out_dir, config, v8_config)))
69133

70134
# Write depfile. Force regenerating config.gypi when GN configs change.
71-
with open(depfile, 'w') as f:
72-
f.write('%s: %s '%(output_file, 'build.ninja'))
135+
if args.dep_file:
136+
with open(args.dep_file, 'w') as f:
137+
f.write('%s: %s '%(args.target, 'build.ninja'))
73138

74139
if __name__ == '__main__':
75-
main(sys.argv[1], sys.argv[2], sys.argv[3])
140+
main()

tools/v8_gypfiles/features.gypi

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155

156156
# Enable pointer compression (sets -dV8_COMPRESS_POINTERS).
157157
'v8_enable_pointer_compression%': 0,
158+
'v8_enable_pointer_compression_shared_cage%': 0,
158159
'v8_enable_31bit_smis_on_64bit_arch%': 0,
159160

160161
# Sets -dV8_SHORT_BUILTIN_CALLS
@@ -197,6 +198,15 @@
197198
# currently implemented.
198199
'v8_use_perfetto%': 0,
199200

201+
# Enable map packing & unpacking (sets -dV8_MAP_PACKING).
202+
'v8_enable_map_packing%': 0,
203+
204+
# Scan the call stack conservatively during garbage collection.
205+
'v8_enable_conservative_stack_scanning%': 0,
206+
207+
# Use direct pointers in local handles.
208+
'v8_enable_direct_local%': 0,
209+
200210
# Controls the threshold for on-heap/off-heap Typed Arrays.
201211
'v8_typed_array_max_size_in_heap%': 64,
202212

@@ -345,10 +355,13 @@
345355
'defines': ['ENABLE_VTUNE_JIT_INTERFACE',],
346356
}],
347357
['v8_enable_pointer_compression==1', {
348-
'defines': [
349-
'V8_COMPRESS_POINTERS',
350-
'V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE',
351-
],
358+
'defines': ['V8_COMPRESS_POINTERS'],
359+
}],
360+
['v8_enable_pointer_compression_shared_cage==1', {
361+
'defines': ['V8_COMPRESS_POINTERS_IN_SHARED_CAGE'],
362+
}],
363+
['v8_enable_pointer_compression==1 and v8_enable_pointer_compression_shared_cage==0', {
364+
'defines': ['V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE'],
352365
}],
353366
['v8_enable_pointer_compression==1 or v8_enable_31bit_smis_on_64bit_arch==1', {
354367
'defines': ['V8_31BIT_SMIS_ON_64BIT_ARCH',],
@@ -392,13 +405,9 @@
392405
}],
393406
['v8_deprecation_warnings==1', {
394407
'defines': ['V8_DEPRECATION_WARNINGS',],
395-
},{
396-
'defines!': ['V8_DEPRECATION_WARNINGS',],
397408
}],
398409
['v8_imminent_deprecation_warnings==1', {
399410
'defines': ['V8_IMMINENT_DEPRECATION_WARNINGS',],
400-
},{
401-
'defines!': ['V8_IMMINENT_DEPRECATION_WARNINGS',],
402411
}],
403412
['v8_enable_i18n_support==1', {
404413
'defines': ['V8_INTL_SUPPORT',],
@@ -443,9 +452,21 @@
443452
['v8_use_perfetto==1', {
444453
'defines': ['V8_USE_PERFETTO',],
445454
}],
455+
['v8_enable_map_packing==1', {
456+
'defines': ['V8_MAP_PACKING',],
457+
}],
446458
['v8_win64_unwinding_info==1', {
447459
'defines': ['V8_WIN64_UNWINDING_INFO',],
448460
}],
461+
['tsan==1', {
462+
'defines': ['V8_IS_TSAN',],
463+
}],
464+
['v8_enable_conservative_stack_scanning==1', {
465+
'defines': ['V8_ENABLE_CONSERVATIVE_STACK_SCANNING',],
466+
}],
467+
['v8_enable_direct_local==1', {
468+
'defines': ['V8_ENABLE_DIRECT_LOCAL',],
469+
}],
449470
['v8_enable_regexp_interpreter_threaded_dispatch==1', {
450471
'defines': ['V8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH',],
451472
}],

unofficial.gni

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -256,10 +256,11 @@ template("node_gn_build") {
256256
script = "tools/generate_config_gypi.py"
257257
outputs = [ "$target_gen_dir/config.gypi" ]
258258
depfile = "$target_gen_dir/$target_name.d"
259-
script_args = [ "$root_build_dir" ]
260-
script_args += outputs
261-
script_args += [ depfile ]
262-
args = rebase_path(script_args, root_build_dir)
259+
args = rebase_path(outputs, root_build_dir) + [
260+
"--out-dir", rebase_path(root_build_dir, root_build_dir),
261+
"--dep-file", rebase_path(depfile, root_build_dir),
262+
"--node-gn-path", node_path,
263+
]
263264
}
264265

265266
executable("node_js2c") {

0 commit comments

Comments
 (0)