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

Commit

Permalink
build: build with chakrashim/chakracore
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kunalspathak committed Jan 12, 2016
1 parent 8a8c98c commit 12cc5d9
Show file tree
Hide file tree
Showing 13 changed files with 444 additions and 25 deletions.
45 changes: 42 additions & 3 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
'component%': 'static_library', # NB. these names match with what V8 expects
'msvs_multi_core_compile': '0', # we do enable multicore compiles, but not using the V8 way
'python%': 'python',
'node_engine%': 'v8',
'msvs_windows_target_platform_version': 'v10.0', # used for node_engine==chakracore

'node_tag%': '',
'uv_library%': 'static_library',
Expand Down Expand Up @@ -51,6 +53,37 @@
],
},

'conditions': [
['node_engine=="v8"', {
'target_defaults': {
'defines': [
'NODE_ENGINE="<(node_engine)"',
'NODE_ENGINE_V8',
],
},
'variables': {
'node_engine_include_dir%': 'deps/v8/include'
},
}],
['node_engine=="chakracore"', {
'target_defaults': {
'defines': [
'NODE_ENGINE="<(node_engine)"',
'NODE_ENGINE_CHAKRACORE',
],
'conditions': [
['target_arch=="arm"', {
'msvs_windows_target_platform_version': '<(msvs_windows_target_platform_version)',
}],
],
},
'variables': {
'node_engine_include_dir%': 'deps/chakrashim/include',
'node_engine_libs': '-lchakracore.lib',
},
}],
],

'target_defaults': {
'default_configuration': 'Release',
'configurations': {
Expand All @@ -64,6 +97,9 @@
['target_arch=="x64"', {
'msvs_configuration_platform': 'x64',
}],
['target_arch=="arm"', {
'msvs_configuration_platform': 'ARM',
}],
['OS=="aix"', {
'cflags': [ '-gxcoff' ],
'ldflags': [ '-Wl,-bbigtoc' ],
Expand Down Expand Up @@ -94,6 +130,9 @@
['target_arch=="x64"', {
'msvs_configuration_platform': 'x64',
}],
['target_arch=="arm"', {
'msvs_configuration_platform': 'ARM',
}],
['OS=="solaris"', {
# pull in V8's postmortem metadata
'ldflags': [ '-Wl,-z,allextract' ]
Expand Down Expand Up @@ -251,9 +290,9 @@
'ldflags': [ '-m32' ],
}],
[ 'target_arch=="ppc64" and OS!="aix"', {
'cflags': [ '-m64', '-mminimal-toc' ],
'ldflags': [ '-m64' ],
}],
'cflags': [ '-m64', '-mminimal-toc' ],
'ldflags': [ '-m64' ],
}],
[ 'OS=="solaris"', {
'cflags': [ '-pthreads' ],
'ldflags': [ '-pthreads' ],
Expand Down
16 changes: 16 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,12 @@ parser.add_option('--enable-static',
dest='enable_static',
help='build as static library')

parser.add_option('--engine',
action='store',
dest='engine',
help='Use specified JS engine (default is V8)')


(options, args) = parser.parse_args()

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

if os.name == 'nt':
k = {}
k['__ARM_ARCH_7__'] = True
k['__ARM_NEON__'] = True
return k

This comment has been minimized.

Copy link
@thefourtheye

thefourtheye Jan 19, 2016

Contributor

Prefer dict literals, return {'__ARM_ARCH_7__': True, '__ARM_NEON__': True}

This comment has been minimized.

Copy link
@kunalspathak

kunalspathak Jan 19, 2016

Author Member

Good point.

try:
p = subprocess.Popen(shlex.split(cc or CC) + ['-dM', '-E', '-'],
stdin=subprocess.PIPE,
Expand Down Expand Up @@ -1101,6 +1112,10 @@ def configure_intl(o):
pprint.pformat(icu_config, indent=2) + '\n')
return # end of configure_intl

def configure_engine(o):
engine = options.engine or 'v8'
o['variables']['node_engine'] = engine.lower()

output = {
'variables': { 'python': sys.executable },
'include_dirs': [],
Expand Down Expand Up @@ -1128,6 +1143,7 @@ configure_openssl(output)
configure_winsdk(output)
configure_intl(output)
configure_static(output)
configure_engine(output)

# variables should be a root level element,
# move everything else to target_defaults
Expand Down
77 changes: 77 additions & 0 deletions deps/chakrashim/chakracore.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
{
'variables': {
'target_arch%': 'ia32',
'library%': 'static_library', # build chakracore as static library or dll
'component%': 'static_library', # link crt statically or dynamically
'chakra_dir%': 'core',
'msvs_windows_target_platform_version_prop': '',

'conditions': [
['target_arch=="ia32"', { 'Platform': 'x86' }],
['target_arch=="x64"', { 'Platform': 'x64' }],
['target_arch=="arm"', {
'Platform': 'arm',
'msvs_windows_target_platform_version_prop':
'/p:WindowsTargetPlatformVersion=$(WindowsTargetPlatformVersion)',
}],
],
},

'targets': [
{
'target_name': 'chakracore',
'toolsets': ['host'],
'type': 'none',

'variables': {
'chakracore_sln': '<(chakra_dir)/build/Chakra.Core.sln',
'chakracore_header': [
'<(chakra_dir)/lib/jsrt/chakracore.h',
'<(chakra_dir)/lib/jsrt/chakracommon.h'
],
'chakracore_binaries': [
'<(chakra_dir)/build/vcbuild/bin/<(Platform)_$(ConfigurationName)/chakracore.dll',
'<(chakra_dir)/build/vcbuild/bin/<(Platform)_$(ConfigurationName)/chakracore.pdb',
'<(chakra_dir)/build/vcbuild/bin/<(Platform)_$(ConfigurationName)/chakracore.lib',
],
},

'actions': [
{
'action_name': 'build_chakracore',
'inputs': [
'<(chakracore_sln)'
],
'outputs': [
'<@(chakracore_binaries)',
],
'action': [
'msbuild',
'/p:Platform=<(Platform)',
'/p:Configuration=$(ConfigurationName)',
'/p:RuntimeLib=<(component)',
'<(msvs_windows_target_platform_version_prop)',
'/m',
'<@(_inputs)',
],
},
],

'copies': [
{
'destination': 'include',
'files': [ '<@(chakracore_header)' ],
},
{
'destination': '<(PRODUCT_DIR)',
'files': [ '<@(chakracore_binaries)' ],
},
],

'direct_dependent_settings': {
'library_dirs': [ '<(PRODUCT_DIR)' ],
},

}, # end chakracore
],
}
141 changes: 141 additions & 0 deletions deps/chakrashim/chakrashim.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
{
'variables': {
'library_files': [
'lib/chakra_shim.js',
],
},

'targets': [
{
'target_name': 'chakrashim',
'type': '<(library)',

'dependencies': [
'chakra_js2c#host',
],

'include_dirs': [
'include',
'<(SHARED_INTERMEDIATE_DIR)'
],
'defines': [
'BUILDING_CHAKRASHIM=1',
],
'conditions': [
[ 'target_arch=="ia32"', { 'defines': [ '__i386__=1' ] } ],
[ 'target_arch=="x64"', { 'defines': [ '__x86_64__=1' ] } ],
[ 'target_arch=="arm"', { 'defines': [ '__arm__=1' ] } ],
['node_engine=="chakracore"', {
'dependencies': [
'chakracore.gyp:chakracore#host',
],
'export_dependent_settings': [
'chakracore.gyp:chakracore#host',
],
}],
],
'msvs_use_library_dependency_inputs': 1,

'direct_dependent_settings': {
'include_dirs': [
'include',
],
'defines': [
'BUILDING_CHAKRASHIM=1',
],
'libraries': [
'-lole32.lib',
'-lversion.lib',
'<@(node_engine_libs)',
],
'conditions': [
[ 'target_arch=="arm"', {
'defines': [ '__arm__=1' ]
}],
],
},

'sources': [
'include/libplatform/libplatform.h',
'include/v8.h',
'include/v8config.h',
'include/v8-debug.h',
'include/v8-platform.h',
'include/v8-profiler.h',
'include/v8-version.h',
'src/jsrtcachedpropertyidref.inc',
'src/jsrtcontextcachedobj.inc',
'src/jsrtcontextshim.cc',
'src/jsrtcontextshim.h',
'src/jsrtisolateshim.cc',
'src/jsrtisolateshim.h',
'src/jsrtpromise.cc',
'src/jsrtproxyutils.cc',
'src/jsrtproxyutils.h',
'src/jsrtstringutils.cc',
'src/jsrtstringutils.h',
'src/jsrtutils.cc',
'src/jsrtutils.h',
'src/v8array.cc',
'src/v8arraybuffer.cc',
'src/v8boolean.cc',
'src/v8booleanobject.cc',
'src/v8chakra.h',
'src/v8context.cc',
'src/v8date.cc',
'src/v8debug.cc',
'src/v8exception.cc',
'src/v8external.cc',
'src/v8function.cc',
'src/v8functiontemplate.cc',
'src/v8global.cc',
'src/v8handlescope.cc',
'src/v8int32.cc',
'src/v8integer.cc',
'src/v8isolate.cc',
'src/v8message.cc',
'src/v8number.cc',
'src/v8numberobject.cc',
'src/v8object.cc',
'src/v8objecttemplate.cc',
'src/v8persistent.cc',
'src/v8script.cc',
'src/v8signature.cc',
'src/v8stacktrace.cc',
'src/v8string.cc',
'src/v8stringobject.cc',
'src/v8template.cc',
'src/v8trycatch.cc',
'src/v8typedarray.cc',
'src/v8uint32.cc',
'src/v8v8.cc',
'src/v8value.cc',
],
}, # end chakrashim

{
'target_name': 'chakra_js2c',
'type': 'none',
'toolsets': ['host'],
'msvs_disabled_warnings': [4091],
'actions': [
{
'action_name': 'chakra_js2c',
'inputs': [
'<@(library_files)'
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/chakra_natives.h',
],
'action': [
'<(python)',
'./../../tools/js2c.py',
'--namespace=jsrt',
'<@(_outputs)',
'<@(_inputs)',
],
},
],
}, # end chakra_js2c
],
}
8 changes: 7 additions & 1 deletion deps/npm/node_modules/node-gyp/addon.gypi

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 12cc5d9

Please sign in to comment.