diff --git a/configure.py b/configure.py index 40a9bea640361a..a9910d038f01cb 100755 --- a/configure.py +++ b/configure.py @@ -1621,7 +1621,7 @@ def configure_node_lib_files(o): o['variables']['node_library_files'] = SearchFiles('lib', 'js') def configure_node_cctest_sources(o): - o['variables']['node_cctest_sources'] = [ 'src/node_snapshot_stub.cc' ] + \ + o['variables']['node_cctest_sources'] = [] + \ SearchFiles('test/cctest', 'cc') + \ SearchFiles('test/cctest', 'h') @@ -1676,10 +1676,6 @@ def configure_node(o): o['variables']['arm_fpu'] = options.arm_fpu or 'neon' if options.node_snapshot_main is not None: - if options.shared: - # This should be possible to fix, but we will need to refactor the - # libnode target to avoid building it twice. - error('--node-snapshot-main is incompatible with --shared') if options.without_node_snapshot: error('--node-snapshot-main is incompatible with ' + '--without-node-snapshot') @@ -1690,8 +1686,7 @@ def configure_node(o): if options.without_node_snapshot or options.node_builtin_modules_path: o['variables']['node_use_node_snapshot'] = 'false' else: - o['variables']['node_use_node_snapshot'] = b( - not cross_compiling and not options.shared) + o['variables']['node_use_node_snapshot'] = b(not cross_compiling) # Do not use code cache when Node.js is built for collecting coverage of itself, this allows more # precise coverage for the JS built-ins. @@ -1699,8 +1694,7 @@ def configure_node(o): o['variables']['node_use_node_code_cache'] = 'false' else: # TODO(refack): fix this when implementing embedded code-cache when cross-compiling. - o['variables']['node_use_node_code_cache'] = b( - not cross_compiling and not options.shared) + o['variables']['node_use_node_code_cache'] = b(not cross_compiling) if options.write_snapshot_as_array_literals is not None: o['variables']['node_write_snapshot_as_array_literals'] = b(options.write_snapshot_as_array_literals) diff --git a/node.gyp b/node.gyp index 269718e0bd7f5a..bd66c9b4982e7f 100644 --- a/node.gyp +++ b/node.gyp @@ -6,9 +6,12 @@ 'v8_enable_31bit_smis_on_64bit_arch%': 0, 'force_dynamic_crt%': 0, 'node_builtin_modules_path%': '', + # `node` executable target name. 'node_core_target_name%': 'node', - 'node_enable_v8_vtunejit%': 'false', - 'node_intermediate_lib_type%': 'static_library', + # `libnode` target type, `static_library` if `node_shared` is false and `shared_library` if `node_shared` is true. + 'node_lib_type%': 'static_library', + # `libnode` target name, can be a `static_library` or `shared_library` based on `node_shared`. + # NOTE: Gyp will prefix this with `lib` if this name does not start with `lib`. 'node_lib_target_name%': 'libnode', 'node_module_version%': '', 'node_no_browser_globals%': 'false', @@ -35,6 +38,7 @@ 'node_use_quic%': 'false', 'node_use_sqlite%': 'true', 'node_use_v8_platform%': 'true', + 'node_enable_v8_vtunejit%': 'false', 'node_v8_options%': '', 'node_write_snapshot_as_string_literals': 'true', 'ossfuzz' : 'false', @@ -469,17 +473,7 @@ }], [ 'node_shared=="true"', { 'node_target_type%': 'shared_library', - 'conditions': [ - ['OS in "aix os400"', { - # For AIX, always generate static library first, - # It needs an extra step to generate exp and - # then use both static lib and exp to create - # shared lib. - 'node_intermediate_lib_type': 'static_library', - }, { - 'node_intermediate_lib_type': 'shared_library', - }], - ], + 'node_lib_type': 'shared_library', }, { 'node_target_type%': 'executable', }], @@ -591,6 +585,10 @@ 'src/node_main.cc' ], + 'dependencies': [ + '<(node_lib_target_name)', + ], + 'msvs_settings': { 'VCLinkerTool': { 'GenerateMapFile': 'true', # /MAP @@ -623,37 +621,26 @@ 'WARNING_CFLAGS': [ '-Werror' ], }, }], - [ 'node_intermediate_lib_type=="static_library" and ' - 'node_shared=="true" and OS in "aix os400"', { - # For AIX, shared lib is linked by static lib and .exp. In the - # case here, the executable needs to link to shared lib. - # Therefore, use 'node_aix_shared' target to generate the - # shared lib and then executable. - 'dependencies': [ 'node_aix_shared' ], - }, { - 'dependencies': [ '<(node_lib_target_name)' ], - 'conditions': [ - ['OS=="win" and node_shared=="true"', { - 'dependencies': ['generate_node_def'], - 'msvs_settings': { - 'VCLinkerTool': { - 'ModuleDefinitionFile': '<(PRODUCT_DIR)/<(node_core_target_name).def', - }, - }, - }], - ], + ['node_shared=="true" and OS=="win"', { + 'dependencies': ['generate_node_def'], + 'msvs_settings': { + 'VCLinkerTool': { + 'ModuleDefinitionFile': '<(PRODUCT_DIR)/<(node_core_target_name).def', + }, + }, }], - [ 'node_intermediate_lib_type=="static_library" and node_shared=="false"', { + [ 'node_shared=="false"', { + # Keep this whole-archive section in sync with the `node_lib` target below. 'xcode_settings': { 'OTHER_LDFLAGS': [ - '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)', '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)', ], }, 'msvs_settings': { 'VCLinkerTool': { 'AdditionalOptions': [ - '/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(node_lib_target_name)<(STATIC_LIB_SUFFIX)', + '/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)', '/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)', ], }, @@ -662,7 +649,7 @@ ['OS != "aix" and OS != "os400" and OS != "mac" and OS != "ios"', { 'ldflags': [ '-Wl,--whole-archive', - '<(obj_dir)/<(STATIC_LIB_PREFIX)<(node_core_target_name)<(STATIC_LIB_SUFFIX)', + '<(obj_dir)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)', '<(obj_dir)/tools/v8_gypfiles/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)', '-Wl,--no-whole-archive', ], @@ -731,57 +718,6 @@ 'LinkIncremental': 2, # enable incremental linking }, }, - }], - ['node_use_node_snapshot=="true"', { - 'dependencies': [ - 'node_mksnapshot', - ], - 'conditions': [ - ['node_snapshot_main!=""', { - 'actions': [ - { - 'action_name': 'node_mksnapshot', - 'process_outputs_as_sources': 1, - 'inputs': [ - '<(node_mksnapshot_exec)', - '<(node_snapshot_main)', - ], - 'outputs': [ - '<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc', - ], - 'action': [ - '<@(emulator)', - '<(node_mksnapshot_exec)', - '--build-snapshot', - '<(node_snapshot_main)', - '<@(_outputs)', - ], - }, - ], - }, { - 'actions': [ - { - 'action_name': 'node_mksnapshot', - 'process_outputs_as_sources': 1, - 'inputs': [ - '<(node_mksnapshot_exec)', - ], - 'outputs': [ - '<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc', - ], - 'action': [ - '<@(emulator)', - '<@(_inputs)', - '<@(_outputs)', - ], - }, - ], - }], - ], - }, { - 'sources': [ - 'src/node_snapshot_stub.cc' - ], }], [ 'OS in "linux freebsd openharmony" and ' 'target_arch=="x64"', { @@ -875,8 +811,8 @@ ], }, # node_core_target_name { - 'target_name': '<(node_lib_target_name)', - 'type': '<(node_intermediate_lib_type)', + 'target_name': 'node_base', + 'type': 'static_library', 'includes': [ 'node.gypi', ], @@ -896,9 +832,6 @@ # Dependency headers 'deps/v8/include/v8.h', 'deps/postject/postject-api.h', - # javascript files to make for an even more pleasant IDE experience - '<@(library_files)', - '<@(deps_files)', # node.gyp is added by default, common.gypi is added for change detection 'common.gypi', ], @@ -942,17 +875,6 @@ }], [ 'node_builtin_modules_path!=""', { 'defines': [ 'NODE_BUILTIN_MODULES_PATH="<(node_builtin_modules_path)"' ], - # When loading builtins from disk, JS source files do not need to - # trigger rebuilds since the binary reads them at runtime. - 'sources!': [ - '<@(library_files)', - '<@(deps_files)', - ], - }], - [ 'node_shared=="true"', { - 'sources': [ - 'src/node_snapshot_stub.cc', - ] }], [ 'node_shared_gtest=="false"', { 'dependencies': [ @@ -974,29 +896,12 @@ '<@(node_sqlite_sources)', ], }], - [ 'node_shared=="true" and node_module_version!="" and OS!="win"', { - 'product_extension': '<(shlib_suffix)', - 'xcode_settings': { - 'LD_DYLIB_INSTALL_NAME': - '@rpath/lib<(node_core_target_name).<(shlib_suffix)' - }, - }], - ['node_shared=="true" and OS in "aix os400"', { - 'product_name': 'node_base', - }], [ 'v8_enable_inspector==1', { 'includes' : [ 'src/inspector/node_inspector.gypi' ], }, { 'defines': [ 'HAVE_INSPECTOR=0' ] }], [ 'OS=="win"', { - 'conditions': [ - [ 'node_intermediate_lib_type!="static_library"', { - 'sources': [ - 'src/res/node.rc', - ], - }], - ], 'libraries': [ 'Dbghelp', 'Psapi', @@ -1071,7 +976,7 @@ [ 'debug_nghttp2==1', { 'defines': [ 'NODE_DEBUG_NGHTTP2=1' ] }], - # Thin LTO for node sources (scoped to libnode, not global) + # Thin LTO for node sources (scoped to node_base, not global) ['node_with_ltcg=="true"', { 'msvs_settings': { 'VCCLCompilerTool': { @@ -1117,6 +1022,142 @@ ], }, ], + }, # node_base + { + 'target_name': '<(node_lib_target_name)', + 'type': '<(node_lib_type)', + 'includes': [ + 'node.gypi', + ], + + 'include_dirs': [ + 'src', + 'deps/v8/include', + 'deps/uv/include', + ], + + 'dependencies': [ + 'node_base', + ], + + 'defines': [ + 'NODE_ARCH="<(target_arch)"', + 'NODE_PLATFORM="<(OS)"', + 'NODE_WANT_INTERNALS=1', + ], + + 'sources': [ + # javascript files to make for an even more pleasant IDE experience + '<@(library_files)', + '<@(deps_files)', + ], + + 'conditions': [ + [ 'node_builtin_modules_path!=""', { + # When loading builtins from disk, JS source files do not need to + # trigger rebuilds since the binary reads them at runtime. + 'sources!': [ + '<@(library_files)', + '<@(deps_files)', + ], + }], + ['node_use_node_snapshot=="true"', { + 'dependencies': [ + 'node_mksnapshot', + ], + 'conditions': [ + ['node_snapshot_main!=""', { + 'actions': [ + { + 'action_name': 'node_mksnapshot', + 'process_outputs_as_sources': 1, + 'inputs': [ + '<(node_mksnapshot_exec)', + '<(node_snapshot_main)', + ], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc', + ], + 'action': [ + '<@(emulator)', + '<(node_mksnapshot_exec)', + '--build-snapshot', + '<(node_snapshot_main)', + '<@(_outputs)', + ], + }, + ], + }, { + 'actions': [ + { + 'action_name': 'node_mksnapshot', + 'process_outputs_as_sources': 1, + 'inputs': [ + '<(node_mksnapshot_exec)', + ], + 'outputs': [ + '<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc', + ], + 'action': [ + '<@(emulator)', + '<@(_inputs)', + '<@(_outputs)', + ], + }, + ], + }], + ], + }, { + 'sources': [ + 'src/node_snapshot_stub.cc' + ], + }], + [ 'node_shared=="true"', { + # Keep this whole-archive section in sync with the `node_exe` target above. + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)', + ], + }, + 'msvs_settings': { + 'VCLinkerTool': { + 'AdditionalOptions': [ + '/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)', + '/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)', + ], + }, + }, + 'conditions': [ + ['node_use_bundled_v8=="true"', { + 'xcode_settings': { + 'OTHER_LDFLAGS': [ + '-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)', + ], + }, + }], + # gyp automatically applies `--whole-archive` to static dependencies of `shared_library` targets. + # No need to add the flags again here. + ], + }], + [ 'node_shared=="true" and node_module_version!="" and OS!="win"', { + 'product_extension': '<(shlib_suffix)', + 'xcode_settings': { + 'LD_DYLIB_INSTALL_NAME': + '@rpath/lib<(node_core_target_name).<(shlib_suffix)' + }, + }], + ['node_shared=="true" and OS in "aix os400"', { + 'ldflags': ['--shared'], + 'direct_dependent_settings': { + 'ldflags': [ '-Wl,-brtl' ], + }, + }], + [ 'node_shared=="true" and OS=="win"', { + 'sources': [ + 'src/res/node.rc', + ], + }], + ], }, # node_lib_target_name { # fuzz_env 'target_name': 'fuzz_env', @@ -1143,7 +1184,6 @@ 'NODE_WANT_INTERNALS=1', ], 'sources': [ - 'src/node_snapshot_stub.cc', 'test/fuzzers/fuzz_env.cc', ], 'conditions': [ @@ -1188,7 +1228,6 @@ 'NODE_WANT_INTERNALS=1', ], 'sources': [ - 'src/node_snapshot_stub.cc', 'test/fuzzers/fuzz_ClientHelloParser.cc', ], 'conditions': [ @@ -1237,7 +1276,6 @@ 'NODE_WANT_INTERNALS=1', ], 'sources': [ - 'src/node_snapshot_stub.cc', 'test/fuzzers/fuzz_strings.cc', ], 'conditions': [ @@ -1417,7 +1455,6 @@ ], 'sources': [ - 'src/node_snapshot_stub.cc', 'test/embedding/embedtest.cc', ], @@ -1549,7 +1586,7 @@ 'type': 'executable', 'dependencies': [ - '<(node_lib_target_name)', + 'node_base', ], 'includes': [ @@ -1635,33 +1672,6 @@ ], # end targets 'conditions': [ - ['OS in "aix os400" and node_shared=="true"', { - 'targets': [ - { - 'target_name': 'node_aix_shared', - 'type': 'shared_library', - 'product_name': '<(node_core_target_name)', - 'ldflags': ['--shared'], - 'product_extension': '<(shlib_suffix)', - 'includes': [ - 'node.gypi' - ], - 'dependencies': ['<(node_lib_target_name)'], - 'include_dirs': [ - 'src', - 'deps/v8/include', - ], - 'sources': [ - '<@(library_files)', - '<@(deps_files)', - 'common.gypi', - ], - 'direct_dependent_settings': { - 'ldflags': [ '-Wl,-brtl' ], - }, - }, - ] - }], # end aix section ['OS=="win" and node_shared=="true"', { 'targets': [ {