1 From 999d918bc8fefec1752243743a47c0ce5380bcec Mon Sep 17 00:00:00 2001
2 From: Ivan Trubach <mr.trubach@icloud.com>
3 Date: Wed, 17 Jul 2024 10:16:02 +0300
4 Subject: [PATCH] build: support setting an emulator from configure script
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
9 V8’s JIT infrastructure requires binaries such as mksnapshot to be run
10 during the build. However, these binaries must have the same bit-width
11 as the host platform (e.g. a x86_64 build platform targeting ARMv6 needs
12 to produce a 32-bit binary).
14 To work around this issue, allow building the binaries for the host
15 platform and running them on the build platform with an emulator.
17 Based on Buildroot’s nodejs-src 0001-add-qemu-wrapper-support.patch.
18 https://gitlab.com/buildroot.org/buildroot/-/blob/c1d5eada4d4db9eeaa1c44dd1dea95a67c8a70ca/package/nodejs/nodejs-src/0001-add-qemu-wrapper-support.patch
20 Upstream: https://github.com/nodejs/node/pull/53899
23 configure.py | 14 ++++++++++++++
25 tools/v8_gypfiles/v8.gyp | 4 ++++
26 4 files changed, 23 insertions(+)
28 diff --git a/common.gypi b/common.gypi
29 index 154bbf2a0d..54d2afe3b3 100644
33 'enable_pgo_generate%': '0',
34 'enable_pgo_use%': '0',
38 'node_shared%': 'false',
39 'force_dynamic_crt%': 0,
40 diff --git a/configure.py b/configure.py
41 index f7e3310723..f7c7acdf4f 100755
44 @@ -112,6 +112,12 @@ parser.add_argument('--dest-cpu',
46 help=f"CPU architecture to build for ({', '.join(valid_arch)})")
48 +parser.add_argument('--emulator',
52 + help='emulator command that can run executables built for the target system')
54 parser.add_argument('--cross-compiling',
56 dest='cross_compiling',
57 @@ -2276,6 +2282,14 @@ if flavor == 'win' and python.lower().endswith('.exe'):
58 # will fail to run python scripts.
59 gyp_args += ['-Dpython=' + python]
61 +if options.emulator is not None:
62 + if not options.cross_compiling:
63 + # Note that emulator is a list so we have to quote the variable.
64 + gyp_args += ['-Demulator=' + shlex.quote(options.emulator)]
66 + # TODO: perhaps use emulator for tests?
67 + warn('The `--emulator` option has no effect when cross-compiling.')
70 gyp_args += ['-f', 'ninja-' + flavor]
71 elif flavor == 'win' and sys.platform != 'msys':
72 diff --git a/node.gyp b/node.gyp
73 index 9617596760..439c76aca6 100644
77 '<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
81 '<(node_mksnapshot_exec)',
83 '<(node_snapshot_main)',
85 '<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
93 '<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
100 @@ -1477,6 +1480,7 @@
101 '<(PRODUCT_DIR)/<(node_core_target_name).def',
105 '<(PRODUCT_DIR)/gen_node_def.exe',
108 diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
109 index d65a5c268e..5cd6c36b86 100644
110 --- a/tools/v8_gypfiles/v8.gyp
111 +++ b/tools/v8_gypfiles/v8.gyp
113 '<@(torque_outputs_inc)',
117 '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)torque<(EXECUTABLE_SUFFIX)',
118 '-o', '<(SHARED_INTERMEDIATE_DIR)/torque-generated',
119 '-v8-root', '<(V8_ROOT)',
123 '<(V8_ROOT)/tools/run.py',
134 '>@(mksnapshot_flags)',
136 @@ -1842,6 +1845,7 @@
139 '<(V8_ROOT)/tools/run.py',