Skip to content

Commit 49d8c2e

Browse files
yhwangMylesBorins
authored andcommittedMar 30, 2018
build: refine static and shared lib build
Refine the static and shared lib build process in order to integrate static and shared lib verfication into CI. When building both static and shared lib, we still build node executable now and it uses the shared and static lib. Signed-off-by: Yihong Wang <[email protected]> Refs: #14158 Backport-PR-URL: #19050 PR-URL: #17604 Reviewed-By: Bartosz Sosnowski <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: Daniel Bevenius <[email protected]>
1 parent 72a5710 commit 49d8c2e

File tree

4 files changed

+479
-251
lines changed

4 files changed

+479
-251
lines changed
 

‎configure

+8-1
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,6 @@ def configure_node(o):
845845
configure_mips(o)
846846

847847
if flavor == 'aix':
848-
o['variables']['node_core_target_name'] = 'node_base'
849848
o['variables']['node_target_type'] = 'static_library'
850849

851850
if target_arch in ('x86', 'x64', 'ia32', 'x32'):
@@ -945,6 +944,13 @@ def configure_node(o):
945944
else:
946945
o['variables']['coverage'] = 'false'
947946

947+
if options.shared:
948+
o['variables']['node_target_type'] = 'shared_library'
949+
elif options.enable_static:
950+
o['variables']['node_target_type'] = 'static_library'
951+
else:
952+
o['variables']['node_target_type'] = 'executable'
953+
948954
def configure_library(lib, output):
949955
shared_lib = 'shared_' + lib
950956
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
@@ -1440,6 +1446,7 @@ config = {
14401446
'BUILDTYPE': 'Debug' if options.debug else 'Release',
14411447
'USE_XCODE': str(int(options.use_xcode or 0)),
14421448
'PYTHON': sys.executable,
1449+
'NODE_TARGET_TYPE': variables['node_target_type'],
14431450
}
14441451

14451452
if options.prefix:

‎node.gyp

+370-72
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
'node_v8_options%': '',
2222
'node_enable_v8_vtunejit%': 'false',
2323
'node_core_target_name%': 'node',
24+
'node_lib_target_name%': 'node_lib',
25+
'node_intermediate_lib_type%': 'static_library',
2426
'library_files': [
2527
'lib/internal/bootstrap_node.js',
2628
'lib/_debug_agent.js',
@@ -111,6 +113,17 @@
111113
'conditions': [
112114
[ 'node_shared=="true"', {
113115
'node_target_type%': 'shared_library',
116+
'conditions': [
117+
['OS=="aix"', {
118+
# For AIX, always generate static library first,
119+
# It needs an extra step to generate exp and
120+
# then use both static lib and exp to create
121+
# shared lib.
122+
'node_intermediate_lib_type': 'static_library',
123+
}, {
124+
'node_intermediate_lib_type': 'shared_library',
125+
}],
126+
],
114127
}, {
115128
'node_target_type%': 'executable',
116129
}],
@@ -127,7 +140,81 @@
127140
'targets': [
128141
{
129142
'target_name': '<(node_core_target_name)',
130-
'type': '<(node_target_type)',
143+
'type': 'executable',
144+
'sources': [
145+
'src/node_main.cc'
146+
],
147+
'include_dirs': [
148+
'src',
149+
'deps/v8/include',
150+
],
151+
'conditions': [
152+
[ 'node_intermediate_lib_type=="static_library" and '
153+
'node_shared=="true" and OS=="aix"', {
154+
# For AIX, shared lib is linked by static lib and .exp. In the
155+
# case here, the executable needs to link to shared lib.
156+
# Therefore, use 'node_aix_shared' target to generate the
157+
# shared lib and then executable.
158+
'dependencies': [ 'node_aix_shared' ],
159+
}, {
160+
'dependencies': [ '<(node_lib_target_name)' ],
161+
}],
162+
[ 'node_intermediate_lib_type=="static_library" and '
163+
'node_shared=="false"', {
164+
'includes': [
165+
'node.gypi'
166+
],
167+
'xcode_settings': {
168+
'OTHER_LDFLAGS': [
169+
'-Wl,-force_load,<(PRODUCT_DIR)/<(STATIC_LIB_PREFIX)'
170+
'<(node_core_target_name)<(STATIC_LIB_SUFFIX)',
171+
],
172+
},
173+
'msvs_settings': {
174+
'VCLinkerTool': {
175+
'AdditionalOptions': [
176+
'/WHOLEARCHIVE:<(PRODUCT_DIR)\\lib\\'
177+
'<(node_core_target_name)<(STATIC_LIB_SUFFIX)',
178+
],
179+
},
180+
},
181+
'conditions': [
182+
['OS in "linux freebsd openbsd solaris android"', {
183+
'ldflags': [
184+
'-Wl,--whole-archive,<(OBJ_DIR)/<(STATIC_LIB_PREFIX)'
185+
'<(node_core_target_name)<(STATIC_LIB_SUFFIX)',
186+
'-Wl,--no-whole-archive',
187+
],
188+
}],
189+
[ 'OS=="win"', {
190+
'sources': [ 'src/res/node.rc' ],
191+
'conditions': [
192+
[ 'node_use_etw=="true"', {
193+
'sources': [
194+
'tools/msvs/genfiles/node_etw_provider.rc'
195+
],
196+
}],
197+
[ 'node_use_perfctr=="true"', {
198+
'sources': [
199+
'tools/msvs/genfiles/node_perfctr_provider.rc',
200+
],
201+
}]
202+
],
203+
}],
204+
],
205+
}],
206+
[ 'node_intermediate_lib_type=="shared_library" and OS=="win"', {
207+
# On Windows, having the same name for both executable and shared
208+
# lib causes filename collision. Need a different PRODUCT_NAME for
209+
# the executable and rename it back to node.exe later
210+
'product_name': '<(node_core_target_name)-win',
211+
}],
212+
],
213+
},
214+
{
215+
'target_name': '<(node_lib_target_name)',
216+
'type': '<(node_intermediate_lib_type)',
217+
'product_name': '<(node_core_target_name)',
131218

132219
'dependencies': [
133220
'node_js2c#host',
@@ -139,7 +226,6 @@
139226

140227
'include_dirs': [
141228
'src',
142-
'tools/msvs/genfiles',
143229
'deps/uv/src/ares',
144230
'<(SHARED_INTERMEDIATE_DIR)',
145231
],
@@ -161,7 +247,6 @@
161247
'src/node_contextify.cc',
162248
'src/node_file.cc',
163249
'src/node_http_parser.cc',
164-
'src/node_main.cc',
165250
'src/node_os.cc',
166251
'src/node_revert.cc',
167252
'src/node_url.cc',
@@ -249,7 +334,168 @@
249334
'conditions': [
250335
[ 'node_shared=="true" and node_module_version!="" and OS!="win"', {
251336
'product_extension': '<(shlib_suffix)',
252-
}]
337+
}],
338+
['node_shared=="true" and OS=="aix"', {
339+
'product_name': 'node_base',
340+
}],
341+
[ 'v8_inspector=="true"', {
342+
'defines': [
343+
'HAVE_INSPECTOR=1',
344+
],
345+
'sources': [
346+
'src/inspector_agent.cc',
347+
'src/inspector_socket.cc',
348+
'src/inspector_agent.h',
349+
'src/inspector_socket.h',
350+
],
351+
'dependencies': [
352+
'deps/v8_inspector/third_party/v8_inspector/platform/'
353+
'v8_inspector/v8_inspector.gyp:v8_inspector_stl',
354+
'deps/v8_inspector/third_party/v8_inspector/platform/'
355+
'v8_inspector/v8_inspector.gyp:protocol_sources_stl',
356+
'v8_inspector_compress_protocol_json#host',
357+
],
358+
'include_dirs': [
359+
'deps/v8_inspector/third_party/v8_inspector',
360+
'<(SHARED_INTERMEDIATE_DIR)/blink', # for inspector
361+
],
362+
}, {
363+
'defines': [ 'HAVE_INSPECTOR=0' ]
364+
}],
365+
[ 'OS=="win"', {
366+
'sources': [
367+
'src/backtrace_win32.cc',
368+
],
369+
'conditions': [
370+
[ 'node_intermediate_lib_type!="static_library"', {
371+
'sources': [
372+
'src/res/node.rc',
373+
],
374+
}],
375+
],
376+
'defines!': [
377+
'NODE_PLATFORM="win"',
378+
],
379+
'defines': [
380+
'FD_SETSIZE=1024',
381+
# we need to use node's preferred "win32" rather than gyp's preferred "win"
382+
'NODE_PLATFORM="win32"',
383+
'_UNICODE=1',
384+
],
385+
'libraries': [ '-lpsapi.lib' ]
386+
}, { # POSIX
387+
'defines': [ '__POSIX__' ],
388+
'sources': [ 'src/backtrace_posix.cc' ],
389+
}],
390+
[ 'node_use_etw=="true"', {
391+
'defines': [ 'HAVE_ETW=1' ],
392+
'dependencies': [ 'node_etw' ],
393+
'include_dirs': [
394+
'src',
395+
'tools/msvs/genfiles',
396+
'<(SHARED_INTERMEDIATE_DIR)' # for node_natives.h
397+
],
398+
'sources': [
399+
'src/node_win32_etw_provider.h',
400+
'src/node_win32_etw_provider-inl.h',
401+
'src/node_win32_etw_provider.cc',
402+
'src/node_dtrace.cc',
403+
'tools/msvs/genfiles/node_etw_provider.h',
404+
],
405+
'conditions': [
406+
['node_intermediate_lib_type != "static_library"', {
407+
'sources': [
408+
'tools/msvs/genfiles/node_etw_provider.rc',
409+
],
410+
}],
411+
],
412+
}],
413+
[ 'node_use_perfctr=="true"', {
414+
'defines': [ 'HAVE_PERFCTR=1' ],
415+
'dependencies': [ 'node_perfctr' ],
416+
'include_dirs': [
417+
'src',
418+
'tools/msvs/genfiles',
419+
'<(SHARED_INTERMEDIATE_DIR)' # for node_natives.h
420+
],
421+
'sources': [
422+
'src/node_win32_perfctr_provider.h',
423+
'src/node_win32_perfctr_provider.cc',
424+
'src/node_counters.cc',
425+
'src/node_counters.h',
426+
],
427+
'conditions': [
428+
['node_intermediate_lib_type != "static_library"', {
429+
'sources': [
430+
'tools/msvs/genfiles/node_perfctr_provider.rc',
431+
],
432+
}],
433+
],
434+
}],
435+
[ 'node_use_lttng=="true"', {
436+
'defines': [ 'HAVE_LTTNG=1' ],
437+
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
438+
'libraries': [ '-llttng-ust' ],
439+
'include_dirs': [
440+
'src',
441+
'tools/msvs/genfiles',
442+
'<(SHARED_INTERMEDIATE_DIR)' # for node_natives.h
443+
],
444+
'sources': [
445+
'src/node_lttng.cc'
446+
],
447+
}],
448+
[ 'node_use_dtrace=="true"', {
449+
'defines': [ 'HAVE_DTRACE=1' ],
450+
'dependencies': [
451+
'node_dtrace_header',
452+
'specialize_node_d',
453+
],
454+
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
455+
#
456+
# DTrace is supported on linux, solaris, mac, and bsd. There are
457+
# three object files associated with DTrace support, but they're
458+
# not all used all the time:
459+
#
460+
# node_dtrace.o all configurations
461+
# node_dtrace_ustack.o not supported on mac and linux
462+
# node_dtrace_provider.o All except OS X. "dtrace -G" is not
463+
# used on OS X.
464+
#
465+
# Note that node_dtrace_provider.cc and node_dtrace_ustack.cc do not
466+
# actually exist. They're listed here to trick GYP into linking the
467+
# corresponding object files into the final "node" executable. These
468+
# object files are generated by "dtrace -G" using custom actions
469+
# below, and the GYP-generated Makefiles will properly build them when
470+
# needed.
471+
#
472+
'sources': [ 'src/node_dtrace.cc' ],
473+
'conditions': [
474+
[ 'OS=="linux"', {
475+
'sources': [
476+
'<(SHARED_INTERMEDIATE_DIR)/node_dtrace_provider.o'
477+
],
478+
}],
479+
[ 'OS!="mac" and OS!="linux"', {
480+
'sources': [
481+
'src/node_dtrace_ustack.cc',
482+
'src/node_dtrace_provider.cc',
483+
]
484+
}
485+
] ]
486+
} ],
487+
[ 'node_use_openssl=="true"', {
488+
'sources': [
489+
'src/node_crypto.cc',
490+
'src/node_crypto_bio.cc',
491+
'src/node_crypto_clienthello.cc',
492+
'src/node_crypto.h',
493+
'src/node_crypto_bio.h',
494+
'src/node_crypto_clienthello.h',
495+
'src/tls_wrap.cc',
496+
'src/tls_wrap.h'
497+
],
498+
}],
253499
],
254500
'direct_dependent_settings': {
255501
'defines': [
@@ -398,7 +644,7 @@
398644
[ 'node_use_dtrace=="false" and node_use_etw=="false"', {
399645
'inputs': [ 'src/notrace_macros.py' ]
400646
}],
401-
['node_use_lttng=="false"', {
647+
[ 'node_use_lttng=="false"', {
402648
'inputs': [ 'src/nolttng_macros.py' ]
403649
}],
404650
[ 'node_use_perfctr=="false"', {
@@ -451,10 +697,10 @@
451697
{
452698
'action_name': 'node_dtrace_provider_o',
453699
'inputs': [
454-
'<(OBJ_DIR)/node/src/node_dtrace.o',
700+
'<(OBJ_DIR)/<(node_lib_target_name)/src/node_dtrace.o',
455701
],
456702
'outputs': [
457-
'<(OBJ_DIR)/node/src/node_dtrace_provider.o'
703+
'<(OBJ_DIR)/<(node_lib_target_name)/src/node_dtrace_provider.o'
458704
],
459705
'action': [ 'dtrace', '-G', '-xnolibs', '-s', 'src/node_provider.d',
460706
'<@(_inputs)', '-o', '<@(_outputs)' ]
@@ -504,7 +750,7 @@
504750
'<(SHARED_INTERMEDIATE_DIR)/v8constants.h'
505751
],
506752
'outputs': [
507-
'<(OBJ_DIR)/node/src/node_dtrace_ustack.o'
753+
'<(OBJ_DIR)/<(node_lib_target_name)/src/node_dtrace_ustack.o'
508754
],
509755
'conditions': [
510756
[ 'target_arch=="ia32" or target_arch=="arm"', {
@@ -551,12 +797,41 @@
551797
} ],
552798
]
553799
},
800+
{
801+
# When using shared lib to build executable in Windows, in order to avoid
802+
# filename collision, the executable name is node-win.exe. Need to rename
803+
# it back to node.exe
804+
'target_name': 'rename_node_bin_win',
805+
'type': 'none',
806+
'dependencies': [
807+
'<(node_core_target_name)',
808+
],
809+
'conditions': [
810+
[ 'OS=="win" and node_intermediate_lib_type=="shared_library"', {
811+
'actions': [
812+
{
813+
'action_name': 'rename_node_bin_win',
814+
'inputs': [
815+
'<(PRODUCT_DIR)/<(node_core_target_name)-win.exe'
816+
],
817+
'outputs': [
818+
'<(PRODUCT_DIR)/<(node_core_target_name).exe',
819+
],
820+
'action': [
821+
'mv', '<@(_inputs)', '<@(_outputs)',
822+
],
823+
},
824+
],
825+
} ],
826+
]
827+
},
554828
{
555829
'target_name': 'cctest',
556830
'type': 'executable',
557831

558832
'dependencies': [
559833
'<(node_core_target_name)',
834+
'rename_node_bin_win',
560835
'deps/gtest/gtest.gyp:gtest',
561836
'node_js2c#host',
562837
'node_dtrace_header',
@@ -565,18 +840,18 @@
565840
],
566841

567842
'variables': {
568-
'OBJ_PATH': '<(OBJ_DIR)/node/src',
569-
'OBJ_GEN_PATH': '<(OBJ_DIR)/node/gen',
843+
'OBJ_PATH': '<(OBJ_DIR)/<(node_lib_target_name)/src',
844+
'OBJ_GEN_PATH': '<(OBJ_DIR)/<(node_lib_target_name)/gen',
570845
'OBJ_SUFFIX': 'o',
571846
'conditions': [
572847
['OS=="win"', {
573-
'OBJ_PATH': '<(OBJ_DIR)/node',
574-
'OBJ_GEN_PATH': '<(OBJ_DIR)/node',
848+
'OBJ_PATH': '<(OBJ_DIR)/<(node_lib_target_name)',
849+
'OBJ_GEN_PATH': '<(OBJ_DIR)/<(node_lib_target_name)',
575850
'OBJ_SUFFIX': 'obj',
576851
}],
577852
['OS=="aix"', {
578-
'OBJ_PATH': '<(OBJ_DIR)/node_base/src',
579-
'OBJ_GEN_PATH': '<(OBJ_DIR)/node_base/gen',
853+
'OBJ_PATH': '<(OBJ_DIR)/<(node_lib_target_name)/src',
854+
'OBJ_GEN_PATH': '<(OBJ_DIR)/<(node_lib_target_name)/gen',
580855
}],
581856
],
582857
},
@@ -628,41 +903,91 @@
628903
'test/cctest/test_url.cc'
629904
],
630905

631-
'sources!': [
632-
'src/node_main.cc'
633-
],
634-
635906
'conditions': [
907+
[ 'node_use_openssl=="true"', {
908+
'conditions': [
909+
['node_target_type!="static_library"', {
910+
'libraries': [
911+
'<(OBJ_PATH)/node_crypto.<(OBJ_SUFFIX)',
912+
'<(OBJ_PATH)/node_crypto_bio.<(OBJ_SUFFIX)',
913+
'<(OBJ_PATH)/node_crypto_clienthello.<(OBJ_SUFFIX)',
914+
'<(OBJ_PATH)/tls_wrap.<(OBJ_SUFFIX)',
915+
],
916+
}],
917+
],
918+
'defines': [
919+
'HAVE_OPENSSL=1',
920+
],
921+
}],
922+
[ 'node_use_perfctr=="true"', {
923+
'defines': [ 'HAVE_PERFCTR=1' ],
924+
'libraries': [
925+
'<(OBJ_PATH)/node_counters.<(OBJ_SUFFIX)',
926+
'<(OBJ_PATH)/node_win32_perfctr_provider.<(OBJ_SUFFIX)',
927+
],
928+
}],
636929
['v8_inspector=="true"', {
637930
'sources': [
638931
'test/cctest/test_inspector_socket.cc',
639932
],
933+
'dependencies': [
934+
'deps/v8_inspector/third_party/v8_inspector/platform/'
935+
'v8_inspector/v8_inspector.gyp:v8_inspector_stl',
936+
'deps/v8_inspector/third_party/v8_inspector/platform/'
937+
'v8_inspector/v8_inspector.gyp:protocol_sources_stl',
938+
'v8_inspector_compress_protocol_json#host',
939+
],
940+
'include_dirs': [
941+
'deps/v8_inspector/third_party/v8_inspector',
942+
'<(SHARED_INTERMEDIATE_DIR)/blink', # for inspector
943+
],
944+
'libraries': [
945+
'<(OBJ_PATH)/inspector_agent.<(OBJ_SUFFIX)',
946+
'<(OBJ_PATH)/inspector_socket.<(OBJ_SUFFIX)',
947+
],
640948
'conditions': [
641949
[ 'node_shared_openssl=="false" and node_shared=="false"', {
642950
'dependencies': [
643951
'deps/openssl/openssl.gyp:openssl'
644952
]
645953
}],
646-
[ 'node_shared_http_parser=="false"', {
647-
'dependencies': [
648-
'deps/http_parser/http_parser.gyp:http_parser'
954+
]
955+
}],
956+
[ 'node_use_dtrace=="true"', {
957+
'libraries': [
958+
'<(OBJ_PATH)/node_dtrace.<(OBJ_SUFFIX)',
959+
],
960+
'conditions': [
961+
['OS!="mac" and OS!="linux"', {
962+
'libraries': [
963+
'<(OBJ_PATH)/node_dtrace_provider.<(OBJ_SUFFIX)',
964+
'<(OBJ_PATH)/node_dtrace_ustack.<(OBJ_SUFFIX)',
649965
]
650966
}],
651-
[ 'node_shared_libuv=="false"', {
652-
'dependencies': [
653-
'deps/uv/uv.gyp:libuv'
967+
['OS=="linux"', {
968+
'libraries': [
969+
'<(SHARED_INTERMEDIATE_DIR)/node_dtrace_provider.<(OBJ_SUFFIX)',
654970
]
971+
}],
972+
],
973+
}, {
974+
'conditions': [
975+
[ 'node_use_etw=="true" and OS=="win"', {
976+
'libraries': [
977+
'<(OBJ_PATH)/node_dtrace.<(OBJ_SUFFIX)',
978+
'<(OBJ_PATH)/node_win32_etw_provider.<(OBJ_SUFFIX)',
979+
],
655980
}]
656981
]
657982
}],
658-
[ 'node_use_dtrace=="true" and OS!="mac" and OS!="linux"', {
659-
'copies': [{
660-
'destination': '<(OBJ_DIR)/cctest/src',
661-
'files': [
662-
'<(OBJ_PATH)/node_dtrace_ustack.<(OBJ_SUFFIX)',
663-
'<(OBJ_PATH)/node_dtrace_provider.<(OBJ_SUFFIX)',
664-
'<(OBJ_PATH)/node_dtrace.<(OBJ_SUFFIX)',
665-
]},
983+
[ 'OS=="win"', {
984+
'libraries': [
985+
'<(OBJ_PATH)/backtrace_win32.<(OBJ_SUFFIX)',
986+
],
987+
}, { # POSIX
988+
'defines': [ '__POSIX__' ],
989+
'libraries': [
990+
'<(OBJ_PATH)/backtrace_posix.<(OBJ_SUFFIX)',
666991
],
667992
}],
668993
['OS=="solaris"', {
@@ -673,21 +998,19 @@
673998
], # end targets
674999

6751000
'conditions': [
676-
['OS=="aix"', {
1001+
[ 'OS=="aix" and node_shared=="true"', {
6771002
'targets': [
6781003
{
679-
'target_name': 'node',
1004+
'target_name': 'node_aix_shared',
1005+
'type': 'shared_library',
1006+
'product_name': '<(node_core_target_name)',
1007+
'ldflags': [ '--shared' ],
1008+
'product_extension': '<(shlib_suffix)',
6801009
'conditions': [
681-
['node_shared=="true"', {
682-
'type': 'shared_library',
683-
'ldflags': ['--shared'],
684-
'product_extension': '<(shlib_suffix)',
685-
}, {
686-
'type': 'executable',
687-
}],
6881010
['target_arch=="ppc64"', {
6891011
'ldflags': [
690-
'-Wl,-blibpath:/usr/lib:/lib:/opt/freeware/lib/pthread/ppc64'
1012+
'-Wl,-blibpath:/usr/lib:/lib:'
1013+
'/opt/freeware/lib/pthread/ppc64'
6911014
],
6921015
}],
6931016
['target_arch=="ppc"', {
@@ -696,45 +1019,20 @@
6961019
],
6971020
}]
6981021
],
699-
'dependencies': ['<(node_core_target_name)', 'node_exp'],
700-
1022+
'includes': [
1023+
'node.gypi'
1024+
],
1025+
'dependencies': [ '<(node_lib_target_name)' ],
7011026
'include_dirs': [
7021027
'src',
7031028
'deps/v8/include',
7041029
],
705-
7061030
'sources': [
707-
'src/node_main.cc',
7081031
'<@(library_files)',
709-
# node.gyp is added to the project by default.
7101032
'common.gypi',
7111033
],
712-
713-
'ldflags': ['-Wl,-bE:<(PRODUCT_DIR)/node.exp'],
7141034
},
715-
{
716-
'target_name': 'node_exp',
717-
'type': 'none',
718-
'dependencies': [
719-
'<(node_core_target_name)',
720-
],
721-
'actions': [
722-
{
723-
'action_name': 'expfile',
724-
'inputs': [
725-
'<(OBJ_DIR)'
726-
],
727-
'outputs': [
728-
'<(PRODUCT_DIR)/node.exp'
729-
],
730-
'action': [
731-
'sh', 'tools/create_expfile.sh',
732-
'<@(_inputs)', '<@(_outputs)'
733-
],
734-
}
735-
]
736-
}
737-
], # end targets
1035+
]
7381036
}], # end aix section
7391037
], # end conditions block
7401038
}

‎node.gypi

+100-178
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,29 @@
11
{
2+
# 'force_load' means to include the static libs into the shared lib or
3+
# executable. Therefore, it is enabled when building:
4+
# 1. The executable and it uses static lib (cctest and node)
5+
# 2. The shared lib
6+
# Linker optimizes out functions that are not used. When force_load=true,
7+
# --whole-archive,force_load and /WHOLEARCHIVE are used to include
8+
# all obj files in static libs into the executable or shared lib.
9+
'variables': {
10+
'variables': {
11+
'variables': {
12+
'force_load%': 'true',
13+
'current_type%': '<(_type)',
14+
},
15+
'force_load%': '<(force_load)',
16+
'conditions': [
17+
['current_type=="static_library"', {
18+
'force_load': 'false',
19+
}],
20+
[ 'current_type=="executable" and node_target_type=="shared_library"', {
21+
'force_load': 'false',
22+
}]
23+
],
24+
},
25+
'force_load%': '<(force_load)',
26+
},
227
'conditions': [
328
[ 'node_shared=="false"', {
429
'msvs_settings': {
@@ -36,12 +61,6 @@
3661
[ 'node_v8_options!=""', {
3762
'defines': [ 'NODE_V8_OPTIONS="<(node_v8_options)"'],
3863
}],
39-
# No node_main.cc for anything except executable
40-
[ 'node_target_type!="executable"', {
41-
'sources!': [
42-
'src/node_main.cc',
43-
],
44-
}],
4564
[ 'node_release_urlbase!=""', {
4665
'defines': [
4766
'NODE_RELEASE_URLBASE="<(node_release_urlbase)"',
@@ -66,164 +85,14 @@
6685
'deps/v8/src/third_party/vtune/v8vtune.gyp:v8_vtune'
6786
],
6887
}],
69-
['v8_inspector=="true"', {
70-
'defines': [
71-
'HAVE_INSPECTOR=1',
72-
],
73-
'sources': [
74-
'src/inspector_agent.cc',
75-
'src/inspector_socket.cc',
76-
'src/inspector_agent.h',
77-
'src/inspector_socket.h',
78-
],
79-
'dependencies': [
80-
'deps/v8_inspector/third_party/v8_inspector/platform/'
81-
'v8_inspector/v8_inspector.gyp:v8_inspector_stl',
82-
'v8_inspector_compress_protocol_json#host',
83-
],
84-
'include_dirs': [
85-
'deps/v8_inspector/third_party/v8_inspector',
86-
'<(SHARED_INTERMEDIATE_DIR)/blink', # for inspector
87-
],
88-
}, {
89-
'defines': [ 'HAVE_INSPECTOR=0' ]
90-
}],
91-
[ 'node_use_openssl=="true"', {
92-
'defines': [ 'HAVE_OPENSSL=1' ],
93-
'sources': [
94-
'src/node_crypto.cc',
95-
'src/node_crypto_bio.cc',
96-
'src/node_crypto_clienthello.cc',
97-
'src/node_crypto.h',
98-
'src/node_crypto_bio.h',
99-
'src/node_crypto_clienthello.h',
100-
'src/tls_wrap.cc',
101-
'src/tls_wrap.h'
102-
],
103-
'conditions': [
104-
['openssl_fips != ""', {
105-
'defines': [ 'NODE_FIPS_MODE' ],
106-
}],
107-
[ 'node_shared_openssl=="false"', {
108-
'dependencies': [
109-
'./deps/openssl/openssl.gyp:openssl',
110-
111-
# For tests
112-
'./deps/openssl/openssl.gyp:openssl-cli',
113-
],
114-
# Do not let unused OpenSSL symbols to slip away
115-
'conditions': [
116-
# -force_load or --whole-archive are not applicable for
117-
# the static library
118-
[ 'node_target_type!="static_library"', {
119-
'xcode_settings': {
120-
'OTHER_LDFLAGS': [
121-
'-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)',
122-
],
123-
},
124-
'conditions': [
125-
['OS in "linux freebsd" and node_shared=="false"', {
126-
'ldflags': [
127-
'-Wl,--whole-archive,'
128-
'<(OBJ_DIR)/deps/openssl/'
129-
'<(OPENSSL_PRODUCT)',
130-
'-Wl,--no-whole-archive',
131-
],
132-
}],
133-
# openssl.def is based on zlib.def, zlib symbols
134-
# are always exported.
135-
['use_openssl_def==1', {
136-
'sources': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'],
137-
}],
138-
['OS=="win" and use_openssl_def==0', {
139-
'sources': ['deps/zlib/win32/zlib.def'],
140-
}],
141-
],
142-
}],
143-
],
144-
}]]
145-
}, {
146-
'defines': [ 'HAVE_OPENSSL=0' ]
147-
}],
148-
[ 'node_use_dtrace=="true"', {
149-
'defines': [ 'HAVE_DTRACE=1' ],
150-
'dependencies': [
151-
'node_dtrace_header',
152-
'specialize_node_d',
153-
],
154-
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
155-
156-
#
157-
# DTrace is supported on linux, solaris, mac, and bsd. There are
158-
# three object files associated with DTrace support, but they're
159-
# not all used all the time:
160-
#
161-
# node_dtrace.o all configurations
162-
# node_dtrace_ustack.o not supported on mac and linux
163-
# node_dtrace_provider.o All except OS X. "dtrace -G" is not
164-
# used on OS X.
165-
#
166-
# Note that node_dtrace_provider.cc and node_dtrace_ustack.cc do not
167-
# actually exist. They're listed here to trick GYP into linking the
168-
# corresponding object files into the final "node" executable. These
169-
# object files are generated by "dtrace -G" using custom actions
170-
# below, and the GYP-generated Makefiles will properly build them when
171-
# needed.
172-
#
173-
'sources': [ 'src/node_dtrace.cc' ],
174-
'conditions': [
175-
[ 'OS=="linux"', {
176-
'sources': [
177-
'<(SHARED_INTERMEDIATE_DIR)/node_dtrace_provider.o'
178-
],
179-
}],
180-
[ 'OS!="mac" and OS!="linux"', {
181-
'sources': [
182-
'src/node_dtrace_ustack.cc',
183-
'src/node_dtrace_provider.cc',
184-
]
185-
}
186-
] ]
187-
} ],
188-
[ 'node_use_lttng=="true"', {
189-
'defines': [ 'HAVE_LTTNG=1' ],
190-
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
191-
'libraries': [ '-llttng-ust' ],
192-
'sources': [
193-
'src/node_lttng.cc'
194-
],
195-
} ],
196-
[ 'node_use_etw=="true"', {
197-
'defines': [ 'HAVE_ETW=1' ],
198-
'dependencies': [ 'node_etw' ],
199-
'sources': [
200-
'src/node_win32_etw_provider.h',
201-
'src/node_win32_etw_provider-inl.h',
202-
'src/node_win32_etw_provider.cc',
203-
'src/node_dtrace.cc',
204-
'tools/msvs/genfiles/node_etw_provider.h',
205-
'tools/msvs/genfiles/node_etw_provider.rc',
206-
]
207-
} ],
208-
[ 'node_use_perfctr=="true"', {
209-
'defines': [ 'HAVE_PERFCTR=1' ],
210-
'dependencies': [ 'node_perfctr' ],
211-
'sources': [
212-
'src/node_win32_perfctr_provider.h',
213-
'src/node_win32_perfctr_provider.cc',
214-
'src/node_counters.cc',
215-
'src/node_counters.h',
216-
'tools/msvs/genfiles/node_perfctr_provider.rc',
217-
]
218-
} ],
21988
[ 'node_no_browser_globals=="true"', {
22089
'defines': [ 'NODE_NO_BROWSER_GLOBALS' ],
22190
} ],
22291
[ 'node_use_bundled_v8=="true" and v8_postmortem_support=="true"', {
22392
'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:postmortem-metadata' ],
22493
'conditions': [
22594
# -force_load is not applicable for the static library
226-
[ 'node_target_type!="static_library"', {
95+
[ 'force_load=="true"', {
22796
'xcode_settings': {
22897
'OTHER_LDFLAGS': [
22998
'-Wl,-force_load,<(V8_BASE)',
@@ -248,25 +117,6 @@
248117
'dependencies': [ 'deps/uv/uv.gyp:libuv' ],
249118
}],
250119

251-
[ 'OS=="win"', {
252-
'sources': [
253-
'src/backtrace_win32.cc',
254-
'src/res/node.rc',
255-
],
256-
'defines!': [
257-
'NODE_PLATFORM="win"',
258-
],
259-
'defines': [
260-
'FD_SETSIZE=1024',
261-
# we need to use node's preferred "win32" rather than gyp's preferred "win"
262-
'NODE_PLATFORM="win32"',
263-
'_UNICODE=1',
264-
],
265-
'libraries': [ '-lpsapi.lib' ]
266-
}, { # POSIX
267-
'defines': [ '__POSIX__' ],
268-
'sources': [ 'src/backtrace_posix.cc' ],
269-
}],
270120
[ 'OS=="mac"', {
271121
# linking Corefoundation is needed since certain OSX debugging tools
272122
# like Instruments require it for some features
@@ -289,6 +139,27 @@
289139
'defines': [
290140
'_LINUX_SOURCE_COMPAT',
291141
],
142+
'conditions': [
143+
[ 'force_load=="true"', {
144+
145+
'actions': [
146+
{
147+
'action_name': 'expfile',
148+
'inputs': [
149+
'<(OBJ_DIR)'
150+
],
151+
'outputs': [
152+
'<(PRODUCT_DIR)/node.exp'
153+
],
154+
'action': [
155+
'sh', 'tools/create_expfile.sh',
156+
'<@(_inputs)', '<@(_outputs)'
157+
],
158+
}
159+
],
160+
'ldflags': ['-Wl,-bE:<(PRODUCT_DIR)/node.exp', '-Wl,-brtl'],
161+
}],
162+
],
292163
}],
293164
[ 'OS=="solaris"', {
294165
'libraries': [
@@ -304,12 +175,14 @@
304175
'NODE_PLATFORM="sunos"',
305176
],
306177
}],
307-
[ '(OS=="freebsd" or OS=="linux") and node_shared=="false" and coverage=="false"', {
178+
[ '(OS=="freebsd" or OS=="linux") and node_shared=="false"'
179+
' and coverage=="false" and force_load=="true"', {
308180
'ldflags': [ '-Wl,-z,noexecstack',
309181
'-Wl,--whole-archive <(V8_BASE)',
310182
'-Wl,--no-whole-archive' ]
311183
}],
312-
[ '(OS=="freebsd" or OS=="linux") and node_shared=="false" and coverage=="true"', {
184+
[ '(OS=="freebsd" or OS=="linux") and node_shared=="false"'
185+
' and coverage=="true" and force_load=="true"', {
313186
'ldflags': [ '-Wl,-z,noexecstack',
314187
'-Wl,--whole-archive <(V8_BASE)',
315188
'-Wl,--no-whole-archive',
@@ -324,5 +197,54 @@
324197
[ 'OS=="sunos"', {
325198
'ldflags': [ '-Wl,-M,/usr/lib/ld/map.noexstk' ],
326199
}],
200+
201+
[ 'node_use_openssl=="true"', {
202+
'defines': [ 'HAVE_OPENSSL=1' ],
203+
'conditions': [
204+
['openssl_fips != ""', {
205+
'defines': [ 'NODE_FIPS_MODE' ],
206+
}],
207+
[ 'node_shared_openssl=="false"', {
208+
'dependencies': [
209+
'./deps/openssl/openssl.gyp:openssl',
210+
211+
# For tests
212+
'./deps/openssl/openssl.gyp:openssl-cli',
213+
],
214+
'conditions': [
215+
# -force_load or --whole-archive are not applicable for
216+
# the static library
217+
[ 'force_load=="true"', {
218+
'xcode_settings': {
219+
'OTHER_LDFLAGS': [
220+
'-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)',
221+
],
222+
},
223+
'conditions': [
224+
['OS in "linux freebsd" and node_shared=="false"', {
225+
'ldflags': [
226+
'-Wl,--whole-archive,'
227+
'<(OBJ_DIR)/deps/openssl/'
228+
'<(OPENSSL_PRODUCT)',
229+
'-Wl,--no-whole-archive',
230+
],
231+
}],
232+
# openssl.def is based on zlib.def, zlib symbols
233+
# are always exported.
234+
['use_openssl_def==1', {
235+
'sources': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'],
236+
}],
237+
['OS=="win" and use_openssl_def==0', {
238+
'sources': ['deps/zlib/win32/zlib.def'],
239+
}],
240+
],
241+
}],
242+
],
243+
}]]
244+
245+
}, {
246+
'defines': [ 'HAVE_OPENSSL=0' ]
247+
}],
248+
327249
],
328250
}

‎src/node_main.cc

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "node.h"
22

33
#ifdef _WIN32
4+
#include <windows.h>
45
#include <VersionHelpers.h>
56

67
int wmain(int argc, wchar_t *wargv[]) {

0 commit comments

Comments
 (0)
Please sign in to comment.