build: support setting an emulator from configure script

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

PR-URL: https://github.com/nodejs/node/pull/53899
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Aviv Keller <me@aviv.sh>
This commit is contained in:
Ivan Trubach authored and GitHub committed 2026-06-25 10:56:23 +02:00
1 parent c612f3583c
commit b087e922bd
4 files changed
+23

No files matched your search

+1
View File
@@ -14,6 +14,7 @@
'enable_pgo_use%': '0',
'clang_profile_lib%': '',
'python%': 'python',
'emulator%': [],
'node_shared%': 'false',
'node_enable_experimentals%': 'false',
+14
View File
@@ -117,6 +117,12 @@ parser.add_argument('--dest-cpu',
choices=valid_arch,
help=f"CPU architecture to build for ({', '.join(valid_arch)})")
parser.add_argument('--emulator',
action='store',
dest='emulator',
default=None,
help='emulator command that can run executables built for the target system')
parser.add_argument('--cross-compiling',
action='store_true',
dest='cross_compiling',
@@ -2947,6 +2953,14 @@ if flavor == 'win' and python.lower().endswith('.exe'):
# will fail to run python scripts.
gyp_args += ['-Dpython=' + python]
if options.emulator is not None:
if not options.cross_compiling:
# Note that emulator is a list so we have to quote the variable.
gyp_args += ['-Demulator=' + shlex.quote(options.emulator)]
else:
# TODO: perhaps use emulator for tests?
warn('The `--emulator` option has no effect when cross-compiling.')
if not options.v8_disable_temporal_support or not options.shared_temporal_capi:
cargo = os.environ.get('CARGO')
if cargo:
+4
View File
@@ -1092,6 +1092,7 @@
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
],
'action': [
'<@(emulator)',
'<(node_js2c_exec)',
'<@(_outputs)',
'lib',
@@ -1158,6 +1159,7 @@
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
],
'action': [
'<@(emulator)',
'<(node_mksnapshot_exec)',
'--build-snapshot',
'<(node_snapshot_main)',
@@ -1177,6 +1179,7 @@
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
],
'action': [
'<@(emulator)',
'<@(_inputs)',
'<@(_outputs)',
],
@@ -1835,6 +1838,7 @@
'<(PRODUCT_DIR)/<(node_core_target_name).def',
],
'action': [
'<@(emulator)',
'<(PRODUCT_DIR)/gen_node_def.exe',
'<@(_inputs)',
'<@(_outputs)',
+4
View File
@@ -149,6 +149,7 @@
'<@(torque_outputs_inc)',
],
'action': [
'<@(emulator)',
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)torque<(EXECUTABLE_SUFFIX)',
'-o', '<(SHARED_INTERMEDIATE_DIR)/torque-generated',
'-v8-root', '<(V8_ROOT)',
@@ -269,6 +270,7 @@
'action': [
'<(python)',
'<(V8_ROOT)/tools/run.py',
'<@(emulator)',
'<@(_inputs)',
'<@(_outputs)',
],
@@ -470,6 +472,7 @@
}],
],
'action': [
'<@(emulator)',
'>@(_inputs)',
'>@(mksnapshot_flags)',
],
@@ -1990,6 +1993,7 @@
'action': [
'<(python)',
'<(V8_ROOT)/tools/run.py',
'<@(emulator)',
'<@(_inputs)',
'<@(_outputs)',
],