-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
ci5.html
522 lines (486 loc) · 31 KB
/
ci5.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<title>macOS Build Farm for Apache NuttX RTOS (Apple Silicon)</title>
<!-- Begin scripts/articles/*-header.html: Article Header for Custom Markdown files processed by rustdoc, like chip8.md -->
<meta property="og:title"
content="macOS Build Farm for Apache NuttX RTOS (Apple Silicon)"
data-rh="true">
<meta property="og:description"
content="Folks on macOS: Compiling Apache NuttX RTOS used to be so tiresome. Not any more! In this article, we explain how to build anything on macOS, by patching the NuttX CI Script. Which also becomes our macOS Build Farm."
data-rh="true">
<meta name="description"
content="Folks on macOS: Compiling Apache NuttX RTOS used to be so tiresome. Not any more! In this article, we explain how to build anything on macOS, by patching the NuttX CI Script. Which also becomes our macOS Build Farm.">
<meta property="og:image"
content="https://lupyuen.github.io/images/ci5-title.png">
<meta property="og:type"
content="article" data-rh="true">
<link rel="canonical"
href="https://lupyuen.org/articles/ci5.html" />
<!-- End scripts/articles/*-header.html -->
<!-- Begin scripts/rustdoc-header.html: Header for Custom Markdown files processed by rustdoc, like chip8.md -->
<link rel="alternate" type="application/rss+xml" title="RSS Feed for lupyuen" href="/rss.xml" />
<link rel="stylesheet" type="text/css" href="../normalize.css">
<link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle">
<link rel="stylesheet" type="text/css" href="../dark.css">
<link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle">
<link rel="stylesheet" type="text/css" href="../prism.css">
<script src="../storage.js"></script><noscript>
<link rel="stylesheet" href="../noscript.css"></noscript>
<link rel="shortcut icon" href="../favicon.ico">
<style type="text/css">
#crate-search {
background-image: url("../down-arrow.svg");
}
</style>
<!-- End scripts/rustdoc-header.html -->
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<!-- Begin scripts/rustdoc-before.html: Pre-HTML for Custom Markdown files processed by rustdoc, like chip8.md -->
<!-- Begin Theme Picker -->
<div class="theme-picker" style="left: 0"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg"
width="18" alt="Pick another theme!"></button>
<div id="theme-choices"></div>
</div>
<!-- Theme Picker -->
<!-- End scripts/rustdoc-before.html -->
<h1 class="title">macOS Build Farm for Apache NuttX RTOS (Apple Silicon)</h1>
<nav id="rustdoc"><ul>
<li><a href="#fix-the-path" title="Fix the PATH!">1 Fix the PATH!</a><ul></ul></li>
<li><a href="#build-anything-on-macos" title="Build Anything on macOS">2 Build Anything on macOS</a><ul></ul></li>
<li><a href="#patch-the-ci-script" title="Patch the CI Script">3 Patch the CI Script</a><ul></ul></li>
<li><a href="#except-these-targets" title="Except These Targets">4 Except These Targets</a><ul></ul></li>
<li><a href="#macos-build-farm" title="macOS Build Farm">5 macOS Build Farm</a><ul></ul></li>
<li><a href="#mac-gets-smokin-hot" title="Mac Gets Smokin’ Hot">6 Mac Gets Smokin’ Hot</a><ul></ul></li>
<li><a href="#macos-reconsidered" title="macOS Reconsidered">7 macOS Reconsidered</a><ul></ul></li>
<li><a href="#whats-next" title="What’s Next">8 What’s Next</a><ul></ul></li></ul></nav><p>📝 <em>8 Dec 2024</em></p>
<p><img src="https://lupyuen.github.io/images/ci5-title.png" alt="macOS Build Farm for Apache NuttX RTOS (Apple Silicon)" /></p>
<p><strong>Folks on macOS:</strong> Compiling <a href="https://nuttx.apache.org/docs/latest/"><strong>Apache NuttX RTOS</strong></a> used to be so tiresome. Not any more! <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-build-macos.sh">run-build-macos.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Build Anything on Apple Silicon macOS:
## Arm32, RISC-V and Xtensa!
git clone https://github.com/lupyuen/nuttx-build-farm
cd nuttx-build-farm
./run-build-macos.sh raspberrypi-pico:nsh
./run-build-macos.sh ox64:nsh
./run-build-macos.sh esp32s3-devkit:nsh
## NuttX Executable will be at
## /tmp/run-build-macos/nuttx</code></pre></div>
<p>In this article, we explain…</p>
<ul>
<li>
<p>How we <strong>Build Anything</strong> on macOS Arm64</p>
</li>
<li>
<p>By patching the <strong>NuttX CI Script</strong> for macOS</p>
</li>
<li>
<p>Which also becomes our <strong>macOS Build Farm</strong></p>
</li>
<li>
<p>Thanks to the awesome work by <a href="https://github.com/simbit18"><strong>Simbit18</strong></a>!</p>
</li>
<li>
<p><strong>Can macOS replace a PC?</strong> Not quite yet</p>
</li>
<li>
<p>Because some NuttX Targets <strong>won’t build</strong> correctly</p>
</li>
</ul>
<blockquote>
<p><img src="https://lupyuen.github.io/images/ci5-path.png" alt="GNU Coreutils and Binutils on PATH are also known to break build in MacOS" /></p>
</blockquote>
<blockquote>
<p><span style="font-size:80%"> <a href="https://github.com/pyenv/pyenv/issues/2862#issuecomment-1849198741"><em>“GNU Coreutils and Binutils on PATH are also known to break build in MacOS”</em></a> </span></p>
</blockquote>
<h1 id="fix-the-path"><a class="doc-anchor" href="#fix-the-path">§</a>1 Fix the PATH!</h1>
<p><strong>Super Important!</strong> NuttX won’t build correctly on macOS unless we remove <strong>Homebrew <code>ar</code></strong> from <strong>PATH</strong>: <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-job-macos.sh#L32-L46">run-job-macos.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Remove Homebrew `ar` from PATH
## Instead: We use `/usr/bin/ar`
## https://github.com/pyenv/pyenv/issues/2862#issuecomment-1849198741
export PATH=$(
echo $PATH \
| tr ':' '\n' \
| grep -v "/opt/homebrew/opt/make/libexec/gnubin" \
| grep -v "/opt/homebrew/opt/coreutils/libexec/gnubin" \
| grep -v "/opt/homebrew/opt/binutils/bin" \
| tr '\n' ':'
)
if [[ $(which ar) != "/usr/bin/ar" ]]; then
echo "ERROR: Expected 'which ar' to return /usr/bin/ar, not $(which ar)"
exit 1
fi</code></pre></div>
<p>Thus we should always do the above before compiling NuttX. Otherwise we’ll see a conflict between the <a href="https://github.com/apache/nuttx/pull/14691#issuecomment-2462583245"><strong>Homebrew and Clang Linkers</strong></a>…</p>
<div class="example-wrap"><pre class="language-text"><code>ld: archive member '/' not a mach-o file in 'libgp.a'
clang++: error: linker command failed with exit code 1 (use -v to see invocation)</code></pre></div>
<p><img src="https://lupyuen.github.io/images/ci5-build.png" alt="Building raspberrypi-pico:nsh on macOS" /></p>
<h1 id="build-anything-on-macos"><a class="doc-anchor" href="#build-anything-on-macos">§</a>2 Build Anything on macOS</h1>
<p>Earlier we talked about compiling <strong>Any NuttX Target</strong> on macOS: <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-build-macos.sh">run-build-macos.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Build Anything on Apple Silicon macOS:
## Arm32, RISC-V and Xtensa!
git clone https://github.com/lupyuen/nuttx-build-farm
cd nuttx-build-farm
./run-build-macos.sh raspberrypi-pico:nsh
./run-build-macos.sh ox64:nsh
./run-build-macos.sh esp32s3-devkit:nsh
## NuttX Executable will be at
## /tmp/run-build-macos/nuttx
## To re-download the GCC Toolchains
## rm -rf /tmp/run-build-macos</code></pre></div>
<p>And it works on <strong>Apple Silicon</strong>! M1, M2, M3, M4, …</p>
<div class="example-wrap"><pre class="language-text"><code>$ ./run-build-macos.sh raspberrypi-pico:nsh
Configuration/Tool: raspberrypi-pico/nsh,CONFIG_ARM_TOOLCHAIN_GNU_EABI
Cleaning...
Configuring...
Disabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
Enabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
Building NuttX...
Normalize raspberrypi-pico/nsh</code></pre></div>
<ul>
<li>
<p><a href="https://gist.github.com/lupyuen/5feabeb03f07da716745f9edde73babb"><strong>Build Log for Arm32</strong></a> <em>(raspberrypi-pico:nsh)</em></p>
</li>
<li>
<p><a href="https://gist.github.com/lupyuen/0274fa1ed737d3c82a6b11883a4ad761"><strong>Build Log for RISC-V</strong></a> <em>(ox64:nsh)</em></p>
</li>
<li>
<p><a href="https://gist.github.com/lupyuen/2e9934d78440551f10771b7afcbb33be"><strong>Build Log for Xtensa</strong></a> <em>(esp32s3-devkit:nsh)</em></p>
</li>
<li>
<p>With <strong>Some Exceptions</strong>, see below</p>
</li>
</ul>
<p><em>Huh what about the GCC Toolchains? Arm32, RISC-V, Xtensa…</em></p>
<p><strong>Toolchains are Auto-Downloaded</strong>. Thanks to the brilliant Continuous Integration Script by <a href="https://github.com/simbit18"><strong>Simbit18</strong></a>!</p>
<ul>
<li>
<p><a href="https://github.com/apache/nuttx/pull/14723"><strong>NuttX CI for macOS Arm64</strong></a> <em>(darwin_arm64.sh)</em></p>
</li>
<li>
<p><a href="https://github.com/apache/nuttx/pull/14934"><strong>Add Xtensa Toolchain</strong></a></p>
</li>
<li>
<p><a href="https://github.com/apache/nuttx/commits/master/tools/ci/platforms/darwin_arm64.sh"><strong>Plus more updates</strong></a></p>
</li>
<li>
<p><a href="https://github.com/apache/nuttx/pull/14691"><strong>How it started</strong></a></p>
</li>
</ul>
<p>Just make sure we’ve installed <a href="https://brew.sh"><strong>brew</strong></a>, <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-build-macos.sh#L1-L11"><strong>neofetch</strong></a> and <a href="https://www.makeuseof.com/install-xcode-command-line-tools/"><strong>Xcode Command-Line Tools</strong></a>.</p>
<p><a href="https://github.com/apache/nuttx/blob/master/.github/workflows/build.yml#L239-L251">(Yep the same script drives our <strong>GitHub Daily Builds</strong>)</a></p>
<blockquote>
<p><img src="https://lupyuen.github.io/images/ci5-toolchains.png" alt="Toolchains are downloaded in 10 mins, subsequent builds are quicker" /></p>
</blockquote>
<blockquote>
<p><span style="font-size:80%"> <a href="https://gist.github.com/lupyuen/0274fa1ed737d3c82a6b11883a4ad761#file-gistfile1-txt-L4236"><em>Toolchains are downloaded in <strong>10 mins</strong>, subsequent builds are quicker</em></a> </span></p>
</blockquote>
<h1 id="patch-the-ci-script"><a class="doc-anchor" href="#patch-the-ci-script">§</a>3 Patch the CI Script</h1>
<p><em>We’re running the NuttX CI Script on our computer. How does it work?</em></p>
<p>This is how we call <a href="https://github.com/apache/nuttx/blob/master/tools/ci/cibuild.sh"><em>tools/ci/cibuild.sh</em></a> to Download the Toolchains and <strong>Compile our NuttX Target</strong>: <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-build-macos.sh">run-build-macos.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Let's download the NuttX Toolchains and Run a NuttX Build on macOS
## First we checkout the NuttX Repo and NuttX Apps...
tmp_dir=/tmp/run-build-macos
cd $tmp_dir
git clone https://github.com/apache/nuttx
git clone https://github.com/apache/nuttx-apps apps
## Then we patch the NuttX CI Script for Apple Silicon: darwin_arm64.sh
## Which will trigger an "uncommitted files" warning later
pushd nuttx
$script_dir/patch-ci-macos.sh ## https://github.com/lupyuen/nuttx-build-farm/blob/main/patch-ci-macos.sh
popd
## Omitted: Suppress the uncommitted darwin_arm64.sh warning:
## We copy the patched "nuttx" folder to "nuttx-patched"
## Then restore the original "nuttx" folder
...
## NuttX CI Build expects this Target Format:
## /arm/rp2040/raspberrypi-pico/configs/nsh,CONFIG_ARM_TOOLCHAIN_GNU_EABI
## /risc-v/bl808/ox64/configs/nsh
## /xtensa/esp32s3/esp32s3-devkit/configs/nsh
target_file=$tmp_dir/target.dat
rm -f $target_file
echo "/arm/*/$board/configs/$config,CONFIG_ARM_TOOLCHAIN_GNU_EABI" >>$target_file
echo "/arm64/*/$board/configs/$config" >>$target_file
echo "/risc-v/*/$board/configs/$config" >>$target_file
echo "/sim/*/$board/configs/$config" >>$target_file
echo "/x86_64/*/$board/configs/$config" >>$target_file
echo "/xtensa/*/$board/configs/$config" >>$target_file
## Run the NuttX CI Build in "nuttx-patched"
pushd nuttx-patched/tools/ci
(
./cibuild.sh -i -c -A -R $target_file \
|| echo '***** BUILD FAILED'
)
popd</code></pre></div>
<p><em>What is patch-ci-macos.sh?</em></p>
<p><strong>To run NuttX CI Locally:</strong> We made Minor Tweaks. Somehow this Python Environment runs OK at <strong>GitHub Actions</strong>: <a href="https://github.com/apache/nuttx/blob/master/tools/ci/platforms/darwin_arm64.sh#L209-L250">darwin_arm64.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Original Python Environment:
## Works OK for GitHub Actions
python_tools() { ...
python3 \
-m venv \
--system-site-packages /opt/homebrew ...</code></pre></div>
<p>But it doesn’t work locally. Hence we patch <a href="https://github.com/apache/nuttx/blob/master/tools/ci/platforms/darwin_arm64.sh"><em>darwin_arm64.sh</em></a> to <strong>Run Locally</strong>: <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/patch-ci-macos.sh#L52-L75">patch-ci-macos.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Modified Python Environment:
## For Local macOS
python_tools() {
python3 -m venv .venv
source .venv/bin/activate</code></pre></div>
<p><em>Why the “uncommitted darwin_arm64.sh warning”?</em></p>
<p>Remember we just patched <em>darwin_arm64.sh</em>? NuttX CI is super picky about <strong>Modified Files</strong>, it will warn us because we changed <em>darwin_arm64.sh</em>.</p>
<p><strong>Our Workaround:</strong> We copy the modified <em>nuttx</em> folder to <em>nuttx-patched</em>. Then we run NuttX CI from <em>nuttx-patched</em> folder: <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-build-macos.sh#L89-L134">run-build-macos.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Suppress the uncommitted darwin_arm64.sh warning:
## We copy the patched "nuttx" folder to "nuttx-patched"
## Then restore the original "nuttx" folder
cp -r nuttx nuttx-patched
pushd nuttx
git restore tools/ci
popd
## Patch the CI Job cibuild.sh to point to "nuttx-patched"
## Change: CIPLAT=${CIWORKSPACE}/nuttx/tools/ci/platforms
## To: CIPLAT=${CIWORKSPACE}/nuttx-patched/tools/ci/platforms
file=nuttx-patched/tools/ci/cibuild.sh
tmp_file=$tmp_dir/cibuild.sh
search='\/nuttx\/tools\/'
replace='\/nuttx-patched\/tools\/'
cat $file \
| sed "s/$search/$replace/g" \
>$tmp_file
mv $tmp_file $file
chmod +x $file
## Run the NuttX CI Build in "nuttx-patched"
pushd nuttx-patched/tools/ci
./cibuild.sh -i -c -A -R $target_file
...</code></pre></div>
<p><img src="https://lupyuen.github.io/images/ci5-simnsh.png" alt="macOS won’t compile sim:nsh" /></p>
<h1 id="except-these-targets"><a class="doc-anchor" href="#except-these-targets">§</a>4 Except These Targets</h1>
<p><em>Awesome! We can compile Everything NuttX on macOS Arm64?</em></p>
<p>Erm sorry not quite. These NuttX Targets <strong>won’t compile on macOS</strong>…</p>
<span style="font-size:90%">
<div><table><thead><tr><th style="text-align: left">Group</th><th style="text-align: left">Target</th><th style="text-align: left">Troubles</th></tr></thead><tbody>
<tr><td style="text-align: left"><strong>arm-05</strong></td><td style="text-align: left"><a href="https://gist.github.com/lupyuen/1ce979b38c32943545fdde6da144998d"><em>nrf5340-dk : <br> rpmsghci_nimble_cpuapp</em></a></td><td style="text-align: left"><em>ble_svc_gatt.c: rc set but not used</em></td></tr>
<tr><td style="text-align: left"><strong>arm-07</strong></td><td style="text-align: left"><a href="https://gist.github.com/lupyuen/e2129ba7aa707372be5c13d733b14044"><em>ucans32k146 : <br> se05x</em></a></td><td style="text-align: left"><em>mv: illegal option T</em></td></tr>
<tr><td style="text-align: left"><strong>arm64-01</strong></td><td style="text-align: left"><a href="https://gist.github.com/lupyuen/90d5825725c5abfe89805f104bfa8696"><em>imx93-evk : <br> bootloader</em></a></td><td style="text-align: left"><em>ld: library not found for -lcrt0.o</em></td></tr>
<tr><td style="text-align: left"><strong>other</strong></td><td style="text-align: left"><a href="https://gist.github.com/lupyuen/966ba9c1bafdfb4cc11625c68a66709b"><em>micropendous3 : <br> hello</em></a></td><td style="text-align: left"><em>avr-objcopy: Bad CPU type in executable</em></td></tr>
<tr><td style="text-align: left"><strong>sim-01 to 03</strong></td><td style="text-align: left"><a href="https://gist.github.com/lupyuen/41955b62a7620cd65e49c6202dc73e6d"><em>sim : <br> nsh</em></a></td><td style="text-align: left"><em>clang: invalid argument ‘medium’ to -mcmodel=</em></td></tr>
<tr><td style="text-align: left"><strong>x86_64-01</strong></td><td style="text-align: left"><a href="https://gist.github.com/lupyuen/2771ee11a07f0a33bf0c5d8ef2e5db5f"><em>qemu-intel64 : <br> jumbo</em></a></td><td style="text-align: left"><em>arg_rex.c: setjmp.h: No such file or directory</em></td></tr>
<tr><td style="text-align: left"><strong>xtensa-02</strong></td><td style="text-align: left"><a href="https://gist.github.com/lupyuen/d3a45a1cb247649e83c0c240eb233fd3"><em>esp32s3-devkit : <br> qemu_debug</em></a></td><td style="text-align: left"><em>xtensa_hostfs.c: SIMCALL_O_NONBLOCK undeclared</em></td></tr>
<tr><td style="text-align: left"><strong>xtensa-02</strong></td><td style="text-align: left"><a href="https://gist.github.com/lupyuen/122a9d572e486b43d3eb60edb44f2189"><em>esp32s3-devkit : <br> knsh</em></a></td><td style="text-align: left"><em>sed: invalid command code .</em></td></tr>
<tr><td style="text-align: left"><strong>Clang Groups</strong></td><td style="text-align: left"><a href="https://github.com/apache/nuttx/pull/14691#issuecomment-2466518544"><em>Clang Targets</em></a></td><td style="text-align: left"><em>clang++: configuration file cannot be found</em></td></tr>
<tr><td style="text-align: left"> </td><td style="text-align: left"></td><td style="text-align: left"></td></tr>
</tbody></table>
</div></span>
<p>We’ll come back to this. First we talk about NuttX Build Farm…</p>
<p><img src="https://lupyuen.github.io/images/ci5-farm.jpg" alt="macOS Build Farm" /></p>
<h1 id="macos-build-farm"><a class="doc-anchor" href="#macos-build-farm">§</a>5 macOS Build Farm</h1>
<p><em>What’s this macOS Build Farm?</em></p>
<p>Earlier we compiled NuttX for One Single Target. Now we scale up and <strong>Compile All NuttX Targets</strong>… Non-Stop 24 by 7!</p>
<p>This becomes our Community-Hosted <strong>macOS Build Farm</strong> for NuttX.</p>
<p><a href="https://lupyuen.github.io/articles/ci4">(Why? So we can <strong>Catch Build Errors</strong> without depending on GitHub Actions)</a></p>
<p>If Your Mac has Spare CPU Cycles: Please join our <strong>macOS Build Farm</strong>! 🙏 Like so: <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run.sh">run.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Run the NuttX Build Farm for macOS.
## Set the GitHub Token: (Should have Gist Permission)
## export GITHUB_TOKEN=...
. $HOME/github-token.sh
brew install neofetch gh glab
## Run All NuttX CI Jobs on macOS
## Will repeat forever
git clone https://github.com/lupyuen/nuttx-build-farm
cd nuttx-build-farm
./run-ci-macos.sh
## To re-download the GCC Toolchains:
## rm -rf /tmp/run-job-macos
## For Testing:
## Run One Single NuttX CI Job on macOS
## ./run-job-macos.sh risc-v-01</code></pre></div>
<p>And please tell me your <strong>Gist User ID</strong>. (Also works for <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-ci-macos.sh#L1-L20"><strong>GitLab Snippets</strong></a>)</p>
<p>The Build Outcomes will appear in <a href="https://lupyuen.github.io/articles/ci4"><strong>NuttX Dashboard</strong></a>…</p>
<p><img src="https://lupyuen.github.io/images/ci5-dashboard.png" alt="macOS Build Farm for Apache NuttX RTOS (Apple Silicon)" /></p>
<p><em>How does it work?</em></p>
<p>macOS Build Farm shall run (nearly) <strong>All NuttX CI Jobs</strong>, forever and ever: <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-ci-macos.sh#L85-L139">run-ci-macos.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Run All NuttX CI Jobs on macOS, forever and ever.
## Arm32 Jobs run hotter (80 deg C) than RISC-V Jobs (70 deg C).
## So we stagger the jobs.
## risc-v-05: CI Test may hang, we move to the end
for (( ; ; )); do
for job in \
arm-08 risc-v-06 \
arm-09 xtensa-01 \
arm-10 arm-11 arm-12 arm-13 arm-14 \
arm-01 risc-v-01 \
arm-02 risc-v-02 \
arm-03 risc-v-03 \
arm-04 risc-v-04 \
arm-06 risc-v-05
do
## Run the CI Job and find Errors / Warnings
run_job $job
clean_log
find_messages
## Upload the log to GitLab Snippet or GitHub Gist
upload_log $job $nuttx_hash $apps_hash
done
done
## Run the NuttX CI Job (e.g. risc-v-01)
## Capture the output
function run_job {
local job=$1
pushd /tmp
script $log_file \
$script_option \
$script_dir/run-job-macos.sh $job
popd
}</code></pre></div><span style="font-size:90%">
<p><a href="https://lupyuen.github.io/articles/ci5#except-these-targets">(<strong>Some Target Groups</strong> won’t compile)</a></p>
<p><a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-ci-macos.sh#L37-L55">(<strong>clean_log</strong> removes Control Chars)</a></p>
<p><a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-ci-macos.sh#L55-L69">(<strong>find_messages</strong> searches for Errors)</a></p>
<p><a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-ci-macos.sh#L69-L81">(<strong>upload_log</strong> uploads to GitLab Snippet or GitHub Gist)</a></p>
</span>
<p><em>What’s inside run-job-macos.sh?</em></p>
<p>It will run one single <strong>NuttX CI Job</strong>. Similar to the <a href="https://lupyuen.github.io/articles/ci5#patch-the-ci-script"><strong>NuttX Build Script</strong></a> we saw earlier: <a href="https://github.com/lupyuen/nuttx-build-farm/blob/main/run-job-macos.sh">run-job-macos.sh</a></p>
<div class="example-wrap"><pre class="language-bash"><code>## Run one single NuttX CI Job on macOS (e.g. risc-v-01)
## Checkout the NuttX Repo and NuttX Apps
tmp_dir=/tmp/run-job-macos
cd $tmp_dir
git clone https://github.com/apache/nuttx
git clone https://github.com/apache/nuttx-apps apps
## Patch the macOS CI Job for Apple Silicon: darwin_arm64.sh
## Which will trigger an "uncommitted files" warning later
pushd nuttx
$script_dir/patch-ci-macos.sh ## https://github.com/lupyuen/nuttx-build-farm/blob/main/patch-ci-macos.sh
popd
## Omitted: Suppress the uncommitted darwin_arm64.sh warning:
## We copy the patched "nuttx" folder to "nuttx-patched"
## Then restore the original "nuttx" folder
...
## Exclude clang Targets from macOS Build
## Because they will fail due to unknown arch
## "/arm/lpc54xx,CONFIG_ARM_TOOLCHAIN_CLANG"
## https://github.com/apache/nuttx/pull/14691#issuecomment-2466518544
tmp_file=$tmp_dir/rewrite-testlist.dat
for file in nuttx-patched/tools/ci/testlist/*.dat; do
grep -v "CLANG" \
$file \
>$tmp_file
mv $tmp_file $file
done
## If CI Test Hangs: Kill it after 1 hour
( sleep 3600 ; echo Killing pytest after timeout... ; pkill -f pytest )&
## Run the CI Job in "nuttx-patched"
## ./cibuild.sh -i -c -A -R testlist/risc-v-01.dat
pushd nuttx-patched/tools/ci
(
./cibuild.sh -i -c -A -R testlist/$job.dat \
|| echo '***** BUILD FAILED'
)
popd</code></pre></div>
<p>Now we can cook some NuttX on macOS…</p>
<p><img src="https://lupyuen.github.io/images/ci5-title.png" alt="Mac Mini will get (nearly) Boiling Hot (90 deg C) when running the NuttX Build Farm" /></p>
<h1 id="mac-gets-smokin-hot"><a class="doc-anchor" href="#mac-gets-smokin-hot">§</a>6 Mac Gets Smokin’ Hot</h1>
<p><em>Anything we should worry about?</em></p>
<p>Yeah Mac Mini will get (nearly) <strong>Boiling Hot</strong> (90°C) when running the NuttX Build Farm! All CPU Cores will be <strong>100% Maxed Out</strong>. (M2 Pro, pic above)</p>
<p>I recommend <a href="https://www.tunabellysoftware.com/tgpro/"><strong>TG Pro</strong></a> for Fan Control. Set the <strong>Fan Speed to Auto-Max</strong>. (Pic below)</p>
<p>Which will trigger the fans at <strong>70°C</strong> (red bar below), keeping things cooler. (Compare the green bars with above)</p>
<p>Do you have a <strong>Mac Pro</strong> or <strong>M4 Pro</strong>? Please test the <a href="https://lupyuen.github.io/articles/ci5#macos-build-farm"><strong>NuttX Build Farm</strong></a>! 🙏</p>
<p>(<a href="https://github.com/devMEremenko/XcodeBenchmark"><strong>Xcode Benchmark</strong></a> suggests Your Mac might be twice as fast as my M2 Pro)</p>
<p><img src="https://lupyuen.github.io/images/ci5-fan.png" alt="TG Pro will trigger the fans at 70 deg C" /></p>
<p><em>Is macOS Arm64 faster than Intel PC? For compiling NuttX Arm32?</em></p>
<p>Not really, Compiling Arm on Arm isn’t much faster. I still prefer Ubuntu PC for compiling NuttX, lemme explain…</p>
<p><img src="https://lupyuen.github.io/images/ci4-thinkstation.jpg" alt="Refurbished 12-Core Xeon ThinkStation ($400 / 24 kg!) becomes (hefty) Ubuntu Build Farm for Apache NuttX RTOS. 4 times the throughput of a PC!" /></p>
<span style="font-size:80%">
<p><a href="https://qoto.org/@lupyuen/113517788288458811"><em>Refurbished 12-Core Xeon ThinkStation ($400 / 24 kg!) becomes (hefty) Ubuntu Build Farm for Apache NuttX RTOS. 4 times the throughput of a PC!</em></a></p>
</span>
<h1 id="macos-reconsidered"><a class="doc-anchor" href="#macos-reconsidered">§</a>7 macOS Reconsidered</h1>
<p><em>Is macOS good enough for NuttX Development?</em></p>
<p>If we’re Compiling NuttX for <strong>One Single Target</strong>: Arm32 / RISC-V / Xtensa… Yep sure!</p>
<p>But as NuttX Maintainer: I find it tough to reproduce <strong>All Possible NuttX Builds</strong> on macOS…</p>
<ul>
<li>
<p><a href="https://lupyuen.github.io/articles/ci5#except-these-targets"><strong>Some NuttX Targets</strong></a> won’t compile for macOS</p>
</li>
<li>
<p>We have <strong>Limited Skills</strong> (and machines) for maintaining NuttX CI on macOS</p>
</li>
<li>
<p>My Favourite Setup: <a href="https://youtu.be/gPNURDLBu70"><strong>VSCode on macOS</strong></a> controlling a <a href="https://qoto.org/@lupyuen/113517788288458811"><strong>Refurbished Xeon Workstation</strong></a> for <a href="https://lupyuen.github.io/articles/ci2#build-nuttx-for-one-target-group"><strong>Ubuntu Docker Builds</strong></a> (which will faithfully compile everything)</p>
</li>
<li>
<p>Shall we use <a href="https://discord.com/channels/716091708336504884/1280436444141453313"><strong>Docker for macOS Arm64</strong></a>?</p>
</li>
<li>
<p>By <a href="https://lupyuen.github.io/articles/pr#appendix-building-the-docker-image-for-nuttx-ci"><strong>Modding the NuttX Dockerfile</strong></a>?</p>
</li>
</ul>
<p><img src="https://lupyuen.github.io/images/ci5-remote.jpg" alt="VSCode on macOS controlling a Refurbished Xeon Workstation for Ubuntu Docker Builds" /></p>
<p><a href="https://youtu.be/gPNURDLBu70">(Watch the <strong>Video on YouTube</strong>)</a></p>
<p>Hopefully we’ll find a reliable way to compile <em>sim:nsh</em> on macOS…</p>
<div class="example-wrap"><pre class="language-bash"><code>## macOS Arm64 won't compile sim:nsh
$ git clone https://github.com/lupyuen/nuttx-build-farm
$ cd nuttx-build-farm
$ ./run-build-macos.sh sim:nsh
clang: error: invalid argument 'medium' to -mcmodel=</code></pre></div><span style="font-size:90%">
<p><a href="https://gist.github.com/lupyuen/41955b62a7620cd65e49c6202dc73e6d">(See the <strong>Complete Log</strong>)</a></p>
<p><a href="https://github.com/apache/nuttx/pull/14606#pullrequestreview-2425925903">(It was <strong>Previously Working!</strong>)</a></p>
</span>
<p><img src="https://lupyuen.github.io/images/ci4-flow.jpg" alt="Build Farm for Apache NuttX RTOS" /></p>
<h1 id="whats-next"><a class="doc-anchor" href="#whats-next">§</a>8 What’s Next</h1>
<p>Next Article: We chat about a new tool to <strong>“Rewind The Build”</strong> when something breaks the Daily Build…</p>
<ul>
<li><a href="https://lupyuen.github.io/articles/ci6"><strong>“Rewinding a Build for Apache NuttX RTOS (Docker)”</strong></a></li>
</ul>
<p>Then we study the internals of a <a href="https://github.com/apache/nuttx/issues/14808"><strong>Mystifying Bug</strong></a> that concerns <strong>PyTest, QEMU RISC-V and <code>expect</code></strong>.</p>
<ul>
<li>
<p><a href="https://lupyuen.github.io/articles/ci7"><strong>“Failing a Continuous Integration Test for Apache NuttX RTOS (QEMU RISC-V)”</strong></a></p>
</li>
<li>
<p><a href="https://lupyuen.github.io/articles/mastodon"><strong>“(Experimental) Mastodon Server for Apache NuttX Continuous Integration (macOS Rancher Desktop)”</strong></a></p>
</li>
<li>
<p><a href="https://lupyuen.org/articles/bisect.html"><strong>“Git Bisecting a Bug (Apache NuttX RTOS)”</strong></a></p>
</li>
</ul>
<p>Many Thanks to the awesome <strong>NuttX Admins</strong> and <strong>NuttX Devs</strong>! And my <a href="https://lupyuen.github.io/articles/sponsor"><strong>GitHub Sponsors</strong></a>, for sticking with me all these years.</p>
<ul>
<li>
<p><a href="https://lupyuen.github.io/articles/sponsor"><strong>Sponsor me a coffee</strong></a></p>
</li>
<li>
<p><a href="https://news.ycombinator.com/item?id=42353273"><strong>Discuss this article on Hacker News</strong></a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/nuttx-sg2000"><strong>My Current Project: “Apache NuttX RTOS for Sophgo SG2000”</strong></a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/nuttx-ox64"><strong>My Other Project: “NuttX for Ox64 BL808”</strong></a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/nuttx-star64"><strong>Older Project: “NuttX for Star64 JH7110”</strong></a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/pinephone-nuttx"><strong>Olderer Project: “NuttX for PinePhone”</strong></a></p>
</li>
<li>
<p><a href="https://lupyuen.github.io"><strong>Check out my articles</strong></a></p>
</li>
<li>
<p><a href="https://lupyuen.github.io/rss.xml"><strong>RSS Feed</strong></a></p>
</li>
</ul>
<p><em>Got a question, comment or suggestion? Create an Issue or submit a Pull Request here…</em></p>
<p><a href="https://github.com/lupyuen/lupyuen.github.io/blob/master/src/ci5.md"><strong>lupyuen.github.io/src/ci5.md</strong></a></p>
<!-- Begin scripts/rustdoc-after.html: Post-HTML for Custom Markdown files processed by rustdoc, like chip8.md -->
<!-- Begin Theme Picker and Prism Theme -->
<script src="../theme.js"></script>
<script src="../prism.js"></script>
<!-- Theme Picker and Prism Theme -->
<!-- End scripts/rustdoc-after.html -->
</body>
</html>