Skip to content

Commit 66f6ac0

Browse files
tierichardlau
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 <duhamelantoine1995@gmail.com> Reviewed-By: Aviv Keller <me@aviv.sh>
1 parent 570952d commit 66f6ac0

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',
@@ -2936,6 +2942,14 @@ def make_bin_override():
29362942
# will fail to run python scripts.
29372943
gyp_args += ['-Dpython=' + python]
29382944

2945+
if options.emulator is not None:
2946+
if not options.cross_compiling:
2947+
# Note that emulator is a list so we have to quote the variable.
2948+
gyp_args += ['-Demulator=' + shlex.quote(options.emulator)]
2949+
else:
2950+
# TODO: perhaps use emulator for tests?
2951+
warn('The `--emulator` option has no effect when cross-compiling.')
2952+
29392953
if not options.v8_disable_temporal_support or not options.shared_temporal_capi:
29402954
cargo = os.environ.get('CARGO')
29412955
if cargo:

node.gyp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,6 +1073,7 @@
10731073
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
10741074
],
10751075
'action': [
1076+
'<@(emulator)',
10761077
'<(node_js2c_exec)',
10771078
'<@(_outputs)',
10781079
'lib',
@@ -1139,6 +1140,7 @@
11391140
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
11401141
],
11411142
'action': [
1143+
'<@(emulator)',
11421144
'<(node_mksnapshot_exec)',
11431145
'--build-snapshot',
11441146
'<(node_snapshot_main)',
@@ -1158,6 +1160,7 @@
11581160
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
11591161
],
11601162
'action': [
1163+
'<@(emulator)',
11611164
'<@(_inputs)',
11621165
'<@(_outputs)',
11631166
],
@@ -1816,6 +1819,7 @@
18161819
'<(PRODUCT_DIR)/<(node_core_target_name).def',
18171820
],
18181821
'action': [
1822+
'<@(emulator)',
18191823
'<(PRODUCT_DIR)/gen_node_def.exe',
18201824
'<@(_inputs)',
18211825
'<@(_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)