GeezerVison is showing github.com — v8,tools: expose necessary V8 defines · nodejs/node@a5d959b
File treeExpand file treeCollapse file tree Open diff view settings Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: common.gypi +50-10Lines changed: 50 additions & 10 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 75 | 75 |
| 76 | 76 | 'v8_win64_unwinding_info': 1, | 77 | 77 |
| 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, | 79 | 86 | 'v8_use_perfetto': 0, | | 87 | + 'tsan%': 0, | 80 | 88 |
| 81 | 89 | ##### end V8 defaults ##### | 82 | 90 |
| | 134 | 142 | }], | 135 | 143 | ], | 136 | 144 | }, | 137 | | - 'defines': [ 'DEBUG', '_DEBUG', 'V8_ENABLE_CHECKS' ], | | 145 | + 'defines': [ 'DEBUG', '_DEBUG' ], | 138 | 146 | 'cflags': [ '-g', '-O0' ], | 139 | 147 | 'conditions': [ | 140 | 148 | ['OS in "aix os400"', { | | 257 | 265 | } | 258 | 266 | }, | 259 | 267 |
| 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. | 262 | 269 | 'defines': [ | 263 | | - 'V8_DEPRECATION_WARNINGS', | 264 | | - 'V8_IMMINENT_DEPRECATION_WARNINGS', | 265 | 270 | '_GLIBCXX_USE_CXX11_ABI=1', | 266 | 271 | ], | 267 | 272 |
| | 369 | 374 | }], | 370 | 375 | ], | 371 | 376 | }], | | 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 | + }], | 372 | 382 | ['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'], | 377 | 390 | }], | 378 | 391 | ['v8_enable_pointer_compression == 1 or v8_enable_31bit_smis_on_64bit_arch == 1', { | 379 | 392 | 'defines': ['V8_31BIT_SMIS_ON_64BIT_ARCH'], | 380 | 393 | }], | | 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 | + }], | 381 | 421 | ['OS == "win"', { | 382 | 422 | 'defines': [ | 383 | 423 | 'WIN32', | |
Collapse file Copy file name to clipboardExpand all lines: configure.py +1Lines changed: 1 addition & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -1505,6 +1505,7 @@ def configure_v8(o): | 1505 | 1505 | o['variables']['v8_enable_31bit_smis_on_64bit_arch'] = 1 if options.enable_pointer_compression else 0 | 1506 | 1506 | o['variables']['v8_enable_shared_ro_heap'] = 0 if options.enable_pointer_compression or options.disable_shared_ro_heap else 1 | 1507 | 1507 | o['variables']['v8_enable_extensible_ro_snapshot'] = 0 | | 1508 | + o['variables']['v8_enable_v8_checks'] = 1 if options.debug else 0 | 1508 | 1509 | o['variables']['v8_trace_maps'] = 1 if options.trace_maps else 0 | 1509 | 1510 | o['variables']['node_use_v8_platform'] = b(not options.without_v8_platform) | 1510 | 1511 | o['variables']['node_use_bundled_v8'] = b(not options.without_bundled_v8) | |
Collapse file Copy file name to clipboardExpand all lines: tools/generate_config_gypi.py +91-27Lines changed: 91 additions & 27 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 7 | 7 | # This script reads the configurations of GN and outputs a config.gypi file that | 8 | 8 | # will be used to populate process.config.variables. | 9 | 9 |
| | 10 | +import argparse | 10 | 11 | import re | 11 | 12 | import os | 12 | 13 | import subprocess | 13 | 14 | import sys | 14 | 15 |
| 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__)) | 18 | 17 | import getnapibuildversion | 19 | 18 |
| | 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". | 20 | 40 | GN_RE = re.compile(r'(\w+)\s+=\s+(.*?)$', re.MULTILINE) | 21 | 41 |
| | 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 | + | 22 | 50 | 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 | 24 | 73 |
| 25 | | -def translate_config(config): | 26 | | - return { | | 74 | +def translate_config(out_dir, config, v8_config): | | 75 | + config_gypi = { | 27 | 76 | 'target_defaults': { | 28 | 77 | 'default_configuration': | 29 | 78 | 'Debug' if config['is_debug'] == 'true' else 'Release', | 30 | 79 | }, | 31 | 80 | 'variables': { | 32 | 81 | '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']), | 33 | 84 | 'llvm_version': 13, | 34 | 85 | 'napi_build_version': config['napi_build_version'], | 35 | 86 | 'node_builtin_shareable_builtins': | 36 | 87 | eval(config['node_builtin_shareable_builtins']), | 37 | 88 | 'node_module_version': int(config['node_module_version']), | 38 | | - 'node_shared': bool_string_to_number(config['is_component_build']), | 39 | 89 | 'node_use_openssl': config['node_use_openssl'], | 40 | 90 | 'node_use_node_code_cache': config['node_use_node_code_cache'], | 41 | 91 | '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']), | 46 | 92 | 'v8_enable_i18n_support': | 47 | 93 | bool_string_to_number(config['v8_enable_i18n_support']), | 48 | 94 | 'v8_enable_inspector': # this is actually a node misnomer | 49 | 95 | bool_string_to_number(config['node_enable_inspector']), | 50 | 96 | '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', | 51 | 109 | } | 52 | 110 | } | | 111 | + config_gypi['variables'].update(v8_config) | | 112 | + return config_gypi | 53 | 113 |
| 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) | 65 | 128 |
| 66 | 129 | # 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))) | 69 | 132 |
| 70 | 133 | # 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')) | 73 | 137 |
| 74 | 138 | if __name__ == '__main__': | 75 | | - main(sys.argv[1], sys.argv[2], sys.argv[3]) | | 139 | + main() |
Collapse file Copy file name to clipboardExpand all lines: tools/v8_gypfiles/features.gypi +29-8Lines changed: 29 additions & 8 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 155 | 155 |
| 156 | 156 | # Enable pointer compression (sets -dV8_COMPRESS_POINTERS). | 157 | 157 | 'v8_enable_pointer_compression%': 0, | | 158 | + 'v8_enable_pointer_compression_shared_cage%': 0, | 158 | 159 | 'v8_enable_31bit_smis_on_64bit_arch%': 0, | 159 | 160 |
| 160 | 161 | # Sets -dV8_SHORT_BUILTIN_CALLS | | 197 | 198 | # currently implemented. | 198 | 199 | 'v8_use_perfetto%': 0, | 199 | 200 |
| | 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 | + | 200 | 210 | # Controls the threshold for on-heap/off-heap Typed Arrays. | 201 | 211 | 'v8_typed_array_max_size_in_heap%': 64, | 202 | 212 |
| | 345 | 355 | 'defines': ['ENABLE_VTUNE_JIT_INTERFACE',], | 346 | 356 | }], | 347 | 357 | ['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'], | 352 | 365 | }], | 353 | 366 | ['v8_enable_pointer_compression==1 or v8_enable_31bit_smis_on_64bit_arch==1', { | 354 | 367 | 'defines': ['V8_31BIT_SMIS_ON_64BIT_ARCH',], | | 392 | 405 | }], | 393 | 406 | ['v8_deprecation_warnings==1', { | 394 | 407 | 'defines': ['V8_DEPRECATION_WARNINGS',], | 395 | | - },{ | 396 | | - 'defines!': ['V8_DEPRECATION_WARNINGS',], | 397 | 408 | }], | 398 | 409 | ['v8_imminent_deprecation_warnings==1', { | 399 | 410 | 'defines': ['V8_IMMINENT_DEPRECATION_WARNINGS',], | 400 | | - },{ | 401 | | - 'defines!': ['V8_IMMINENT_DEPRECATION_WARNINGS',], | 402 | 411 | }], | 403 | 412 | ['v8_enable_i18n_support==1', { | 404 | 413 | 'defines': ['V8_INTL_SUPPORT',], | | 443 | 452 | ['v8_use_perfetto==1', { | 444 | 453 | 'defines': ['V8_USE_PERFETTO',], | 445 | 454 | }], | | 455 | + ['v8_enable_map_packing==1', { | | 456 | + 'defines': ['V8_MAP_PACKING',], | | 457 | + }], | 446 | 458 | ['v8_win64_unwinding_info==1', { | 447 | 459 | 'defines': ['V8_WIN64_UNWINDING_INFO',], | 448 | 460 | }], | | 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 | + }], | 449 | 470 | ['v8_enable_regexp_interpreter_threaded_dispatch==1', { | 450 | 471 | 'defines': ['V8_ENABLE_REGEXP_INTERPRETER_THREADED_DISPATCH',], | 451 | 472 | }], | |
Collapse file Copy file name to clipboardExpand all lines: unofficial.gni +5-4Lines changed: 5 additions & 4 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -257,10 +257,11 @@ template("node_gn_build") { | 257 | 257 | script = "tools/generate_config_gypi.py" | 258 | 258 | outputs = [ "$target_gen_dir/config.gypi" ] | 259 | 259 | 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 | + ] | 264 | 265 | } | 265 | 266 |
| 266 | 267 | executable("node_js2c") { | |
|