Skip to content

Commit d2646b3

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 d2646b3

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

common.gypi

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
'enable_pgo_generate%': '0',
1414
'enable_pgo_use%': '0',
1515
'python%': 'python',
16+
'emulator%': [],
17+
'emulator_path%': '',
1618

1719
'node_shared%': 'false',
1820
'force_dynamic_crt%': 0,
@@ -117,6 +119,11 @@
117119
['target_arch in "ppc64 s390x"', {
118120
'v8_enable_backtrace': 1,
119121
}],
122+
['emulator_path != ""', {
123+
'emulator%': [
124+
'<(emulator_path)'
125+
]
126+
}],
120127
['OS=="linux"', {
121128
'node_section_ordering_info%': ''
122129
}],

configure.py

Lines changed: 9 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='use an emulator to run intermediate build tools')
120+
115121
parser.add_argument('--cross-compiling',
116122
action='store_true',
117123
dest='cross_compiling',
@@ -2283,6 +2289,9 @@ def make_bin_override():
22832289
else:
22842290
gyp_args += ['-f', 'make-' + flavor]
22852291

2292+
if options.emulator is not None:
2293+
gyp_args += ['-Demulator_path=' + options.emulator]
2294+
22862295
if options.compile_commands_json:
22872296
gyp_args += ['-f', 'compile_commands_json']
22882297
os.path.islink('./compile_commands.json') and os.unlink('./compile_commands.json')

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)