Skip to content
This repository was archived by the owner on Oct 15, 2020. It is now read-only.

Commit 12cc5d9

Browse files
committed
build: build with chakrashim/chakracore
Enable building Node.js with chakracore engine. Below are details: * Configure to build Node.js with "v8" (default) or "chakracore" JS engine with optional vcbuild.bat switch. * Support building on Windows on ARM. * chakrashim uses js2c with a namespace. * Configure msvs_windows_target_platform_version to use the right Windows SDK. * Configure msvs_use_library_dependency_inputs to export symbols correctly (otherwise functions not used by node.exe but might be needed by native addon modules could be optimized away by linker). * Configure WindowsSDKDesktopARMSupport for ARM. * Enables building native addon modules for Node.js with multiple node-engines.
1 parent 8a8c98c commit 12cc5d9

File tree

13 files changed

+444
-25
lines changed

13 files changed

+444
-25
lines changed

common.gypi

+42-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
'component%': 'static_library', # NB. these names match with what V8 expects
1111
'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way
1212
'python%': 'python',
13+
'node_engine%': 'v8',
14+
'msvs_windows_target_platform_version': 'v10.0', # used for node_engine==chakracore
1315

1416
'node_tag%': '',
1517
'uv_library%': 'static_library',
@@ -51,6 +53,37 @@
5153
],
5254
},
5355

56+
'conditions': [
57+
['node_engine=="v8"', {
58+
'target_defaults': {
59+
'defines': [
60+
'NODE_ENGINE="<(node_engine)"',
61+
'NODE_ENGINE_V8',
62+
],
63+
},
64+
'variables': {
65+
'node_engine_include_dir%': 'deps/v8/include'
66+
},
67+
}],
68+
['node_engine=="chakracore"', {
69+
'target_defaults': {
70+
'defines': [
71+
'NODE_ENGINE="<(node_engine)"',
72+
'NODE_ENGINE_CHAKRACORE',
73+
],
74+
'conditions': [
75+
['target_arch=="arm"', {
76+
'msvs_windows_target_platform_version': '<(msvs_windows_target_platform_version)',
77+
}],
78+
],
79+
},
80+
'variables': {
81+
'node_engine_include_dir%': 'deps/chakrashim/include',
82+
'node_engine_libs': '-lchakracore.lib',
83+
},
84+
}],
85+
],
86+
5487
'target_defaults': {
5588
'default_configuration': 'Release',
5689
'configurations': {
@@ -64,6 +97,9 @@
6497
['target_arch=="x64"', {
6598
'msvs_configuration_platform': 'x64',
6699
}],
100+
['target_arch=="arm"', {
101+
'msvs_configuration_platform': 'ARM',
102+
}],
67103
['OS=="aix"', {
68104
'cflags': [ '-gxcoff' ],
69105
'ldflags': [ '-Wl,-bbigtoc' ],
@@ -94,6 +130,9 @@
94130
['target_arch=="x64"', {
95131
'msvs_configuration_platform': 'x64',
96132
}],
133+
['target_arch=="arm"', {
134+
'msvs_configuration_platform': 'ARM',
135+
}],
97136
['OS=="solaris"', {
98137
# pull in V8's postmortem metadata
99138
'ldflags': [ '-Wl,-z,allextract' ]
@@ -251,9 +290,9 @@
251290
'ldflags': [ '-m32' ],
252291
}],
253292
[ 'target_arch=="ppc64" and OS!="aix"', {
254-
'cflags': [ '-m64', '-mminimal-toc' ],
255-
'ldflags': [ '-m64' ],
256-
}],
293+
'cflags': [ '-m64', '-mminimal-toc' ],
294+
'ldflags': [ '-m64' ],
295+
}],
257296
[ 'OS=="solaris"', {
258297
'cflags': [ '-pthreads' ],
259298
'ldflags': [ '-pthreads' ],

configure

+16
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,12 @@ parser.add_option('--enable-static',
375375
dest='enable_static',
376376
help='build as static library')
377377

378+
parser.add_option('--engine',
379+
action='store',
380+
dest='engine',
381+
help='Use specified JS engine (default is V8)')
382+
383+
378384
(options, args) = parser.parse_args()
379385

380386
# Expand ~ in the install prefix now, it gets written to multiple files.
@@ -525,6 +531,11 @@ def check_compiler(o):
525531
def cc_macros(cc=None):
526532
"""Checks predefined macros using the C compiler command."""
527533

534+
if os.name == 'nt':
535+
k = {}
536+
k['__ARM_ARCH_7__'] = True
537+
k['__ARM_NEON__'] = True
538+
return k
528539
try:
529540
p = subprocess.Popen(shlex.split(cc or CC) + ['-dM', '-E', '-'],
530541
stdin=subprocess.PIPE,
@@ -1101,6 +1112,10 @@ def configure_intl(o):
11011112
pprint.pformat(icu_config, indent=2) + '\n')
11021113
return # end of configure_intl
11031114

1115+
def configure_engine(o):
1116+
engine = options.engine or 'v8'
1117+
o['variables']['node_engine'] = engine.lower()
1118+
11041119
output = {
11051120
'variables': { 'python': sys.executable },
11061121
'include_dirs': [],
@@ -1128,6 +1143,7 @@ configure_openssl(output)
11281143
configure_winsdk(output)
11291144
configure_intl(output)
11301145
configure_static(output)
1146+
configure_engine(output)
11311147

11321148
# variables should be a root level element,
11331149
# move everything else to target_defaults

deps/chakrashim/chakracore.gyp

+77
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
{
2+
'variables': {
3+
'target_arch%': 'ia32',
4+
'library%': 'static_library', # build chakracore as static library or dll
5+
'component%': 'static_library', # link crt statically or dynamically
6+
'chakra_dir%': 'core',
7+
'msvs_windows_target_platform_version_prop': '',
8+
9+
'conditions': [
10+
['target_arch=="ia32"', { 'Platform': 'x86' }],
11+
['target_arch=="x64"', { 'Platform': 'x64' }],
12+
['target_arch=="arm"', {
13+
'Platform': 'arm',
14+
'msvs_windows_target_platform_version_prop':
15+
'/p:WindowsTargetPlatformVersion=$(WindowsTargetPlatformVersion)',
16+
}],
17+
],
18+
},
19+
20+
'targets': [
21+
{
22+
'target_name': 'chakracore',
23+
'toolsets': ['host'],
24+
'type': 'none',
25+
26+
'variables': {
27+
'chakracore_sln': '<(chakra_dir)/build/Chakra.Core.sln',
28+
'chakracore_header': [
29+
'<(chakra_dir)/lib/jsrt/chakracore.h',
30+
'<(chakra_dir)/lib/jsrt/chakracommon.h'
31+
],
32+
'chakracore_binaries': [
33+
'<(chakra_dir)/build/vcbuild/bin/<(Platform)_$(ConfigurationName)/chakracore.dll',
34+
'<(chakra_dir)/build/vcbuild/bin/<(Platform)_$(ConfigurationName)/chakracore.pdb',
35+
'<(chakra_dir)/build/vcbuild/bin/<(Platform)_$(ConfigurationName)/chakracore.lib',
36+
],
37+
},
38+
39+
'actions': [
40+
{
41+
'action_name': 'build_chakracore',
42+
'inputs': [
43+
'<(chakracore_sln)'
44+
],
45+
'outputs': [
46+
'<@(chakracore_binaries)',
47+
],
48+
'action': [
49+
'msbuild',
50+
'/p:Platform=<(Platform)',
51+
'/p:Configuration=$(ConfigurationName)',
52+
'/p:RuntimeLib=<(component)',
53+
'<(msvs_windows_target_platform_version_prop)',
54+
'/m',
55+
'<@(_inputs)',
56+
],
57+
},
58+
],
59+
60+
'copies': [
61+
{
62+
'destination': 'include',
63+
'files': [ '<@(chakracore_header)' ],
64+
},
65+
{
66+
'destination': '<(PRODUCT_DIR)',
67+
'files': [ '<@(chakracore_binaries)' ],
68+
},
69+
],
70+
71+
'direct_dependent_settings': {
72+
'library_dirs': [ '<(PRODUCT_DIR)' ],
73+
},
74+
75+
}, # end chakracore
76+
],
77+
}

deps/chakrashim/chakrashim.gyp

+141
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
{
2+
'variables': {
3+
'library_files': [
4+
'lib/chakra_shim.js',
5+
],
6+
},
7+
8+
'targets': [
9+
{
10+
'target_name': 'chakrashim',
11+
'type': '<(library)',
12+
13+
'dependencies': [
14+
'chakra_js2c#host',
15+
],
16+
17+
'include_dirs': [
18+
'include',
19+
'<(SHARED_INTERMEDIATE_DIR)'
20+
],
21+
'defines': [
22+
'BUILDING_CHAKRASHIM=1',
23+
],
24+
'conditions': [
25+
[ 'target_arch=="ia32"', { 'defines': [ '__i386__=1' ] } ],
26+
[ 'target_arch=="x64"', { 'defines': [ '__x86_64__=1' ] } ],
27+
[ 'target_arch=="arm"', { 'defines': [ '__arm__=1' ] } ],
28+
['node_engine=="chakracore"', {
29+
'dependencies': [
30+
'chakracore.gyp:chakracore#host',
31+
],
32+
'export_dependent_settings': [
33+
'chakracore.gyp:chakracore#host',
34+
],
35+
}],
36+
],
37+
'msvs_use_library_dependency_inputs': 1,
38+
39+
'direct_dependent_settings': {
40+
'include_dirs': [
41+
'include',
42+
],
43+
'defines': [
44+
'BUILDING_CHAKRASHIM=1',
45+
],
46+
'libraries': [
47+
'-lole32.lib',
48+
'-lversion.lib',
49+
'<@(node_engine_libs)',
50+
],
51+
'conditions': [
52+
[ 'target_arch=="arm"', {
53+
'defines': [ '__arm__=1' ]
54+
}],
55+
],
56+
},
57+
58+
'sources': [
59+
'include/libplatform/libplatform.h',
60+
'include/v8.h',
61+
'include/v8config.h',
62+
'include/v8-debug.h',
63+
'include/v8-platform.h',
64+
'include/v8-profiler.h',
65+
'include/v8-version.h',
66+
'src/jsrtcachedpropertyidref.inc',
67+
'src/jsrtcontextcachedobj.inc',
68+
'src/jsrtcontextshim.cc',
69+
'src/jsrtcontextshim.h',
70+
'src/jsrtisolateshim.cc',
71+
'src/jsrtisolateshim.h',
72+
'src/jsrtpromise.cc',
73+
'src/jsrtproxyutils.cc',
74+
'src/jsrtproxyutils.h',
75+
'src/jsrtstringutils.cc',
76+
'src/jsrtstringutils.h',
77+
'src/jsrtutils.cc',
78+
'src/jsrtutils.h',
79+
'src/v8array.cc',
80+
'src/v8arraybuffer.cc',
81+
'src/v8boolean.cc',
82+
'src/v8booleanobject.cc',
83+
'src/v8chakra.h',
84+
'src/v8context.cc',
85+
'src/v8date.cc',
86+
'src/v8debug.cc',
87+
'src/v8exception.cc',
88+
'src/v8external.cc',
89+
'src/v8function.cc',
90+
'src/v8functiontemplate.cc',
91+
'src/v8global.cc',
92+
'src/v8handlescope.cc',
93+
'src/v8int32.cc',
94+
'src/v8integer.cc',
95+
'src/v8isolate.cc',
96+
'src/v8message.cc',
97+
'src/v8number.cc',
98+
'src/v8numberobject.cc',
99+
'src/v8object.cc',
100+
'src/v8objecttemplate.cc',
101+
'src/v8persistent.cc',
102+
'src/v8script.cc',
103+
'src/v8signature.cc',
104+
'src/v8stacktrace.cc',
105+
'src/v8string.cc',
106+
'src/v8stringobject.cc',
107+
'src/v8template.cc',
108+
'src/v8trycatch.cc',
109+
'src/v8typedarray.cc',
110+
'src/v8uint32.cc',
111+
'src/v8v8.cc',
112+
'src/v8value.cc',
113+
],
114+
}, # end chakrashim
115+
116+
{
117+
'target_name': 'chakra_js2c',
118+
'type': 'none',
119+
'toolsets': ['host'],
120+
'msvs_disabled_warnings': [4091],
121+
'actions': [
122+
{
123+
'action_name': 'chakra_js2c',
124+
'inputs': [
125+
'<@(library_files)'
126+
],
127+
'outputs': [
128+
'<(SHARED_INTERMEDIATE_DIR)/chakra_natives.h',
129+
],
130+
'action': [
131+
'<(python)',
132+
'./../../tools/js2c.py',
133+
'--namespace=jsrt',
134+
'<@(_outputs)',
135+
'<@(_inputs)',
136+
],
137+
},
138+
],
139+
}, # end chakra_js2c
140+
],
141+
}

deps/npm/node_modules/node-gyp/addon.gypi

+7-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)