Skip to content

Commit fac4309

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

2 files changed

Lines changed: 139 additions & 101 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 & 97 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',
@@ -1071,23 +1008,6 @@
10711008
[ 'node_use_lief=="true" and node_shared_lief=="true"', {
10721009
'defines': [ 'HAVE_LIEF=1' ],
10731010
}],
1074-
[ 'node_use_sqlite=="true"', {
1075-
'sources': [
1076-
'<@(node_sqlite_sources)',
1077-
],
1078-
}],
1079-
[ 'node_use_ffi=="true"', {
1080-
'sources': [
1081-
'<@(node_ffi_sources)',
1082-
],
1083-
'conditions': [
1084-
[ 'node_shared_ffi=="false"', {
1085-
'dependencies': [
1086-
'deps/libffi/libffi.gyp:libffi',
1087-
],
1088-
}],
1089-
],
1090-
}],
10911011
[ 'node_use_quic=="true"', {
10921012
'sources': [
10931013
'<@(node_quic_sources)',
@@ -1155,7 +1075,7 @@
11551075
[ 'debug_nghttp2==1', {
11561076
'defines': [ 'NODE_DEBUG_NGHTTP2=1' ]
11571077
}],
1158-
# Thin LTO for node sources (scoped to libnode, not global)
1078+
# Thin LTO for node sources (scoped to node_base, not global)
11591079
['node_with_ltcg=="true"', {
11601080
'msvs_settings': {
11611081
'VCCLCompilerTool': {
@@ -1200,6 +1120,126 @@
12001120
],
12011121
},
12021122
],
1123+
}, # node_base
1124+
{
1125+
'target_name': '<(node_lib_target_name)',
1126+
'type': '<(node_intermediate_lib_type)',
1127+
'includes': [
1128+
'node.gypi',
1129+
],
1130+
1131+
'include_dirs': [
1132+
'src',
1133+
'deps/v8/include',
1134+
'deps/uv/include',
1135+
],
1136+
1137+
'dependencies': [
1138+
'node_base',
1139+
],
1140+
1141+
'defines': [
1142+
'NODE_ARCH="<(target_arch)"',
1143+
'NODE_PLATFORM="<(OS)"',
1144+
'NODE_WANT_INTERNALS=1',
1145+
],
1146+
1147+
'sources': [
1148+
# javascript files to make for an even more pleasant IDE experience
1149+
'<@(library_files)',
1150+
'<@(deps_files)',
1151+
],
1152+
1153+
'conditions': [
1154+
[ 'node_builtin_modules_path!=""', {
1155+
# When loading builtins from disk, JS source files do not need to
1156+
# trigger rebuilds since the binary reads them at runtime.
1157+
'sources!': [
1158+
'<@(library_files)',
1159+
'<@(deps_files)',
1160+
],
1161+
}],
1162+
['node_use_node_snapshot=="true"', {
1163+
'dependencies': [
1164+
'node_mksnapshot',
1165+
],
1166+
'conditions': [
1167+
['node_snapshot_main!=""', {
1168+
'actions': [
1169+
{
1170+
'action_name': 'node_mksnapshot',
1171+
'process_outputs_as_sources': 1,
1172+
'inputs': [
1173+
'<(node_mksnapshot_exec)',
1174+
'<(node_snapshot_main)',
1175+
],
1176+
'outputs': [
1177+
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
1178+
],
1179+
'action': [
1180+
'<(node_mksnapshot_exec)',
1181+
'--build-snapshot',
1182+
'<(node_snapshot_main)',
1183+
'<@(_outputs)',
1184+
],
1185+
},
1186+
],
1187+
}, {
1188+
'actions': [
1189+
{
1190+
'action_name': 'node_mksnapshot',
1191+
'process_outputs_as_sources': 1,
1192+
'inputs': [
1193+
'<(node_mksnapshot_exec)',
1194+
],
1195+
'outputs': [
1196+
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
1197+
],
1198+
'action': [
1199+
'<@(_inputs)',
1200+
'<@(_outputs)',
1201+
],
1202+
},
1203+
],
1204+
}],
1205+
],
1206+
}, {
1207+
'sources': [
1208+
'src/node_snapshot_stub.cc'
1209+
],
1210+
}],
1211+
[ 'node_shared=="true"', {
1212+
'xcode_settings': {
1213+
'OTHER_LDFLAGS': [
1214+
'-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)',
1215+
],
1216+
},
1217+
'conditions': [
1218+
['OS!="aix" and OS!="os400" and OS!="mac" and OS!="ios"', {
1219+
'ldflags': [
1220+
'-Wl,--whole-archive',
1221+
'<(obj_dir)/<(STATIC_LIB_PREFIX)node_base<(STATIC_LIB_SUFFIX)',
1222+
'-Wl,--no-whole-archive',
1223+
],
1224+
}],
1225+
],
1226+
}],
1227+
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
1228+
'product_extension': '<(shlib_suffix)',
1229+
'xcode_settings': {
1230+
'LD_DYLIB_INSTALL_NAME':
1231+
'@rpath/lib<(node_core_target_name).<(shlib_suffix)'
1232+
},
1233+
}],
1234+
['node_shared=="true" and OS in "aix os400"', {
1235+
'product_name': 'node_base',
1236+
}],
1237+
[ 'node_shared=="true" and OS=="win"', {
1238+
'sources': [
1239+
'src/res/node.rc',
1240+
],
1241+
}],
1242+
],
12031243
}, # node_lib_target_name
12041244
{ # fuzz_env
12051245
'target_name': 'fuzz_env',
@@ -1692,7 +1732,7 @@
16921732
'type': 'executable',
16931733

16941734
'dependencies': [
1695-
'<(node_lib_target_name)',
1735+
'node_base',
16961736
],
16971737

16981738
'includes': [

0 commit comments

Comments
 (0)