8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 86e07b7 commit 410296cCopy full SHA for 410296c
common.gypi
@@ -11,6 +11,11 @@
11
'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way
12
'python%': 'python',
13
14
+ 'node_shared%': 'false',
15
+ 'node_use_v8_platform%': 'true',
16
+ 'node_use_bundled_v8%': 'true',
17
+ 'node_module_version%': '',
18
+
19
'node_tag%': '',
20
'uv_library%': 'static_library',
21
@@ -290,6 +295,9 @@
290
295
],
291
296
'ldflags!': [ '-rdynamic' ],
292
297
}],
298
+ [ 'node_shared=="true"', {
299
+ 'cflags': [ '-fPIC' ],
300
+ }],
293
301
294
302
303
[ 'OS=="android"', {
configure
@@ -24,6 +24,10 @@ from gyp.common import GetFlavor
24
sys.path.insert(0, os.path.join(root_dir, 'tools', 'configure.d'))
25
import nodedownload
26
27
+# imports in tools/
28
+sys.path.insert(0, os.path.join(root_dir, 'tools'))
29
+import getmoduleversion
30
31
# parse our options
32
parser = optparse.OptionParser()
33
@@ -420,6 +424,26 @@ parser.add_option('--without-inspector',
420
424
dest='without_inspector',
421
425
help='disable experimental V8 inspector support')
422
426
427
+parser.add_option('--shared',
428
+ action='store_true',
429
+ dest='shared',
430
+ help='compile shared library for embedding node in another project. ' +
431
+ '(This mode is not officially supported for regular applications)')
432
433
+parser.add_option('--without-v8-platform',
434
435
+ dest='without_v8_platform',
436
+ default=False,
437
+ help='do not initialize v8 platform during node.js startup. ' +
438
439
440
+parser.add_option('--without-bundled-v8',
441
442
+ dest='without_bundled_v8',
443
444
+ help='do not use V8 includes from the bundled deps folder. ' +
445
446
423
447
(options, args) = parser.parse_args()
448
449
# Expand ~ in the install prefix now, it gets written to multiple files.
@@ -810,6 +834,10 @@ def configure_node(o):
810
834
o['variables']['node_target_type'] = 'static_library'
811
835
812
836
o['variables']['node_no_browser_globals'] = b(options.no_browser_globals)
837
+ o['variables']['node_shared'] = b(options.shared)
838
+ o['variables']['node_use_v8_platform'] = b(not options.without_v8_platform)
839
+ o['variables']['node_use_bundled_v8'] = b(not options.without_bundled_v8)
840
+ o['variables']['node_module_version'] = int(getmoduleversion.get_version())
813
841
814
842
if options.linked_module:
815
843
o['variables']['library_files'] = options.linked_module
node.gyp
@@ -6,6 +6,10 @@
6
'node_use_etw%': 'false',
7
'node_use_perfctr%': 'false',
8
'node_no_browser_globals%': 'false',
9
10
'node_shared_zlib%': 'false',
'node_shared_http_parser%': 'false',
'node_shared_cares%': 'false',
@@ -14,7 +18,6 @@
'node_shared_openssl%': 'false',
'node_v8_options%': '',
'node_enable_v8_vtunejit%': 'false',
- 'node_target_type%': 'executable',
'node_core_target_name%': 'node',
22
'library_files': [
23
'lib/internal/bootstrap_node.js',
@@ -100,6 +103,13 @@
100
103
'deps/v8/tools/SourceMap.js',
101
104
'deps/v8/tools/tickprocessor-driver.js',
102
105
106
+ 'conditions': [
107
108
+ 'node_target_type%': 'shared_library',
109
+ }, {
110
+ 'node_target_type%': 'executable',
111
112
+ ],
113
},
114
115
'targets': [
@@ -109,16 +119,13 @@
119
120
'dependencies': [
121
'node_js2c#host',
- 'deps/v8/tools/gyp/v8.gyp:v8',
- 'deps/v8/tools/gyp/v8.gyp:v8_libplatform'
122
123
116
124
'include_dirs': [
117
125
'src',
118
126
'tools/msvs/genfiles',
127
'deps/uv/src/ares',
128
'<(SHARED_INTERMEDIATE_DIR)', # for node_natives.h
- 'deps/v8' # include/v8_platform.h
129
130
131
'sources': [
@@ -217,6 +224,42 @@
217
224
218
225
219
226
'conditions': [
227
+ [ 'node_shared=="false"', {
228
+ 'msvs_settings': {
229
+ 'VCManifestTool': {
230
+ 'EmbedManifest': 'true',
231
+ 'AdditionalManifestFiles': 'src/res/node.exe.extra.manifest'
232
+ }
233
+ },
234
235
+ 'defines': [
236
+ 'NODE_SHARED_MODE',
237
238
239
+ [ 'node_module_version!=""', {
240
+ 'product_extension': 'so.<(node_module_version)',
241
+ }]
242
243
244
+ [ 'node_use_bundled_v8=="true"', {
245
+ 'include_dirs': [
246
+ 'deps/v8', # include/v8_platform.h
247
248
249
+ 'dependencies': [
250
+ 'deps/v8/tools/gyp/v8.gyp:v8',
251
+ 'deps/v8/tools/gyp/v8.gyp:v8_libplatform'
252
253
254
+ [ 'node_use_v8_platform=="true"', {
255
256
+ 'NODE_USE_V8_PLATFORM=1',
257
258
259
260
+ 'NODE_USE_V8_PLATFORM=0',
261
262
220
263
[ 'node_tag!=""', {
221
264
'defines': [ 'NODE_TAG="<(node_tag)"' ],
222
265
@@ -245,7 +288,8 @@
288
'defines': [ 'NODE_HAVE_SMALL_ICU=1' ],
289
}]],
- [ 'node_enable_v8_vtunejit=="true" and (target_arch=="x64" or \
+ [ 'node_use_bundled_v8=="true" and \
+ node_enable_v8_vtunejit=="true" and (target_arch=="x64" or \
target_arch=="ia32" or target_arch=="x32")', {
'defines': [ 'NODE_ENABLE_VTUNE_PROFILING' ],
@@ -308,7 +352,7 @@
308
352
309
353
310
354
311
- ['OS in "linux freebsd"', {
355
+ ['OS in "linux freebsd" and node_shared=="false"', {
312
356
'ldflags': [
313
357
'-Wl,--whole-archive <(PRODUCT_DIR)/<(OPENSSL_PRODUCT)',
314
358
'-Wl,--no-whole-archive',
@@ -395,7 +439,7 @@
395
[ 'node_no_browser_globals=="true"', {
396
'defines': [ 'NODE_NO_BROWSER_GLOBALS' ],
397
} ],
398
- [ 'v8_postmortem_support=="true"', {
+ [ 'node_use_bundled_v8=="true" and v8_postmortem_support=="true"', {
399
'dependencies': [ 'deps/v8/tools/gyp/v8.gyp:postmortem-metadata' ],
400
401
# -force_load is not applicable for the static library
@@ -478,7 +522,7 @@
478
522
'NODE_PLATFORM="sunos"',
479
523
480
524
481
- [ 'OS=="freebsd" or OS=="linux"', {
525
+ [ '(OS=="freebsd" or OS=="linux") and node_shared=="false"', {
482
526
'ldflags': [ '-Wl,-z,noexecstack',
483
527
'-Wl,--whole-archive <(V8_BASE)',
484
528
'-Wl,--no-whole-archive' ]
@@ -487,12 +531,6 @@
487
531
'ldflags': [ '-Wl,-M,/usr/lib/ld/map.noexstk' ],
488
532
489
533
490
- 'msvs_settings': {
491
- 'VCManifestTool': {
492
- 'EmbedManifest': 'true',
493
- 'AdditionalManifestFiles': 'src/res/node.exe.extra.manifest'
494
- }
495
- },
496
534
497
535
# generate ETW header and resource files
498
536
{
@@ -718,8 +756,6 @@
718
756
'deps/http_parser/http_parser.gyp:http_parser',
719
757
'deps/gtest/gtest.gyp:gtest',
720
758
'deps/uv/uv.gyp:libuv',
721
722
723
759
724
760
725 A3DB code>
761
@@ -750,7 +786,18 @@
750
786
'src/inspector_socket.cc',
751
787
'test/cctest/test_inspector_socket.cc'
752
788
]
753
- }]
789
790
791
792
+ 'deps/v8/tools/gyp/v8.gyp:v8_libplatform',
793
794
795
796
797
798
799
800
754
801
755
802
}
803
], # end targets
src/node.cc
@@ -39,7 +39,9 @@
39
#include "string_bytes.h"
40
#include "util.h"
41
#include "uv.h"
42
+#if NODE_USE_V8_PLATFORM
43
#include "libplatform/libplatform.h"
44
+#endif // NODE_USE_V8_PLATFORM
45
#include "v8-debug.h"
46
#include "v8-profiler.h"
47
#include "zlib.h"
@@ -183,7 +185,42 @@ static uv_async_t dispatch_debug_messages_async;
183
185
184
186
static Mutex node_isolate_mutex;
187
static v8::Isolate* node_isolate;
-static v8::Platform* default_platform;
188
189
+static struct {
190
191
+ void Initialize(int thread_pool_size) {
192
+ platform_ = v8::platform::CreateDefaultPlatform(thread_pool_size);
193
+ V8::InitializePlatform(platform_);
194
195
196
+ void PumpMessageLoop(Isolate* isolate) {
197
+ v8::platform::PumpMessageLoop(platform_, isolate);
198
199
200
+ void Dispose() {
201
+ delete platform_;
202
+ platform_ = nullptr;
203
204
205
+#if HAVE_INSPECTOR
206
+ void StartInspector(Environment *env, int port, bool wait) {
207
+ env->inspector_agent()->Start(platform_, port, wait);
208
209
+#endif // HAVE_INSPECTOR
210
211
+ v8::Platform* platform_;
212
+#else // !NODE_USE_V8_PLATFORM
213
+ void Initialize(int thread_pool_size) {}
214
+ void PumpMessageLoop(Isolate* isolate) {}
215
+ void Dispose() {}
216
+ env->ThrowError("Node compiled with NODE_USE_V8_PLATFORM=0");
+#endif // !NODE_USE_V8_PLATFORM
223
+} v8_platform;
#ifdef __POSIX__
static uv_sem_t debug_semaphore;
@@ -3652,7 +3689,7 @@ static void StartDebug(Environment* env, bool wait) {
3652
3689
CHECK(!debugger_running);
3653
3690
#if HAVE_INSPECTOR
3654
3691
if (use_inspector) {
3655
- env->inspector_agent()->Start(default_platform, inspector_port, wait);
3692
+ v8_platform.StartInspector(env, inspector_port, wait);
3656
3693
debugger_running = true;
3657
3694
} else {
3658
3695
#endif
@@ -4299,11 +4336,11 @@ static void StartNodeInstance(void* arg) {
4299
4336
SealHandleScope seal(isolate);
4300
4337
bool more;
4301
4338
do {
4302
- v8::platform::PumpMessageLoop(default_platform, isolate);
4339
+ v8_platform.PumpMessageLoop(isolate);
4303
4340
more = uv_run(env.event_loop(), UV_RUN_ONCE);
4304
4341
4305
4342
if (more == false) {
4306
4343
4307
4344
EmitBeforeExit(&env);
4308
4345
4309
4346
// Emit `beforeExit` if the loop became alive either after emitting
@@ -4364,8 +4401,7 @@ int Start(int argc, char** argv) {
4364
4401
V8::SetEntropySource(crypto::EntropySource);
4365
4402
4366
4403
4367
- default_platform = v8::platform::CreateDefaultPlatform(v8_thread_pool_size);
4368
- V8::InitializePlatform(default_platform);
4404
+ v8_platform.Initialize(v8_thread_pool_size);
4369
4405
V8::Initialize();
4370
4406
4371
4407
int exit_code = 1;
@@ -4382,8 +4418,7 @@ int Start(int argc, char** argv) {
4382
4418
4383
4419
V8::Dispose();
4384
4420
4385
- delete default_platform;
4386
- default_platform = nullptr;
4421
+ v8_platform.Dispose();
4387
4422
4388
4423
delete[] exec_argv;
4389
4424
exec_argv = nullptr;
src/node.h
@@ -411,17 +411,23 @@ extern "C" NODE_EXTERN void node_module_register(void* mod);
411
# define NODE_MODULE_EXPORT __attribute__((visibility("default")))
412
413
414
+#ifdef NODE_SHARED_MODE
415
+# define NODE_CTOR_PREFIX
416
+#else
417
+# define NODE_CTOR_PREFIX static
418
+#endif
419
#if defined(_MSC_VER)
#pragma section(".CRT$XCU", read)
#define NODE_C_CTOR(fn) \
- static void __cdecl fn(void); \
+ NODE_CTOR_PREFIX void __cdecl fn(void); \
__declspec(dllexport, allocate(".CRT$XCU")) \
void (__cdecl*fn ## _)(void) = fn; \
- static void __cdecl fn(void)
+ NODE_CTOR_PREFIX void __cdecl fn(void)
#else
- static void fn(void) __attribute__((constructor)); \
- static void fn(void)
+ NODE_CTOR_PREFIX void fn(void) __attribute__((constructor)); \
+ NODE_CTOR_PREFIX void fn(void)
#define NODE_MODULE_X(modname, regfunc, priv, flags) \
test/parallel/test-module-version.js
@@ -0,0 +1,10 @@
1
+'use strict';
2
+require('../common');
3
+var assert = require('assert');
4
5
+// check for existence
+assert(process.config.variables.hasOwnProperty('node_module_version'));
+// ensure that `node_module_version` is an Integer > 0
+assert(Number.isInteger(process.config.variables.node_module_version));
+assert(process.config.variables.node_module_version > 0);