Skip to content

Commit

Permalink
build: support setting an emulator from configure script
Browse files Browse the repository at this point in the history
V8’s JIT infrastructure requires binaries such as mksnapshot to be run
during the build. However, these binaries must have the same bit-width
as the host platform (e.g. a x86_64 build platform targeting ARMv6 needs
to produce a 32-bit binary).

To work around this issue, allow building the binaries for the host
platform and running them on the build platform with an emulator.

Based on Buildroot’s nodejs-src 0001-add-qemu-wrapper-support.patch.
https://gitlab.com/buildroot.org/buildroot/-/blob/c1d5eada4d4db9eeaa1c44dd1dea95a67c8a70ca/package/nodejs/nodejs-src/0001-add-qemu-wrapper-support.patch
  • Loading branch information
tie committed Jul 17, 2024
1 parent 0b1ff69 commit d2646b3
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
'enable_pgo_generate%': '0',
'enable_pgo_use%': '0',
'python%': 'python',
'emulator%': [],
'emulator_path%': '',

'node_shared%': 'false',
'force_dynamic_crt%': 0,
Expand Down Expand Up @@ -117,6 +119,11 @@
['target_arch in "ppc64 s390x"', {
'v8_enable_backtrace': 1,
}],
['emulator_path != ""', {
'emulator%': [
'<(emulator_path)'
]
}],
['OS=="linux"', {
'node_section_ordering_info%': ''
}],
Expand Down
9 changes: 9 additions & 0 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,12 @@
choices=valid_arch,
help=f"CPU architecture to build for ({', '.join(valid_arch)})")

parser.add_argument('--emulator',
action='store',
dest='emulator',
default=None,
help='use an emulator to run intermediate build tools')

parser.add_argument('--cross-compiling',
action='store_true',
dest='cross_compiling',
Expand Down Expand Up @@ -2283,6 +2289,9 @@ def make_bin_override():
else:
gyp_args += ['-f', 'make-' + flavor]

if options.emulator is not None:
gyp_args += ['-Demulator_path=' + options.emulator]

if options.compile_commands_json:
gyp_args += ['-f', 'compile_commands_json']
os.path.islink('./compile_commands.json') and os.unlink('./compile_commands.json')
Expand Down
4 changes: 4 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,7 @@
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
],
'action': [
'<@(emulator)',
'<(node_mksnapshot_exec)',
'--build-snapshot',
'<(node_snapshot_main)',
Expand All @@ -722,6 +723,7 @@
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
],
'action': [
'<@(emulator)',
'<@(_inputs)',
'<@(_outputs)',
],
Expand Down Expand Up @@ -1010,6 +1012,7 @@
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
],
'action': [
'<@(emulator)',
'<(node_js2c_exec)',
'<@(_outputs)',
'lib',
Expand Down Expand Up @@ -1477,6 +1480,7 @@
'<(PRODUCT_DIR)/<(node_core_target_name).def',
],
'action': [
'<@(emulator)',
'<(PRODUCT_DIR)/gen_node_def.exe',
'<@(_inputs)',
'<@(_outputs)',
Expand Down
4 changes: 4 additions & 0 deletions tools/v8_gypfiles/v8.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
'<@(torque_outputs_inc)',
],
'action': [
'<@(emulator)',
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)torque<(EXECUTABLE_SUFFIX)',
'-o', '<(SHARED_INTERMEDIATE_DIR)/torque-generated',
'-v8-root', '<(V8_ROOT)',
Expand Down Expand Up @@ -232,6 +233,7 @@
'action': [
'<(python)',
'<(V8_ROOT)/tools/run.py',
'<@(emulator)',
'<@(_inputs)',
'<@(_outputs)',
],
Expand Down Expand Up @@ -453,6 +455,7 @@
}],
],
'action': [
'<@(emulator)',
'>@(_inputs)',
'>@(mksnapshot_flags)',
],
Expand Down Expand Up @@ -1842,6 +1845,7 @@
'action': [
'<(python)',
'<(V8_ROOT)/tools/run.py',
'<@(emulator)',
'<@(_inputs)',
'<@(_outputs)',
],
Expand Down

0 comments on commit d2646b3

Please sign in to comment.