Skip to content

Commit b087e92

Browse files
authored
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 <duhamelantoine1995@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent c612f35 commit b087e92

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',
@@ -2947,6 +2953,14 @@ def make_bin_override():
29472953
# will fail to run python scripts.
29482954
gyp_args += ['-Dpython=' + python]
29492955

2956+
if options.emulator is not None:
2957+
if not options.cross_compiling:
2958+
# Note that emulator is a list so we have to quote the variable.
2959+
gyp_args += ['-Demulator=' + shlex.quote(options.emulator)]
2960+
else:
2961+
# TODO: perhaps use emulator for tests?
2962+
warn('The `--emulator` option has no effect when cross-compiling.')
2963+
29502964
if not options.v8_disable_temporal_support or not options.shared_temporal_capi:
29512965
cargo = os.environ.get('CARGO')
29522966
if cargo:

node.gyp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,7 @@
10921092
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
10931093
],
10941094
'action': [
1095+
'<@(emulator)',
10951096
'<(node_js2c_exec)',
10961097
'<@(_outputs)',
10971098
'lib',
@@ -1158,6 +1159,7 @@
11581159
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
11591160
],
11601161
'action': [
1162+
'<@(emulator)',
11611163
'<(node_mksnapshot_exec)',
11621164
'--build-snapshot',
11631165
'<(node_snapshot_main)',
@@ -1177,6 +1179,7 @@
11771179
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
11781180
],
11791181
'action': [
1182+
'<@(emulator)',
11801183
'<@(_inputs)',
11811184
'<@(_outputs)',
11821185
],
@@ -1835,6 +1838,7 @@
18351838
'<(PRODUCT_DIR)/<(node_core_target_name).def',
18361839
],
18371840
'action': [
1841+
'<@(emulator)',
18381842
'<(PRODUCT_DIR)/gen_node_def.exe',
18391843
'<@(_inputs)',
18401844
'<@(_outputs)',

tools/v8_gypfiles/v8.gyp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@
149149
'<@(torque_outputs_inc)',
150150
],
151151
'action': [
152+
'<@(emulator)',
152153
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)torque<(EXECUTABLE_SUFFIX)',
153154
'-o', '<(SHARED_INTERMEDIATE_DIR)/torque-generated',
154155
'-v8-root', '<(V8_ROOT)',
@@ -269,6 +270,7 @@
269270
'action': [
270271
'<(python)',
271272
'<(V8_ROOT)/tools/run.py',
273+
'<@(emulator)',
272274
'<@(_inputs)',
273275
'<@(_outputs)',
274276
],
@@ -470,6 +472,7 @@
470472
}],
471473
],
472474
'action': [
475+
'<@(emulator)',
473476
'>@(_inputs)',
474477
'>@(mksnapshot_flags)',
475478
],
@@ -1990,6 +1993,7 @@
19901993
'action': [
19911994
'<(python)',
19921995
'<(V8_ROOT)/tools/run.py',
1996+
'<@(emulator)',
19931997
'<@(_inputs)',
19941998
'<@(_outputs)',
19951999
],

0 commit comments

Comments
 (0)