Skip to content

Commit e880392

Browse files
committed
build: build codecache and snapshot with libnode
Signed-off-by: Chengzhong Wu <cwu631@bloomberg.net>
1 parent 54f7e89 commit e880392

2 files changed

Lines changed: 139 additions & 84 deletions

File tree

configure.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,17 +1900,15 @@ def configure_node(o):
19001900
if options.without_node_snapshot or options.node_builtin_modules_path:
19011901
o['variables']['node_use_node_snapshot'] = 'false'
19021902
else:
1903-
o['variables']['node_use_node_snapshot'] = b(
1904-
not cross_compiling and not options.shared)
1903+
o['variables']['node_use_node_snapshot'] = b(not cross_compiling)
19051904

19061905
# Do not use code cache when Node.js is built for collecting coverage of itself, this allows more
19071906
# precise coverage for the JS built-ins.
19081907
if options.without_node_code_cache or options.without_node_snapshot or options.node_builtin_modules_path or options.coverage:
19091908
o['variables']['node_use_node_code_cache'] = 'false'
19101909
else:
19111910
# TODO(refack): fix this when implementing embedded code-cache when cross-compiling.
1912-
o['variables']['node_use_node_code_cache'] = b(
1913-
not cross_compiling and not options.shared)
1911+
o['variables']['node_use_node_code_cache'] = b(not cross_compiling)
19141912

19151913
if options.write_snapshot_as_array_literals is not None:
19161914
o['variables']['node_write_snapshot_as_array_literals'] = b(options.write_snapshot_as_array_literals)

node.gyp

Lines changed: 137 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,15 @@
66
'v8_enable_31bit_smis_on_64bit_arch%': 0,
77
'force_dynamic_crt%': 0,
88
'node_builtin_modules_path%': '',
9+
# `node` executable target name.
910
'node_core_target_name%': 'node',
10-
'node_enable_v8_vtunejit%': 'false',
11+
# Derived flag from `node_shared`.
12+
# On most platforms, this is `static_library` if `node_shared` is false and `shared_library` if `node_shared` is true.
13+
# AIX needs to generate static library first and then link to shared library `node_aix_shared`.
14+
# TODO(legendecas): move this to depend on target `node_base` in AIX build .
1115
'node_intermediate_lib_type%': 'static_library',
16+
# `libnode` target name, can be a `static_library` or `shared_library` based on `node_shared`.
17+
# NOTE: Gyp will prefix this with `lib` if this name does not start with `lib`.
1218
'node_lib_target_name%': 'libnode',
1319
'node_module_version%': '',
1420
'node_no_browser_globals%': 'false',
@@ -41,6 +47,7 @@
4147
'node_use_sqlite%': 'true',
4248
'node_use_ffi%': 'false',
4349
'node_use_v8_platform%': 'true',
50+
'node_enable_v8_vtunejit%': 'false',
4451
'node_v8_options%': '',
4552
'node_write_snapshot_as_string_literals': 'true',
4653
'ossfuzz' : 'false',
@@ -670,16 +677,16 @@
670677
}],
671678
],
672679
}],
673-
[ 'node_intermediate_lib_type=="static_library" and node_shared=="false"', {
680+
[ 'node_shared=="false"', {
674681
'xcode_settings': {
675682
'OTHER_LDFLAGS': [
676-
'-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)<(node_core_target_name)<(STATIC_LIB_SUFFIX)',
683+
'-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)',
677684
],
678685
},
679686
'msvs_settings': {
680687
'VCLinkerTool': {
681688
'AdditionalOptions': [
682-
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(node_lib_target_name)<(STATIC_LIB_SUFFIX)',
689+
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)',
683690
'/WHOLEARCHIVE:<(PRODUCT_DIR)/lib/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)',
684691
],
685692
},
@@ -695,15 +702,15 @@
695702
['node_use_bundled_v8=="true" and OS != "aix" and OS != "os400" and OS != "mac" and OS != "ios"', {
696703
'ldflags': [
697704
'-Wl,--whole-archive',
698-
'<(obj_dir)/<(STATIC_LIB_PREFIX)<(node_core_target_name)<(STATIC_LIB_SUFFIX)',
705+
'<(obj_dir)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)',
699706
'<(obj_dir)/tools/v8_gypfiles/<(STATIC_LIB_PREFIX)v8_base_without_compiler<(STATIC_LIB_SUFFIX)',
700707
'-Wl,--no-whole-archive',
701708
],
702709
}],
703710
['node_use_bundled_v8!="true" and OS != "aix" and OS != "os400" and OS != "mac" and OS != "ios"', {
704711
'ldflags': [
705712
'-Wl,--whole-archive',
706-
'<(obj_dir)/<(STATIC_LIB_PREFIX)<(node_core_target_name)<(STATIC_LIB_SUFFIX)',
713+
'<(obj_dir)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)',
707714
'-Wl,--no-whole-archive',
708715
],
709716
}],
@@ -771,55 +778,6 @@
771778
'LinkIncremental': 2, # enable incremental linking
772779
},
773780
},
774-
}],
775-
['node_use_node_snapshot=="true"', {
776-
'dependencies': [
777-
'node_mksnapshot',
778-
],
779-
'conditions': [
780-
['node_snapshot_main!=""', {
781-
'actions': [
782-
{
783-
'action_name': 'node_mksnapshot',
784-
'process_outputs_as_sources': 1,
785-
'inputs': [
786-
'<(node_mksnapshot_exec)',
787-
'<(node_snapshot_main)',
788-
],
789-
'outputs': [
790-
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
791-
],
792-
'action': [
793-
'<(node_mksnapshot_exec)',
794-
'--build-snapshot',
795-
'<(node_snapshot_main)',
796-
'<@(_outputs)',
797-
],
798-
},
799-
],
800-
}, {
801-
'actions': [
802-
{
803-
'action_name': 'node_mksnapshot',
804-
'process_outputs_as_sources': 1,
805-
'inputs': [
806-
'<(node_mksnapshot_exec)',
807-
],
808-
'outputs': [
809-
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
810-
],
811-
'action': [
812-
'<@(_inputs)',
813-
'<@(_outputs)',
814-
],
815-
},
816-
],
817-
}],
818-
],
819-
}, {
820-
'sources': [
821-
'src/node_snapshot_stub.cc'
822-
],
823781
}],
824782
[ 'OS in "linux freebsd openharmony" and '
825783
'target_arch=="x64"', {
@@ -913,8 +871,8 @@
913871
],
914872
}, # node_core_target_name
915873
{
916-
'target_name': '<(node_lib_target_name)',
917-
'type': '<(node_intermediate_lib_type)',
874+
'target_name': 'node_base',
875+
'type': 'static_library',
918876
'includes': [
919877
'node.gypi',
920878
],
@@ -933,9 +891,6 @@
933891
# Dependency headers
934892
'deps/v8/include/v8.h',
935893
'deps/postject/postject-api.h',
936-
# javascript files to make for an even more pleasant IDE experience
937-
'<@(library_files)',
938-
'<@(deps_files)',
939894
# node.gyp is added by default, common.gypi is added for change detection
940895
'common.gypi',
941896
],
@@ -979,17 +934,6 @@
979934
}],
980935
[ 'node_builtin_modules_path!=""', {
981936
'defines': [ 'NODE_BUILTIN_MODULES_PATH="<(node_builtin_modules_path)"' ],
982-
# When loading builtins from disk, JS source files do not need to
983-
# trigger rebuilds since the binary reads them at runtime.
984-
'sources!': [
985-
'<@(library_files)',
986-
'<@(deps_files)',
987-
],
988-
}],
989-
[ 'node_shared=="true"', {
990-
'sources': [
991-
'src/node_snapshot_stub.cc',
992-
]
993937
}],
994938
[ 'node_use_bundled_v8!="false"', {
995939
'dependencies': [ 'tools/v8_gypfiles/abseil.gyp:abseil' ],
@@ -1042,13 +986,6 @@
1042986
'defines': [ 'HAVE_INSPECTOR=0' ]
1043987
}],
1044988
[ 'OS=="win"', {
1045-
'conditions': [
1046-
[ 'node_intermediate_lib_type!="static_library"', {
1047-
'sources': [
1048-
'src/res/node.rc',
1049-
],
1050-
}],
1051-
],
1052989
'libraries': [
1053990
'Dbghelp',
1054991
'Psapi',
@@ -1155,7 +1092,7 @@
11551092
[ 'debug_nghttp2==1', {
11561093
'defines': [ 'NODE_DEBUG_NGHTTP2=1' ]
11571094
}],
1158-
# Thin LTO for node sources (scoped to libnode, not global)
1095+
# Thin LTO for node sources (scoped to node_base, not global)
11591096
['node_with_ltcg=="true"', {
11601097
'msvs_settings': {
11611098
'VCCLCompilerTool': {
@@ -1200,6 +1137,126 @@
12001137
],
12011138
},
12021139
],
1140+
}, # node_base
1141+
{
1142+
'target_name': '<(node_lib_target_name)',
1143+
'type': '<(node_intermediate_lib_type)',
1144+
'includes': [
1145+
'node.gypi',
1146+
],
1147+
1148+
'include_dirs': [
1149+
'src',
1150+
'deps/v8/include',
1151+
'deps/uv/include',
1152+
],
1153+
1154+
'dependencies': [
1155+
'node_base',
1156+
],
1157+
1158+
'defines': [
1159+
'NODE_ARCH="<(target_arch)"',
1160+
'NODE_PLATFORM="<(OS)"',
1161+
'NODE_WANT_INTERNALS=1',
1162+
],
1163+
1164+
'sources': [
1165+
# javascript files to make for an even more pleasant IDE experience
1166+
'<@(library_files)',
1167+
'<@(deps_files)',
1168+
],
1169+
1170+
'conditions': [
1171+
[ 'node_builtin_modules_path!=""', {
1172+
# When loading builtins from disk, JS source files do not need to
1173+
# trigger rebuilds since the binary reads them at runtime.
1174+
'sources!': [
1175+
'<@(library_files)',
1176+
'<@(deps_files)',
1177+
],
1178+
}],
1179+
['node_use_node_snapshot=="true"', {
1180+
'dependencies': [
1181+
'node_mksnapshot',
1182+
],
1183+
'conditions': [
1184+
['node_snapshot_main!=""', {
1185+
'actions': [
1186+
{
1187+
'action_name': 'node_mksnapshot',
1188+
'process_outputs_as_sources': 1,
1189+
'inputs': [
1190+
'<(node_mksnapshot_exec)',
1191+
'<(node_snapshot_main)',
1192+
],
1193+
'outputs': [
1194+
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
1195+
],
1196+
'action': [
1197+
'<(node_mksnapshot_exec)',
1198+
'--build-snapshot',
1199+
'<(node_snapshot_main)',
1200+
'<@(_outputs)',
1201+
],
1202+
},
1203+
],
1204+
}, {
1205+
'actions': [
1206+
{
1207+
'action_name': 'node_mksnapshot',
1208+
'process_outputs_as_sources': 1,
1209+
'inputs': [
1210+
'<(node_mksnapshot_exec)',
1211+
],
1212+
'outputs': [
1213+
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
1214+
],
1215+
'action': [
1216+
'<@(_inputs)',
1217+
'<@(_outputs)',
1218+
],
1219+
},
1220+
],
1221+
}],
1222+
],
1223+
}, {
1224+
'sources': [
1225+
'src/node_snapshot_stub.cc'
1226+
],
1227+
}],
1228+
[ 'node_shared=="true"', {
1229+
'xcode_settings': {
1230+
'OTHER_LDFLAGS': [
1231+
'-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)',
1232+
],
1233+
},
1234+
'conditions': [
1235+
['OS!="aix" and OS!="os400" and OS!="mac" and OS!="ios"', {
1236+
'ldflags': [
1237+
'-Wl,--whole-archive',
1238+
'<(obj_dir)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)',
1239+
'-Wl,--no-whole-archive',
1240+
],
1241+
}],
1242+
],
1243+
}],
1244+
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
1245+
'product_extension': '<(shlib_suffix)',
1246+
'xcode_settings': {
1247+
'LD_DYLIB_INSTALL_NAME':
1248+
'@rpath/lib<(node_core_target_name).<(shlib_suffix)'
1249+
},
1250+
}],
1251+
['node_shared=="true" and OS in "aix os400"', {
1252+
'product_name': 'node_base',
1253+
}],
1254+
[ 'node_shared=="true" and OS=="win"', {
1255+
'sources': [
1256+
'src/res/node.rc',
1257+
],
1258+
}],
1259+
],
12031260
}, # node_lib_target_name
12041261
{ # fuzz_env
12051262
'target_name': 'fuzz_env',
@@ -1692,7 +1749,7 @@
16921749
'type': 'executable',
16931750

16941751
'dependencies': [
1695-
'<(node_lib_target_name)',
1752+
'node_base',
16961753
],
16971754

16981755
'includes': [

0 commit comments

Comments
 (0)