Skip to content

Commit 3b6b1af

Browse files
zcbenzUlisesGascon
authored andcommitted
v8,tools: expose necessary V8 defines
PR-URL: #50820 Reviewed-By: Jiawen Geng <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 05e25e0 commit 3b6b1af

File tree

5 files changed

+177
-49
lines changed

5 files changed

+177
-49
lines changed

common.gypi

+50-10
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

+2
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,8 @@ def configure_v8(o):
15041504
o['variables']['v8_enable_pointer_compression'] = 1 if options.enable_pointer_compression else 0
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
1507+
o['variables']['v8_enable_extensible_ro_snapshot'] = 0
1508+
o['variables']['v8_enable_v8_checks'] = 1 if options.debug else 0
15071509
o['variables']['v8_trace_maps'] = 1 if options.trace_maps else 0
15081510
o['variables']['node_use_v8_platform'] = b(not options.without_v8_platform)
15091511
o['variables']['node_use_bundled_v8'] = b(not options.without_bundled_v8)

tools/generate_config_gypi.py

+91-27
Original file line numberDiff line numberDiff line change
@@ -7,69 +7,133 @@
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'))
17-
import getmoduleversion
16+
sys.path.append(os.path.dirname(__file__))
1817
import getnapibuildversion
1918

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

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

25-
def translate_config(config):
26-
return {
74+
def translate_config(out_dir, config, v8_config):
75+
config_gypi = {
2776
'target_defaults': {
2877
'default_configuration':
2978
'Debug' if config['is_debug'] == 'true' else 'Release',
3079
},
3180
'variables': {
3281
'asan': bool_string_to_number(config['is_asan']),
82+
'enable_lto': config['use_thin_lto'],
83+
'is_debug': bool_string_to_number(config['is_debug']),
3384
'llvm_version': 13,
3485
'napi_build_version': config['napi_build_version'],
3586
'node_builtin_shareable_builtins':
3687
eval(config['node_builtin_shareable_builtins']),
3788
'node_module_version': int(config['node_module_version']),
38-
'node_shared': bool_string_to_number(config['is_component_build']),
3989
'node_use_openssl': config['node_use_openssl'],
4090
'node_use_node_code_cache': config['node_use_node_code_cache'],
4191
'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']),
4692
'v8_enable_i18n_support':
4793
bool_string_to_number(config['v8_enable_i18n_support']),
4894
'v8_enable_inspector': # this is actually a node misnomer
4995
bool_string_to_number(config['node_enable_inspector']),
5096
'shlib_suffix': 'dylib' if sys.platform == 'darwin' else 'so',
97+
'tsan': bool_string_to_number(config['is_tsan']),
98+
# TODO(zcbenz): Shared components are not supported in GN config yet.
99+
'node_shared': 'false',
100+
'node_shared_brotli': 'false',
101+
'node_shared_cares': 'false',
102+
'node_shared_http_parser': 'false',
103+
'node_shared_libuv': 'false',
104+
'node_shared_nghttp2': 'false',
105+
'node_shared_nghttp3': 'false',
106+
'node_shared_ngtcp2': 'false',
107+
'node_shared_openssl': 'false',
108+
'node_shared_zlib': 'false',
51109
}
52110
}
111+
config_gypi['variables'].update(v8_config)
112+
return config_gypi
53113

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()
114+
def main():
115+
parser = argparse.ArgumentParser(
116+
description='Generate config.gypi file from GN configurations')
117+
parser.add_argument('target', help='path to generated config.gypi file')
118+
parser.add_argument('--out-dir', help='path to the output directory',
119+
default='out/Release')
120+
parser.add_argument('--node-gn-path', help='path of the node target in GN',
121+
default='//node')
122+
parser.add_argument('--dep-file', help='path to an optional dep file',
123+
default=None)
124+
args, unknown_args = parser.parse_known_args()
125+
126+
config = get_gn_config(args.out_dir)
127+
v8_config = get_v8_config(args.out_dir, args.node_gn_path)
65128

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

70133
# 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'))
134+
if args.dep_file:
135+
with open(args.dep_file, 'w') as f:
136+
f.write('%s: %s '%(args.target, 'build.ninja'))
73137

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

tools/v8_gypfiles/features.gypi

+29-8
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

@@ -341,10 +351,13 @@
341351
'defines': ['ENABLE_VTUNE_JIT_INTERFACE',],
342352
}],
343353
['v8_enable_pointer_compression==1', {
344-
'defines': [
345-
'V8_COMPRESS_POINTERS',
346-
'V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE',
347-
],
354+
'defines': ['V8_COMPRESS_POINTERS'],
355+
}],
356+
['v8_enable_pointer_compression_shared_cage==1', {
357+
'defines': ['V8_COMPRESS_POINTERS_IN_SHARED_CAGE'],
358+
}],
359+
['v8_enable_pointer_compression==1 and v8_enable_pointer_compression_shared_cage==0', {
360+
'defines': ['V8_COMPRESS_POINTERS_IN_ISOLATE_CAGE'],
348361
}],
349362
['v8_enable_pointer_compression==1 or v8_enable_31bit_smis_on_64bit_arch==1', {
350363
'defines': ['V8_31BIT_SMIS_ON_64BIT_ARCH',],
@@ -388,13 +401,9 @@
388401
}],
389402
['v8_deprecation_warnings==1', {
390403
'defines': ['V8_DEPRECATION_WARNINGS',],
391-
},{
392-
'defines!': ['V8_DEPRECATION_WARNINGS',],
393404
}],
394405
['v8_imminent_deprecation_warnings==1', {
395406
'defines': ['V8_IMMINENT_DEPRECATION_WARNINGS',],
396-
},{
397-
'defines!': ['V8_IMMINENT_DEPRECATION_WARNINGS',],
398407
}],
399408
['v8_enable_i18n_support==1', {
400409
'defines': ['V8_INTL_SUPPORT',],
@@ -439,9 +448,21 @@
439448
['v8_use_perfetto==1', {
440449
'defines': ['V8_USE_PERFETTO',],
441450
}],
451+
['v8_enable_map_packing==1', {
452+
'defines': ['V8_MAP_PACKING',],
453+
}],
442454
['v8_win64_unwinding_info==1', {
443455
'defines': ['V8_WIN64_UNWINDING_INFO',],
444456
}],
457+
['tsan==1', {
458+
'defines': ['V8_IS_TSAN',],
459+
}],
460+
['v8_enable_conservative_stack_scanning==1', {
461+
'defines': ['V8_ENABLE_CONSERVATIVE_STACK_SCANNING',],
462+
}],
463+
['v8_enable_direct_local==1', {
464+
'defines': ['V8_ENABLE_DIRECT_LOCAL',],
465+
}],
445466
['v8_enable_regexp_interpreter_threaded_dispatch==1', {
446467
'defines': ['V8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH',],
447468
}],

unofficial.gni

+5-4
Original file line numberDiff line numberDiff line change
@@ -257,10 +257,11 @@ template("node_gn_build") {
257257
script = "tools/generate_config_gypi.py"
258258
outputs = [ "$target_gen_dir/config.gypi" ]
259259
depfile = "$target_gen_dir/$target_name.d"
260-
script_args = [ "$root_build_dir" ]
261-
script_args += outputs
262-
script_args += [ depfile ]
263-
args = rebase_path(script_args, root_build_dir)
260+
args = rebase_path(outputs, root_build_dir) + [
261+
"--out-dir", rebase_path(root_build_dir, root_build_dir),
262+
"--dep-file", rebase_path(depfile, root_build_dir),
263+
"--node-gn-path", node_path,
264+
]
264265
}
265266

266267
executable("node_js2c") {

0 commit comments

Comments
 (0)