Skip to content

Commit 999d918

Browse files
committed
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
1 parent 0b1ff69 commit 999d918

File tree

4 files changed

+23
-0
lines changed

4 files changed

+23
-0
lines changed

common.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
'enable_pgo_generate%': '0',
1414
'enable_pgo_use%': '0',
1515
'python%': 'python',
16+
'emulator%': [],
1617

1718
'node_shared%': 'false',
1819
'force_dynamic_crt%': 0,

configure.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@
112112
choices=valid_arch,
113113
help=f"CPU architecture to build for ({', '.join(valid_arch)})")
114114

115+
parser.add_argument('--emulator',
116+
action='store',
117+
dest='emulator',
118+
default=None,
119+
help='emulator command that can run executables built for the target system')
120+
115121
parser.add_argument('--cross-compiling',
116122
action='store_true',
117123
dest='cross_compiling',
@@ -2276,6 +2282,14 @@ def make_bin_override():
22762282
# will fail to run python scripts.
22772283
gyp_args += ['-Dpython=' + python]
22782284

2285+
if options.emulator is not None:
2286+
if not options.cross_compiling:
2287+
# Note that emulator is a list so we have to quote the variable.
2288+
gyp_args += ['-Demulator=' + shlex.quote(options.emulator)]
2289+
else:
2290+
# TODO: perhaps use emulator for tests?
2291+
warn('The `--emulator` option has no effect when cross-compiling.')
2292+
22792293
if options.use_ninja:
22802294
gyp_args += ['-f', 'ninja-' + flavor]
22812295
elif flavor == 'win' and sys.platform != 'msys':

node.gyp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,7 @@
703703
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
704704
],
705705
'action': [
706+
'<@(emulator)',
706707
'<(node_mksnapshot_exec)',
707708
'--build-snapshot',
708709
'<(node_snapshot_main)',
@@ -722,6 +723,7 @@
722723
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
723724
],
724725
'action': [
726+
'<@(emulator)',
725727
'<@(_inputs)',
726728
'<@(_outputs)',
727729
],
@@ -1010,6 +1012,7 @@
10101012
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
10111013
],
10121014
'action': [
1015+
'<@(emulator)',
10131016
'<(node_js2c_exec)',
10141017
'<@(_outputs)',
10151018
'lib',
@@ -1477,6 +1480,7 @@
14771480
'<(PRODUCT_DIR)/<(node_core_target_name).def',
14781481
],
14791482
'action': [
1483+
'<@(emulator)',
14801484
'<(PRODUCT_DIR)/gen_node_def.exe',
14811485
'<@(_inputs)',
14821486
'<@(_outputs)',

tools/v8_gypfiles/v8.gyp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@
112112
'<@(torque_outputs_inc)',
113113
],
114114
'action': [
115+
'<@(emulator)',
115116
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)torque<(EXECUTABLE_SUFFIX)',
116117
'-o', '<(SHARED_INTERMEDIATE_DIR)/torque-generated',
117118
'-v8-root', '<(V8_ROOT)',
@@ -232,6 +233,7 @@
232233
'action': [
233234
'<(python)',
234235
'<(V8_ROOT)/tools/run.py',
236+
'<@(emulator)',
235237
'<@(_inputs)',
236238
'<@(_outputs)',
237239
],
@@ -453,6 +455,7 @@
453455
}],
454456
],
455457
'action': [
458+
'<@(emulator)',
456459
'>@(_inputs)',
457460
'>@(mksnapshot_flags)',
458461
],
@@ -1842,6 +1845,7 @@
18421845
'action': [
18431846
'<(python)',
18441847
'<(V8_ROOT)/tools/run.py',
1848+
'<@(emulator)',
18451849
'<@(_inputs)',
18461850
'<@(_outputs)',
18471851
],

0 commit comments

Comments
 (0)