Skip to content

Commit 42fa83e

Browse files
Cynerdtie
andcommitted
nodejs: fix cross compilation for armv7l
The v8 library supports only limited number of build platforms based on the host architecture. The rule there is the bitness (the mixing of 32bit and 64bit architectures seems to be in most cases disallowed). Thus this adds usage of the emulator of the host platform and builds tools for that. This also allows us to use ninja instead of make when build ≠ host while waiting for nodejs/gyp-next#185 to be merged. Co-authored-by: Ivan Trubach <[email protected]>
1 parent 8cc8565 commit 42fa83e

File tree

6 files changed

+339
-48
lines changed

6 files changed

+339
-48
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
From eaf2e55c472ce1b71e74d9d30b287be74a2e2b7a Mon Sep 17 00:00:00 2001
2+
From: Ivan Trubach <[email protected]>
3+
Date: Mon, 15 Jul 2024 11:43:43 +0300
4+
Subject: [PATCH] tools: support setting an emulator from configure script
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
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).
13+
14+
To work around this issue, build the binaries for the host platform and
15+
run them on the host with an emulator (if set from configure.py).
16+
17+
Based on Buildroot’s nodejs-src 0001-add-qemu-wrapper-support.patch.
18+
https://gitlab.com/buildroot.org/buildroot/-/raw/c1d5eada4d4db9eeaa1c44dd1dea95a67c8a70ca/package/nodejs/nodejs-src/0001-add-qemu-wrapper-support.patch
19+
---
20+
common.gypi | 1 +
21+
configure.py | 9 +++++++++
22+
node.gyp | 3 +++
23+
tools/v8_gypfiles/v8.gyp | 4 ++++
24+
4 files changed, 17 insertions(+)
25+
26+
diff --git a/common.gypi b/common.gypi
27+
index ec92c9df4c..6474495ab6 100644
28+
--- a/common.gypi
29+
+++ b/common.gypi
30+
@@ -13,6 +13,7 @@
31+
'enable_pgo_generate%': '0',
32+
'enable_pgo_use%': '0',
33+
'python%': 'python',
34+
+ 'emulator%': [],
35+
36+
'node_shared%': 'false',
37+
'force_dynamic_crt%': 0,
38+
diff --git a/configure.py b/configure.py
39+
index 82916748fd..f1d332eefc 100755
40+
--- a/configure.py
41+
+++ b/configure.py
42+
@@ -112,6 +112,12 @@ parser.add_argument('--dest-cpu',
43+
choices=valid_arch,
44+
help=f"CPU architecture to build for ({', '.join(valid_arch)})")
45+
46+
+parser.add_argument('--emulator',
47+
+ action='store',
48+
+ dest='emulator',
49+
+ default=None,
50+
+ help='use an emulator to run intermediate build tools')
51+
+
52+
parser.add_argument('--cross-compiling',
53+
action='store_true',
54+
dest='cross_compiling',
55+
@@ -2167,6 +2173,9 @@ elif flavor == 'win' and sys.platform != 'msys':
56+
else:
57+
gyp_args += ['-f', 'make-' + flavor]
58+
59+
+if options.emulator is not None:
60+
+ gyp_args += ['-Demulator=' + options.emulator]
61+
+
62+
if options.compile_commands_json:
63+
gyp_args += ['-f', 'compile_commands_json']
64+
os.path.islink('./compile_commands.json') and os.unlink('./compile_commands.json')
65+
diff --git a/node.gyp b/node.gyp
66+
index 08cb3f38e8..515b305933 100644
67+
--- a/node.gyp
68+
+++ b/node.gyp
69+
@@ -332,6 +332,7 @@
70+
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
71+
],
72+
'action': [
73+
+ '<@(emulator)',
74+
'<(node_mksnapshot_exec)',
75+
'--build-snapshot',
76+
'<(node_snapshot_main)',
77+
@@ -351,6 +352,7 @@
78+
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
79+
],
80+
'action': [
81+
+ '<@(emulator)',
82+
'<@(_inputs)',
83+
'<@(_outputs)',
84+
],
85+
@@ -1520,6 +1522,7 @@
86+
'<(PRODUCT_DIR)/<(node_core_target_name).def',
87+
],
88+
'action': [
89+
+ '<@(emulator)',
90+
'<(PRODUCT_DIR)/gen_node_def.exe',
91+
'<@(_inputs)',
92+
'<@(_outputs)',
93+
diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
94+
index ba8b161f0f..d5c90dad50 100644
95+
--- a/tools/v8_gypfiles/v8.gyp
96+
+++ b/tools/v8_gypfiles/v8.gyp
97+
@@ -99,6 +99,7 @@
98+
'<@(torque_outputs_inc)',
99+
],
100+
'action': [
101+
+ '<@(emulator)',
102+
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)torque<(EXECUTABLE_SUFFIX)',
103+
'-o', '<(SHARED_INTERMEDIATE_DIR)/torque-generated',
104+
'-v8-root', '<(V8_ROOT)',
105+
@@ -219,6 +220,7 @@
106+
'action': [
107+
'<(python)',
108+
'<(V8_ROOT)/tools/run.py',
109+
+ '<@(emulator)',
110+
'<@(_inputs)',
111+
'<@(_outputs)',
112+
],
113+
@@ -442,6 +444,7 @@
114+
}],
115+
],
116+
'action': [
117+
+ '<@(emulator)',
118+
'>@(_inputs)',
119+
'>@(mksnapshot_flags)',
120+
],
121+
@@ -1577,6 +1580,7 @@
122+
'action': [
123+
'<(python)',
124+
'<(V8_ROOT)/tools/run.py',
125+
+ '<@(emulator)',
126+
'<@(_inputs)',
127+
'<@(_outputs)',
128+
],
129+
--
130+
2.44.1
131+
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
From 438e3a08bf76bc0a9a098c16847e9029e20e240f Mon Sep 17 00:00:00 2001
2+
From: Ivan Trubach <[email protected]>
3+
Date: Mon, 15 Jul 2024 11:43:43 +0300
4+
Subject: [PATCH] tools: support setting an emulator from configure script
5+
MIME-Version: 1.0
6+
Content-Type: text/plain; charset=UTF-8
7+
Content-Transfer-Encoding: 8bit
8+
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).
13+
14+
To work around this issue, build the binaries for the host platform and
15+
run them on the host with an emulator (if set from configure.py).
16+
17+
Based on Buildroot’s nodejs-src 0001-add-qemu-wrapper-support.patch.
18+
https://gitlab.com/buildroot.org/buildroot/-/raw/c1d5eada4d4db9eeaa1c44dd1dea95a67c8a70ca/package/nodejs/nodejs-src/0001-add-qemu-wrapper-support.patch
19+
---
20+
common.gypi | 1 +
21+
configure.py | 9 +++++++++
22+
node.gyp | 4 ++++
23+
tools/v8_gypfiles/v8.gyp | 4 ++++
24+
4 files changed, 18 insertions(+)
25+
26+
diff --git a/common.gypi b/common.gypi
27+
index 3e1902fb78..e4940448ac 100644
28+
--- a/common.gypi
29+
+++ b/common.gypi
30+
@@ -13,6 +13,7 @@
31+
'enable_pgo_generate%': '0',
32+
'enable_pgo_use%': '0',
33+
'python%': 'python',
34+
+ 'emulator%': [],
35+
36+
'node_shared%': 'false',
37+
'force_dynamic_crt%': 0,
38+
diff --git a/configure.py b/configure.py
39+
index ee08264e91..02160ba1fa 100755
40+
--- a/configure.py
41+
+++ b/configure.py
42+
@@ -112,6 +112,12 @@ parser.add_argument('--dest-cpu',
43+
choices=valid_arch,
44+
help=f"CPU architecture to build for ({', '.join(valid_arch)})")
45+
46+
+parser.add_argument('--emulator',
47+
+ action='store',
48+
+ dest='emulator',
49+
+ default=None,
50+
+ help='use an emulator to run intermediate build tools')
51+
+
52+
parser.add_argument('--cross-compiling',
53+
action='store_true',
54+
dest='cross_compiling',
55+
@@ -2114,6 +2120,9 @@ elif flavor == 'win' and sys.platform != 'msys':
56+
else:
57+
gyp_args += ['-f', 'make-' + flavor]
58+
59+
+if options.emulator is not None:
60+
+ gyp_args += ['-Demulator=' + options.emulator]
61+
+
62+
if options.compile_commands_json:
63+
gyp_args += ['-f', 'compile_commands_json']
64+
65+
diff --git a/node.gyp b/node.gyp
66+
index cf016ef468..880449d9bb 100644
67+
--- a/node.gyp
68+
+++ b/node.gyp
69+
@@ -643,6 +643,7 @@
70+
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
71+
],
72+
'action': [
73+
+ '<@(emulator)',
74+
'<(node_mksnapshot_exec)',
75+
'--build-snapshot',
76+
'<(node_snapshot_main)',
77+
@@ -662,6 +663,7 @@
78+
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
79+
],
80+
'action': [
81+
+ '<@(emulator)',
82+
'<@(_inputs)',
83+
'<@(_outputs)',
84+
],
85+
@@ -952,6 +954,7 @@
86+
'<(SHARED_INTERMEDIATE_DIR)/node_javascript.cc',
87+
],
88+
'action': [
89+
+ '<@(emulator)',
90+
'<(node_js2c_exec)',
91+
'<@(_outputs)',
92+
'lib',
93+
@@ -1340,6 +1343,7 @@
94+
'<(PRODUCT_DIR)/<(node_core_target_name).def',
95+
],
96+
'action': [
97+
+ '<@(emulator)',
98+
'<(PRODUCT_DIR)/gen_node_def.exe',
99+
'<@(_inputs)',
100+
'<@(_outputs)',
101+
diff --git a/tools/v8_gypfiles/v8.gyp b/tools/v8_gypfiles/v8.gyp
102+
index f822c056e5..b7a629c54b 100644
103+
--- a/tools/v8_gypfiles/v8.gyp
104+
+++ b/tools/v8_gypfiles/v8.gyp
105+
@@ -112,6 +112,7 @@
106+
'<@(torque_outputs_inc)',
107+
],
108+
'action': [
109+
+ '<@(emulator)',
110+
'<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)torque<(EXECUTABLE_SUFFIX)',
111+
'-o', '<(SHARED_INTERMEDIATE_DIR)/torque-generated',
112+
'-v8-root', '<(V8_ROOT)',
113+
@@ -232,6 +233,7 @@
114+
'action': [
115+
'<(python)',
116+
'<(V8_ROOT)/tools/run.py',
117+
+ '<@(emulator)',
118+
'<@(_inputs)',
119+
'<@(_outputs)',
120+
],
121+
@@ -443,6 +445,7 @@
122+
}],
123+
],
124+
'action': [
125+
+ '<@(emulator)',
126+
'>@(_inputs)',
127+
'>@(mksnapshot_flags)',
128+
],
129+
@@ -1668,6 +1671,7 @@
130+
'action': [
131+
'<(python)',
132+
'<(V8_ROOT)/tools/run.py',
133+
+ '<@(emulator)',
134+
'<@(_inputs)',
135+
'<@(_outputs)',
136+
],
137+
--
138+
2.44.1
139+

0 commit comments

Comments
 (0)