Skip to content

Commit c84011b

Browse files
tieaduh95
authored andcommitted
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: #53899 Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Aviv Keller <[email protected]>
1 parent 70e9390 commit c84011b

4 files changed

Lines changed: 23 additions & 0 deletions

File tree

common.gypi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
'enable_pgo_use%': '0',
1515
'clang_profile_lib%': '',
1616
'python%': 'python',
17+
'emulator%': [],
1718

1819
'node_shared%': 'false',
1920
'node_enable_experimentals%': 'false',

configure.py

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

120+
parser.add_argument('--emulator',
121+
action='store',
122+
dest='emulator',
123+
default=None,
124+
help='emulator command that can run executables built for the target system')
125+
120126
parser.add_argument('--cross-compiling',
121127
action='store_true',
122128
dest='cross_compiling',
@@ -2633,6 +2639,14 @@ def make_bin_override():
26332639
# will fail to run python scripts.
26342640
gyp_args += ['-Dpython=' + python]
26352641

2642+
if options.emulator is not None:
2643+
if not options.cross_compiling:
2644+
# Note that emulator is a list so we have to quote the variable.
2645+
gyp_args += ['-Demulator=' + shlex.quote(options.emulator)]
2646+
else:
2647+
# TODO: perhaps use emulator for tests?
2648+
warn('The `--emulator` option has no effect when cross-compiling.')
2649+
26362650
if options.use_ninja:
26372651
gyp_args += ['-f', 'ninja-' + flavor]
26382652
elif flavor == 'win' and sys.platform != 'msys':

node.gyp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@
750750
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
751751
],
752752
'action': [
753+
'<@(emulator)',
753754
'<(node_mksnapshot_exec)',
754755
'--build-snapshot',
755756
'<(node_snapshot_main)',
@@ -769,6 +770,7 @@
769770
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
770771
],
771772
'action': [
773+
'<@(emulator)',
772774
'<@(_inputs)',
773775
'<@(_outputs)',
774776
],
@@ -1105,6 +1107,7 @@
11051107
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
11061108
],
11071109
'action': [
1110+
'<@(emulator)',
11081111
'<(node_js2c_exec)',
11091112
'<@(_outputs)',
11101113
'lib',
@@ -1685,6 +1688,7 @@
16851688
'<(PRODUCT_DIR)/<(node_core_target_name).def',
16861689
],
16871690
'action': [
1691+
'<@(emulator)',
16881692
'<(PRODUCT_DIR)/gen_node_def.exe',
16891693
'<@(_inputs)',
16901694
'<@(_outputs)',

tools/v8_gypfiles/v8.gyp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
'<@(torque_outputs_inc)',
145145
],
146146
'action': [
147+
'<@(emulator)',
147148
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)torque<(EXECUTABLE_SUFFIX)',
148149
'-o', '<(SHARED_INTERMEDIATE_DIR)/torque-generated',
149150
'-v8-root', '<(V8_ROOT)',
@@ -264,6 +265,7 @@
264265
'action': [
265266
'<(python)',
266267
'<(V8_ROOT)/tools/run.py',
268+
'<@(emulator)',
267269
'<@(_inputs)',
268270
'<@(_outputs)',
269271
],
@@ -492,6 +494,7 @@
492494
}],
493495
],
494496
'action': [
497+
'<@(emulator)',
495498
'>@(_inputs)',
496499
'>@(mksnapshot_flags)',
497500
],
@@ -1981,6 +1984,7 @@
19811984
'action': [
19821985
'<(python)',
19831986
'<(V8_ROOT)/tools/run.py',
1987+
'<@(emulator)',
19841988
'<@(_inputs)',
19851989
'<@(_outputs)',
19861990
],

0 commit comments

Comments
 (0)