Skip to content

Commit f81c622

Browse files
yhwangevanlucas
authored andcommittedJan 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 <yh.wang@ibm.com> Fixes: #14158 PR-URL: #17604 Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
1 parent 2c4e021 commit f81c622

File tree

5 files changed

+358
-298
lines changed

5 files changed

+358
-298
lines changed
 

‎configure

+8-1
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,6 @@ def configure_node(o):
878878
configure_mips(o)
879879

880880
if flavor == 'aix':
881-
o['variables']['node_core_target_name'] = 'node_base'
882881
o['variables']['node_target_type'] = 'static_library'
883882

884883
if target_arch in ('x86', 'x64', 'ia32', 'x32'):
@@ -988,6 +987,13 @@ def configure_node(o):
988987
else:
989988
o['variables']['coverage'] = 'false'
990989

990+
if options.shared:
991+
o['variables']['node_target_type'] = 'shared_library'
992+
elif options.enable_static:
993+
o['variables']['node_target_type'] = 'static_library'
994+
else:
995+
o['variables']['node_target_type'] = 'executable'
996+
991997
def configure_library(lib, output):
992998
shared_lib = 'shared_' + lib
993999
output['variables']['node_' + shared_lib] = b(getattr(options, shared_lib))
@@ -1484,6 +1490,7 @@ config = {
14841490
'BUILDTYPE': 'Debug' if options.debug else 'Release',
14851491
'USE_XCODE': str(int(options.use_xcode or 0)),
14861492
'PYTHON': sys.executable,
1493+
'NODE_TARGET_TYPE': variables['node_target_type'],
14871494
}
14881495

14891496
if options.prefix:

‎node.gyp

+250-233
Large diffs are not rendered by default.

‎node.gypi

+100-40
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)"',
@@ -70,45 +89,14 @@
7089
'deps/v8/src/third_party/vtune/v8vtune.gyp:v8_vtune'
7190
],
7291
}],
73-
[ 'node_use_lttng=="true"', {
74-
'defines': [ 'HAVE_LTTNG=1' ],
75-
'include_dirs': [ '<(SHARED_INTERMEDIATE_DIR)' ],
76-
'libraries': [ '-llttng-ust' ],
77-
'sources': [
78-
'src/node_lttng.cc'
79-
],
80-
} ],
81-
[ 'node_use_etw=="true" and node_target_type!="static_library"', {
82-
'defines': [ 'HAVE_ETW=1' ],
83-
'dependencies': [ 'node_etw' ],
84-
'sources': [
85-
'src/node_win32_etw_provider.h',
86-
'src/node_win32_etw_provider-inl.h',
87-
'src/node_win32_etw_provider.cc',
88-
'src/node_dtrace.cc',
89-
'tools/msvs/genfiles/node_etw_provider.h',
90-
'tools/msvs/genfiles/node_etw_provider.rc',
91-
]
92-
} ],
93-
[ 'node_use_perfctr=="true" and node_target_type!="static_library"', {
94-
'defines': [ 'HAVE_PERFCTR=1' ],
95-
'dependencies': [ 'node_perfctr' ],
96-
'sources': [
97-
'src/node_win32_perfctr_provider.h',
98-
'src/node_win32_perfctr_provider.cc',
99-
'src/node_counters.cc',
100-
'src/node_counters.h',
101-
'tools/msvs/genfiles/node_perfctr_provider.rc',
102-
]
103-
} ],
10492
[ 'node_no_browser_globals=="true"', {
10593
'defines': [ 'NODE_NO_BROWSER_GLOBALS' ],
10694
} ],
10795
[ 'node_use_bundled_v8=="true" and v8_postmortem_support=="true"', {
10896
'dependencies': [ 'deps/v8/src/v8.gyp:postmortem-metadata' ],
10997
'conditions': [
11098
# -force_load is not applicable for the static library
111-
[ 'node_target_type!="static_library"', {
99+
[ 'force_load=="true"', {
112100
'xcode_settings': {
113101
'OTHER_LDFLAGS': [
114102
'-Wl,-force_load,<(V8_BASE)',
@@ -159,6 +147,27 @@
159147
'defines': [
160148
'_LINUX_SOURCE_COMPAT',
161149
],
150+
'conditions': [
151+
[ 'force_load=="true"', {
152+
153+
'actions': [
154+
{
155+
'action_name': 'expfile',
156+
'inputs': [
157+
'<(OBJ_DIR)'
158+
],
159+
'outputs': [
160+
'<(PRODUCT_DIR)/node.exp'
161+
],
162+
'action': [
163+
'sh', 'tools/create_expfile.sh',
164+
'<@(_inputs)', '<@(_outputs)'
165+
],
166+
}
167+
],
168+
'ldflags': ['-Wl,-bE:<(PRODUCT_DIR)/node.exp', '-Wl,-brtl'],
169+
}],
170+
],
162171
}],
163172
[ 'OS=="solaris"', {
164173
'libraries': [
@@ -174,12 +183,14 @@
174183
'NODE_PLATFORM="sunos"',
175184
],
176185
}],
177-
[ '(OS=="freebsd" or OS=="linux") and node_shared=="false" and coverage=="false"', {
186+
[ '(OS=="freebsd" or OS=="linux") and node_shared=="false"'
187+
' and coverage=="false" and force_load=="true"', {
178188
'ldflags': [ '-Wl,-z,noexecstack',
179189
'-Wl,--whole-archive <(V8_BASE)',
180190
'-Wl,--no-whole-archive' ]
181191
}],
182-
[ '(OS=="freebsd" or OS=="linux") and node_shared=="false" and coverage=="true"', {
192+
[ '(OS=="freebsd" or OS=="linux") and node_shared=="false"'
193+
' and coverage=="true" and force_load=="true"', {
183194
'ldflags': [ '-Wl,-z,noexecstack',
184195
'-Wl,--whole-archive <(V8_BASE)',
185196
'-Wl,--no-whole-archive',
@@ -206,5 +217,54 @@
206217
[ 'OS=="sunos"', {
207218
'ldflags': [ '-Wl,-M,/usr/lib/ld/map.noexstk' ],
208219
}],
220+
221+
[ 'node_use_openssl=="true"', {
222+
'defines': [ 'HAVE_OPENSSL=1' ],
223+
'conditions': [
224+
['openssl_fips != ""', {
225+
'defines': [ 'NODE_FIPS_MODE' ],
226+
}],
227+
[ 'node_shared_openssl=="false"', {
228+
'dependencies': [
229+
'./deps/openssl/openssl.gyp:openssl',
230+
231+
# For tests
232+
'./deps/openssl/openssl.gyp:openssl-cli',
233+
],
234+
'conditions': [
235+
# -force_load or --whole-archive are not applicable for
236+
# the static library
237+
[ 'force_load=="true"', {
238+
'xcode_settings': {
239+
'OTHER_LDFLAGS': [
240+
'-Wl,-force_load,<(PRODUCT_DIR)/<(OPENSSL_PRODUCT)',
241+
],
242+
},
243+
'conditions': [
244+
['OS in "linux freebsd" and node_shared=="false"', {
245+
'ldflags': [
246+
'-Wl,--whole-archive,'
247+
'<(OBJ_DIR)/deps/openssl/'
248+
'<(OPENSSL_PRODUCT)',
249+
'-Wl,--no-whole-archive',
250+
],
251+
}],
252+
# openssl.def is based on zlib.def, zlib symbols
253+
# are always exported.
254+
['use_openssl_def==1', {
255+
'sources': ['<(SHARED_INTERMEDIATE_DIR)/openssl.def'],
256+
}],
257+
['OS=="win" and use_openssl_def==0', {
258+
'sources': ['deps/zlib/win32/zlib.def'],
259+
}],
260+
],
261+
}],
262+
],
263+
}]]
264+
265+
}, {
266+
'defines': [ 'HAVE_OPENSSL=0' ]
267+
}],
268+
209269
],
210270
}

‎test/addons/openssl-binding/binding.gyp

-11
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
11
{
2-
'includes': ['../../../config.gypi'],
3-
'variables': {
4-
'node_target_type%': '',
5-
},
62
'targets': [
73
{
84
'target_name': 'binding',
95
'conditions': [
106
['node_use_openssl=="true"', {
117
'sources': ['binding.cc'],
128
'include_dirs': ['../../../deps/openssl/openssl/include'],
13-
'conditions': [
14-
['OS=="win" and node_target_type=="static_library"', {
15-
'libraries': [
16-
'../../../../$(Configuration)/lib/<(OPENSSL_PRODUCT)'
17-
],
18-
}],
19-
],
209
}]
2110
]
2211
},

‎test/addons/zlib-binding/binding.gyp

-13
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,9 @@
11
{
2-
'includes': ['../../../config.gypi'],
3-
'variables': {
4-
'node_target_type%': '',
5-
},
62
'targets': [
73
{
84
'target_name': 'binding',
95
'sources': ['binding.cc'],
106
'include_dirs': ['../../../deps/zlib'],
11-
'conditions': [
12-
['node_target_type=="static_library"', {
13-
'conditions': [
14-
['OS=="win"', {
15-
'libraries': ['../../../../$(Configuration)/lib/zlib.lib'],
16-
}],
17-
],
18-
}],
19-
],
207
},
218
]
229
}

0 commit comments

Comments
 (0)
Please sign in to comment.