-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rust3.html
768 lines (558 loc) · 177 KB
/
Rust3.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
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- iOS Safari -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<!-- Chrome, Firefox OS and Opera Status Bar Color -->
<meta name="theme-color" content="#FFFFFF">
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css">
<link rel="stylesheet" type="text/css"
href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.19.0/themes/prism.min.css">
<link rel="stylesheet" type="text/css" href="css/SourceSansPro.css">
<link rel="stylesheet" type="text/css" href="css/theme.css">
<link rel="stylesheet" type="text/css" href="css/notablog.css">
<link rel="stylesheet" type="text/css" href="css/CustomSetting.css">
<!-- Favicon -->
<link rel="shortcut icon" href="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🥥</text></svg>">
<style>
:root {
font-size: 20px;
}
</style>
<title>开发 Rust std 应用 | 413’s Website</title>
<meta property="og:type" content="blog">
<meta property="og:title" content="开发 Rust std 应用">
<meta property="og:image" content="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🦀</text></svg>">
<style>
.DateTagBar {
margin-top: 1.0rem;
}
</style>
</head>
<body>
<nav class="Navbar">
<a href="index.html">
<div class="Navbar__Btn">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🥥</text></svg>"></span>
<span>Home</span>
</div>
</a>
<span class="Navbar__Delim">·</span>
<a href="blog-collection.html">
<div class="Navbar__Btn">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🥅</text></svg>"></span>
<span>blog mark</span>
</div>
</a>
<span class="Navbar__Delim">·</span>
<a href="Note.html">
<div class="Navbar__Btn">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🎶</text></svg>"></span>
<span>Note</span>
</div>
</a>
<span class="Navbar__Delim">·</span>
<a href="reference.html">
<div class="Navbar__Btn">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>😷</text></svg>"></span>
<span>杂项</span>
</div>
</a>
<span class="Navbar__Delim">·</span>
<a href="About.html">
<div class="Navbar__Btn">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>😀</text></svg>"></span>
<span>About</span>
</div>
</a>
</nav>
<header class="Header">
<div class="Header__Spacer Header__Spacer--NoCover">
</div>
<div class="Header__Icon">
<span><img class="inline-img-icon" src="data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text text-anchor=%22middle%22 dominant-baseline=%22middle%22 x=%2250%22 y=%2255%22 font-size=%2280%22>🦀</text></svg>"></span>
</div>
<h1 class="Header__Title">开发 Rust std 应用</h1>
<div class="DateTagBar">
<span class="DateTagBar__Item DateTagBar__Date">Posted on Mon, Sep 2, 2024</span>
<span class="DateTagBar__Item DateTagBar__Tag DateTagBar__Tag--purple">
<a href="tag/Rust.html">Rust</a>
</span>
<span class="DateTagBar__Item DateTagBar__Tag DateTagBar__Tag--red">
<a href="tag/单片机.html">单片机</a>
</span>
</div>
</header>
<div id="content-html"></div>
<article id="https://www.notion.so/a44047adc2454ddd9d5876bf56da3cb2" class="PageRoot PageRoot--FullWidth"><h2 id="https://www.notion.so/ccd95b333796404b85b472ab6a46c8e8" class="ColorfulBlock ColorfulBlock--ColorDefault Heading Heading--2"><a class="Anchor" href="#https://www.notion.so/ccd95b333796404b85b472ab6a46c8e8"><svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">对于 std 应用</mark></span></span></h2><div id="https://www.notion.so/78d7257e53f34de3b0abbcc6434700e3" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/0199f593023745cf94f2b0ca63260ce2" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">对于 std 应用, 核心是使用 esp-idf-sys 和它绑定链接到的 C/C++ 库 esp-idf。</mark></span></span></p></div><ul class="BulletedListWrapper"><li id="https://www.notion.so/4bc2d98cd70c4a7abc45ad063d5397c4" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">构建的 target 是 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">xtensa-esp32s3-espidf</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">, 而 non_std 应用的 target 是 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">xtensa-esp32s3-none-elf</code></mark></span></span></li></ul><div id="https://www.notion.so/28f43bfa31a14992b87f79a6b4214b8e" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp-idf 是 C/C++ 开发的,运行 FreeRTOS 操作系统,为 Rust std 提供了 newlib enviroment 实现(~/.rustup/toolchains/esp 目录),</mark></span></span></p></div><div id="https://www.notion.so/e45ccb0bf58f44ee84697be4f1fe39de" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">这样 std 应用可以使用 Rust 标准库的各种类型和特性,如 Vec/HashMap/Box,net,heap 内存分配、thread/Mutex 等;</mark></span></span></p></div><div id="https://www.notion.so/16ef07454e8544228172fe7f7cc3cb29" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/5ef9cf9f530e4b2b94bf5d46810a7fcf" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">Rust std 应用与 esp-idf 之间的 3 种互操作方式(这些 std 库惯例是 esp-idf- 开头):</mark></span></span></p></div><ol class="NumberedListWrapper"><li id="https://www.notion.so/516595c4512c4cacb38e1f6056ba0fea" class="NumberedList" value="1"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf-sys</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> crate:esp-idf 的 unsafe binding,Gives </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">raw (unsafe) access</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> to drivers, Wi-Fi and more.</mark></span></span></li><li id="https://www.notion.so/3c9a32d8a709463890acfb7c009fa55f" class="NumberedList" value="2"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf-svc</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> crate:esp-idf 的 safe binding,抽象层次更高,实现了 embedded-svc trait。</mark></span></span></li><li id="https://www.notion.so/5abb9c8ef1df43d6ac80343d5b2bc781" class="NumberedList" value="3"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf-hal</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> crate:实现了 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">embedded-hal</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> trait,支持 async,底层也是基于 esp-idf;</mark></span></span></li></ol><div id="https://www.notion.so/538e05b9c3ab4af28541f699cf5265b1" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">它们之间的层次关系: </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf-svc -> esp-idf-hal -> esp-idf-sys(esp-idf 的 Rust binding).</code></mark></span></span></p></div><div id="https://www.notion.so/5604fdf9b9524a58b61cf7db13f43aef" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/ec021a1b94d641a38ce9899c5753504e" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">embedded-hal 和 embedded-svc 是 Rust embedded workgroup 定义的厂商中立的嵌入式规范.</mark></span></span></p></div><div id="https://www.notion.so/f60d6f4c581948768906f45a948d89db" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/20b42927c42d47a4b56487a4c4e1dbea" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">编译 esp-idf-sys 时, build.rs 会会自动下载/安装/配置/编译和链接 esp-idf 库,</mark></span></span></p></div><div id="https://www.notion.so/ceea135938fc4f969455387fae26a030" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">安装到 $ESP_IDF_TOOLS_INSTALL_DIR 位置,默认为 by 项目的 .embuild/espressif 目录。</mark></span></span></p></div><div id="https://www.notion.so/ae5f7d29feae48fa8994b9a622d7375c" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/7da2510ca12f415a8420555252156a23" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp-idf-sys 默认启用 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 所有的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">Component</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">(静态库的形式) ,这样可以后续直接链接他们(后续也可以通过 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp_idf_components</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">, $ESP_IDF_COMPONENTS 来配置)。</mark></span></span></p></div><div id="https://www.notion.so/3a82cf266650403cb88749f68b64b18f" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/e8e9e9803ad74560ab8ee603ead80de4" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp-idf-sys 也支持添加本地和远程的 C/C++ Component,在构建 esp-idf-sys 时自动使用 bindgen 将它封装为Rust 接口,后续自动链接到可执行程序中。(参考后文)。</mark></span></span></p></div><div id="https://www.notion.so/ae949afd32f84545bf920bb74e54706f" class="Image Image--Normal"><figure><a href="#?width=336"><img src="#?width=336" style="width:336px"/></a><figcaption><span class="SemanticStringArray"></span></figcaption></figure></div><div id="https://www.notion.so/8988f79369ae42ea91cf6c52eb94ffc9" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/f023daaf8c6144708dd02ff910ea8d89" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">如果 esp-idf-hal 不满足需求(如缺少一些 esp32 的寄存器的操作),可以使用 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-rs/esp-pacs</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 下的</mark></span><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/esp-rs/esp-pacs/tree/main/esp32s3"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp32s3 create</mark></a></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">, 它是使用 svd2rust 工具来基于芯片的 svd 自动生成的库。</mark></span></span></p></div><div id="https://www.notion.so/f5c587b30830446e82c05ed4aea5a4b6" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/d88b3760cd9c41dba8486886955a80ed" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://apollolabsblog.hashnode.dev/the-embedded-rust-esp-development-ecosystem"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://apollolabsblog.hashnode.dev/the-embedded-rust-esp-development-ecosystem</mark></a></span></span></p></div><div id="https://www.notion.so/d3fce2d1f5f542e787ef44bbc762bf85" class="Image Image--Normal"><figure><a href="#?width=336"><img src="#?width=336" style="width:336px"/></a><figcaption><span class="SemanticStringArray"></span></figcaption></figure></div><h2 id="https://www.notion.so/cb2b2b479ff24841b42b95c834da4dd8" class="ColorfulBlock ColorfulBlock--ColorDefault Heading Heading--2"><a class="Anchor" href="#https://www.notion.so/cb2b2b479ff24841b42b95c834da4dd8"><svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">使用 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/esp-rs/esp-idf-template/blob/master/README.md">esp-rs/esp-idf-template</a></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 模板</mark></span></span></h2><div id="https://www.notion.so/9622a02da7ba4b44b4e21b837b3737e4" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/485dc9a3c40246d19057da1936a957cd" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">使用 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/esp-rs/esp-idf-template/blob/master/README.md">esp-rs/esp-idf-template</a></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 模板来创建 std 应用:</mark></span></span></p></div><ul class="BulletedListWrapper"><li id="https://www.notion.so/25557e25f987437294e392e34b9a092d" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">在编译 esp-idf-sys 时自动下载和安装 esp-idf 框架到项目的 .embuild/espressif/esp-idf 目录下;</mark></span></span></li><li id="https://www.notion.so/95e112050a494112b7a8641b10450a35" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">可以配置项目的 .cargo/config.toml 文件, 添加 env ESP_IDF_TOOLS_INSTALL_DIR = “global” 来使用全局 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">~/.espressif/</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 下的 esp-idf 工具链(建议).</mark></span></span></li><li id="https://www.notion.so/a8302da8b5b44f6aa3ec9d792677e8c8" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">sdkconfig.defaults 文件为 esp-idf 的缺省参数提供 override 参数如 stack size, log level;</mark></span></span></li></ul><div id="https://www.notion.so/8c41da884a904156856e252243de4fd2" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><pre id="https://www.notion.so/8d291386249749948500891bfda25adb" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>zj@a:~/codes/esp32/$ <span class="token function">cargo</span> generate esp-rs/esp-idf-template <span class="token function">cargo</span>
⚠️ Favorite <span class="token variable"><span class="token variable">`</span>esp-rs/esp-idf-template<span class="token variable">`</span></span> not found <span class="token keyword">in</span> config, using it as a <span class="token function">git</span> repository: https://github.com/esp-rs/esp-idf-template.git
🔧 project-name: myesp <span class="token punctuation">..</span>.
🔧 Generating template <span class="token punctuation">..</span>.
✔ 🤷 Which MCU to target? · esp32s3
✔ 🤷 Configure advanced template options? · <span class="token boolean">true</span>
✔ 🤷 Enable STD support? · <span class="token boolean">true</span>
✔ 🤷 Configure project to use Dev Containers <span class="token punctuation">(</span>VS Code and GitHub Codespaces<span class="token punctuation">)</span>? · <span class="token boolean">false</span>
✔ 🤷 Configure project to support Wokwi simulation with Wokwi VS Code extension? · <span class="token boolean">false</span>
✔ 🤷 Add CI files <span class="token keyword">for</span> GitHub Action? · <span class="token boolean">false</span>
✔ 🤷 ESP-IDF version <span class="token punctuation">(</span>master <span class="token operator">=</span> UNSTABLE<span class="token punctuation">)</span> · v5.1
🔧 Moving generated files into: <span class="token variable"><span class="token variable">`</span>/Users/zhangjun/codes/esp32/esp-demo2/myesp<span class="token variable">`</span></span><span class="token punctuation">..</span>.
🔧 Initializing a fresh Git repository
✨ Done<span class="token operator">!</span> New project created /Users/zhangjun/codes/esp32/esp-demo2/myesp
zj@a:~/codes/esp32/$ <span class="token builtin class-name">cd</span> myesp
zj@a:~/code/esp32/std/myespv4$ <span class="token function">cat</span> src/main.rs
fn <span class="token function-name function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
// It is necessary to call this <span class="token keyword">function</span> once. Otherwise some patches to the runtime
// implemented by esp-idf-sys might not <span class="token function">link</span> properly. See https://github.com/esp-rs/esp-idf-template/issues/71
esp_idf_svc::sys::link_patches<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
// Bind the log crate to the ESP Logging facilities
esp_idf_svc::log::EspLogger::initialize_default<span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
log::info<span class="token operator">!</span><span class="token punctuation">(</span><span class="token string">"Hello, world!"</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span></span></span></span></code></pre><h3 id="https://www.notion.so/32020fd8821a4a4d9e0852a204bbec46" class="ColorfulBlock ColorfulBlock--ColorDefault Heading Heading--3"><a class="Anchor" href="#https://www.notion.so/32020fd8821a4a4d9e0852a204bbec46"><svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">按需修改 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">Cargo.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">:</mark></span></span></h3><div id="https://www.notion.so/1f3f8b7f0d3b40aeb1115b1a95304037" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><pre id="https://www.notion.so/bf420770642248ac910e0abecc86ad9f" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>zj@a:~/code/esp32/std/myesp$ cat Cargo<span class="token punctuation">.</span>toml
<span class="token punctuation">[</span><span class="token table class-name">package</span><span class="token punctuation">]</span>
<span class="token key property">name</span> <span class="token punctuation">=</span> <span class="token string">"myesp"</span>
<span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.1.0"</span>
<span class="token key property">authors</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"alizj"</span><span class="token punctuation">]</span>
<span class="token key property">edition</span> <span class="token punctuation">=</span> <span class="token string">"2021"</span>
<span class="token key property">resolver</span> <span class="token punctuation">=</span> <span class="token string">"2"</span>
<span class="token key property">rust-version</span> <span class="token punctuation">=</span> <span class="token string">"1.71"</span>
<span class="token punctuation">[</span><span class="token table class-name">profile.release</span><span class="token punctuation">]</span>
<span class="token key property">opt-level</span> <span class="token punctuation">=</span> <span class="token string">"s"</span>
<span class="token punctuation">[</span><span class="token table class-name">profile.dev</span><span class="token punctuation">]</span>
<span class="token key property">debug</span> <span class="token punctuation">=</span> <span class="token boolean">true</span> <span class="token comment"># Symbols are nice and they don't increase the size on Flash</span>
<span class="token key property">opt-level</span> <span class="token punctuation">=</span> <span class="token string">"z"</span>
<span class="token punctuation">[</span><span class="token table class-name">features</span><span class="token punctuation">]</span>
<span class="token comment"># 缺省 features:重点是包含 std 和 esp-idf-svc/native</span>
<span class="token comment"># esp-idf-svc/native 指的是 native 平台类型,除此之外还有 pio 平台类型。</span>
<span class="token key property">default</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"std"</span><span class="token punctuation">,</span> <span class="token string">"embassy"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/native"</span><span class="token punctuation">]</span>
<span class="token comment"># std 包含 alloc 和 esp-idf-svc/std</span>
<span class="token key property">std</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"alloc"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/binstart"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/std"</span><span class="token punctuation">]</span>
<span class="token comment"># alloc 依赖 esp-idf-svc/alloc</span>
<span class="token key property">alloc</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/alloc"</span><span class="token punctuation">]</span>
<span class="token comment"># embassy 也仅依赖 esp-idf-svc</span>
<span class="token key property">embassy</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/embassy-sync"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/critical-section"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/embassy-time-driver"</span><span class="token punctuation">]</span>
<span class="token comment"># 总结:cargo gen 通过模板创建的 std 应用仅依赖 std 和 esp-idf-svc</span>
<span class="token key property">pio</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/pio"</span><span class="token punctuation">]</span>
<span class="token key property">nightly</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/nightly"</span><span class="token punctuation">]</span>
<span class="token key property">experimental</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/experimental"</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token table class-name">dependencies</span><span class="token punctuation">]</span>
<span class="token comment"># 通过 log 打印日志,esp-idf-svc 提供了 log 的具体实现</span>
<span class="token key property">log</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.4"</span><span class="token punctuation">,</span> <span class="token key property">default-features</span> <span class="token punctuation">=</span> <span class="token boolean">false</span> <span class="token punctuation">}</span>
<span class="token comment"># std 类型的 crate</span>
<span class="token key property">esp-idf-svc</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.48"</span><span class="token punctuation">,</span> <span class="token key property">default-features</span> <span class="token punctuation">=</span> <span class="token boolean">false</span> <span class="token punctuation">}</span>
<span class="token punctuation">[</span><span class="token table class-name">build-dependencies</span><span class="token punctuation">]</span> <span class="token comment"># build.rs 编译脚本的依赖</span>
<span class="token key property">embuild</span> <span class="token punctuation">=</span> <span class="token string">"0.31.3"</span> <span class="token comment"># build.rs 依赖 embuild</span></span></span></span></code></pre><h3 id="https://www.notion.so/db9b662178504b609e66c7a0737ab6f4" class="ColorfulBlock ColorfulBlock--ColorDefault Heading Heading--3"><a class="Anchor" href="#https://www.notion.so/db9b662178504b609e66c7a0737ab6f4"><svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">修改 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">.cargo/config.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></h3><div id="https://www.notion.so/715362909b1f4c32ac2c06f4f0292b09" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/5447a8a58a1543b487735e2f5cf01424" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">修改 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">.cargo/config.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">文件中的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">ESP_IDF_VERSION</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 为最新版本,内容如下:</mark></span></span></p></div><div id="https://www.notion.so/59f18b8026744178ae9f671930ebadb0" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><pre id="https://www.notion.so/843707f332d240fa8775956c8a6792d0" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>zj@a:~/codes/esp32/myesp$ cat <span class="token punctuation">.</span>cargo/config<span class="token punctuation">.</span>toml
<span class="token punctuation">[</span><span class="token table class-name">build</span><span class="token punctuation">]</span>
<span class="token key property">target</span> <span class="token punctuation">=</span> <span class="token string">"xtensa-esp32s3-espidf"</span> <span class="token comment"># 要构建的 target,这里使用链接 esp-idf 的 target</span>
<span class="token punctuation">[</span><span class="token table class-name">target.xtensa-esp32s3-espidf</span><span class="token punctuation">]</span> <span class="token comment"># target 对应的配置</span>
<span class="token key property">linker</span> <span class="token punctuation">=</span> <span class="token string">"ldproxy"</span> <span class="token comment"># 位于 ~/.cargo/bin/</span>
<span class="token comment"># runner = "espflash --monitor" # Select this runner for espflash v1.x.x</span>
<span class="token key property">runner</span> <span class="token punctuation">=</span> <span class="token string">"espflash flash --monitor"</span> <span class="token comment"># Select this runner for espflash v2.x.x</span>
<span class="token key property">rustflags</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span> <span class="token string">"--cfg"</span><span class="token punctuation">,</span> <span class="token string">"espidf_time64"</span><span class="token punctuation">]</span> <span class="token comment"># Extending time_t for ESP IDF 5: https://github.com/esp-rs/rust/issues/110</span>
<span class="token punctuation">[</span><span class="token table class-name">unstable</span><span class="token punctuation">]</span>
<span class="token key property">build-std</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"std"</span><span class="token punctuation">,</span> <span class="token string">"panic_abort"</span><span class="token punctuation">]</span> <span class="token comment"># 构建和使用 std(对于 no_std 是 core)</span>
<span class="token punctuation">[</span><span class="token table class-name">env</span><span class="token punctuation">]</span> <span class="token comment"># 被 embuild 使用的环境变量</span>
<span class="token key property">MCU</span><span class="token punctuation">=</span><span class="token string">"esp32s3"</span>
<span class="token comment"># Note: this variable is not used by the pio builder (`cargo build --features pio`)</span>
<span class="token key property">ESP_IDF_VERSION</span> <span class="token punctuation">=</span> <span class="token string">"v5.2.1"</span>
<span class="token comment"># 使用全局 ~/.espressif/ 工具链,默认是 by 项目 workspace 的。</span>
<span class="token key property">ESP_IDF_TOOLS_INSTALL_DIR</span> <span class="token punctuation">=</span> <span class="token string">"global"</span></span></span></span></code></pre><div id="https://www.notion.so/0979d72666774ccc8af475b1b2ce2f22" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><h3 id="https://www.notion.so/9662be3579fc44bd84b1dcceace26e5a" class="ColorfulBlock ColorfulBlock--ColorDefault Heading Heading--3"><a class="Anchor" href="#https://www.notion.so/9662be3579fc44bd84b1dcceace26e5a"><svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">按需修改 esp-idf 的配置参数文件</mark></span></span></h3><div id="https://www.notion.so/c49c836a66b6414bbd315f878f826381" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><div id="https://www.notion.so/fc61da8ff2ca47eaacc8370f416d9cf5" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">按需修改 esp-idf 的配置参数文件:</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">sdkconfig.defaults</code></mark></span></span></p></div><pre id="https://www.notion.so/7672e29c7e5141178172f532fcd69c26" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>zj@a:~/docs$ <span class="token function">cat</span> ~/code/esp32/std/myespv2/sdkconfig.defaults
<span class="token comment"># Rust often needs a bit of an extra main task stack size compared to C (the default is 3K)</span>
<span class="token assign-left variable">CONFIG_ESP_MAIN_TASK_STACK_SIZE</span><span class="token operator">=</span><span class="token number">8000</span>
<span class="token comment"># Use this to set FreeRTOS kernel tick frequency to 1000 Hz (100 Hz by default).</span>
<span class="token comment"># This allows to use 1 ms granuality for thread sleeps (10 ms by default).</span>
<span class="token comment">#CONFIG_FREERTOS_HZ=1000</span>
<span class="token comment"># Workaround for https://github.com/espressif/esp-idf/issues/7631</span>
<span class="token comment">#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE=n</span>
<span class="token comment">#CONFIG_MBEDTLS_CERTIFICATE_BUNDLE_DEFAULT_FULL=n</span></span></span></span></code></pre><h3 id="https://www.notion.so/a58d875ced0c441fb32f5a70fbef40ce" class="ColorfulBlock ColorfulBlock--ColorDefault Heading Heading--3"><a class="Anchor" href="#https://www.notion.so/a58d875ced0c441fb32f5a70fbef40ce"><svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">按需修改 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">rust-toolchain.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></h3><div id="https://www.notion.so/0bfea64a42924ba191c9a4ab5ba52b39" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><pre id="https://www.notion.so/f50a038c89a94b17b4e9488bfa90e31e" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span><span class="token comment"># esp32 rust 项目通过 rust-toolchain.toml 来选择 channel 和 target</span>
zj@a:~/code/esp32/myespv2$ cat rust-toolchain<span class="token punctuation">.</span>toml
<span class="token punctuation">[</span><span class="token table class-name">toolchain</span><span class="token punctuation">]</span>
<span class="token key property">channel</span> <span class="token punctuation">=</span> <span class="token string">"esp"</span> <span class="token comment"># ~/.rustup/toolchains/ 下的目录名称,这里使用 esp toolchain</span>
<span class="token comment"># 使用 embuild crate 来安装和构建 esp-idf framework</span>
<span class="token comment"># 对于 non_std 应用,不依赖 esp-idf, 故不需要 build.rs .</span>
zj@a:~/code/esp32/myespv2$ cat build<span class="token punctuation">.</span>rs
fn main() <span class="token punctuation">{</span>
embuild::espidf::sysenv::output();
<span class="token punctuation">}</span></span></span></span></code></pre><h2 id="https://www.notion.so/46a6fccd60a748048f18ea57639baacd" class="ColorfulBlock ColorfulBlock--ColorDefault Heading Heading--2"><a class="Anchor" href="#https://www.notion.so/46a6fccd60a748048f18ea57639baacd"><svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">构建项目:</mark></span></span></h2><ol class="NumberedListWrapper"><li id="https://www.notion.so/b855afd07b7c42a48c34d32318737c3a" class="NumberedList" value="1"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">每次构建前都需要先 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorRed"><code class="SemanticString__Fragment SemanticString__Fragment--Code"><strong class="SemanticString__Fragment SemanticString__Fragment--Bold">source ~/esp/export-esp.sh</strong></code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><strong class="SemanticString__Fragment SemanticString__Fragment--Bold"> </strong></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">脚本。</mark></span></span></li><li id="https://www.notion.so/d9d0604e04df4e0bbc275175f285face" class="NumberedList" value="2"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">不能启用 python env,不能使用 socks 代理,需要设置环境变量;</mark></span></span></li><li id="https://www.notion.so/ba28990c2d5c43799deba11ee2f8c5ea" class="NumberedList" value="3"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">构建过程中默认下载和安装 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">到 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">workspace </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">.embuild/espressif/ </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">目录;</mark></span></span></li></ol><div id="https://www.notion.so/d917cef53a244224bf2bd77f83e2e3f1" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></p></div><pre id="https://www.notion.so/03ec2bbb6b294620b87811ec548d21df" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span><span class="token comment"># 构建 std 应用时,不能 source source ~/esp/esp-idf/v5.2.1/export.sh 文件,否则会构建失败。</span>
zj@a:~/code/esp32/myesp$ <span class="token builtin class-name">source</span> ~/esp/export-esp.sh
zj@a:~/code/esp32/myesp$ <span class="token function">cargo</span> build
<span class="token comment"># by workspace 安装的 esp-idf 到 .embuild/espressif/ 目录</span>
zj@a:~/code/esp32/myespv2$ <span class="token function">ls</span> <span class="token parameter variable">-l</span> .embuild/espressif/
total <span class="token number">4</span>.0K
drwxr-xr-x <span class="token number">6</span> alizj <span class="token number">192</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:54 dist/
drwxr-xr-x <span class="token number">3</span> alizj <span class="token number">96</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 esp-idf/
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">2</span>.8K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:51 espidf.constraints.v5.2.txt
drwxr-xr-x <span class="token number">3</span> alizj <span class="token number">96</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:51 python_env/
drwxr-xr-x <span class="token number">6</span> alizj <span class="token number">192</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:54 tools/
<span class="token comment"># dist 下载的内容被解压到 .embuild/espressif/tools/ 目录</span>
zj@a:~/code/esp32/myespv2$ <span class="token function">ls</span> <span class="token parameter variable">-l</span> .embuild/espressif/dist/
total 193M
-rw-r--r-- <span class="token number">1</span> alizj 70M <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:52 cmake-3.24.0-macos-universal.tar.gz
-rw-r--r-- <span class="token number">1</span> alizj 15M <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:54 esp32ulp-elf-2.35_20220830-macos-arm64.tar.gz
-rw-r--r-- <span class="token number">1</span> alizj 271K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:52 ninja-mac-v1.11.1.zip
-rw-r--r-- <span class="token number">1</span> alizj 96M <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:51 xtensa-esp-elf-13.2.0_20230928-aarch64-apple-darwin.tar.xz <span class="token comment"># 交叉编译工具链</span>
zj@a:~/code/esp32/myespv2$ <span class="token function">ls</span> <span class="token parameter variable">-l</span> .embuild/espressif/tools/
total <span class="token number">0</span>
drwxr-xr-x <span class="token number">3</span> alizj <span class="token number">96</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:52 cmake/
drwxr-xr-x <span class="token number">3</span> alizj <span class="token number">96</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:54 esp32ulp-elf/ <span class="token comment"># ULP (Ultra-Low-Powered)</span>
drwxr-xr-x <span class="token number">3</span> alizj <span class="token number">96</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:52 ninja/
drwxr-xr-x <span class="token number">3</span> alizj <span class="token number">96</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:51 xtensa-esp-elf/
<span class="token comment"># esp-idf framework,被安装到 python_env/ 目录</span>
zj@a:~/code/esp32/myespv2$ <span class="token function">ls</span> <span class="token parameter variable">-l</span> .embuild/espressif/esp-idf/v5.2.1/
total 172K
-rw-r--r-- <span class="token number">1</span> alizj 12K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 CMakeLists.txt
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">4</span>.2K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 COMPATIBILITY.md
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">4</span>.3K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 COMPATIBILITY_CN.md
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">314</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 CONTRIBUTING.md
-rw-r--r-- <span class="token number">1</span> alizj 25K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 Kconfig
-rw-r--r-- <span class="token number">1</span> alizj 12K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 LICENSE
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">8</span>.9K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 README.md
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">8</span>.8K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 README_CN.md
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">532</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 SECURITY.md
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">3</span>.7K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 SUPPORT_POLICY.md
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">3</span>.4K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 SUPPORT_POLICY_CN.md
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">721</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 add_path.sh
drwxr-xr-x <span class="token number">81</span> alizj <span class="token number">2</span>.6K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 components/
-rw-r--r-- <span class="token number">1</span> alizj 12K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 conftest.py
drwxr-xr-x <span class="token number">15</span> alizj <span class="token number">480</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 docs/
drwxr-xr-x <span class="token number">22</span> alizj <span class="token number">704</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 examples/
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">3</span>.9K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 export.bat
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">3</span>.7K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 export.fish
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">3</span>.5K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 export.ps1
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">8</span>.0K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 export.sh
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">1</span>.8K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 install.bat
-rwxr-xr-x <span class="token number">1</span> alizj <span class="token number">971</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 install.fish*
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">982</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 install.ps1
-rwxr-xr-x <span class="token number">1</span> alizj <span class="token number">1004</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 install.sh*
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">889</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 pytest.ini
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">2</span>.0K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 sdkconfig.rename
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">530</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:49 sonar-project.properties
drwxr-xr-x <span class="token number">47</span> alizj <span class="token number">1</span>.5K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:51 tools/
zj@a:~/code/esp32/myesp$ <span class="token function">ls</span> target/
CACHEDIR.TAG debug/ xtensa-esp32s3-espidf/</span></span></span></code></pre><div id="https://www.notion.so/95485c6430784605a7751ebad8b7ec4f" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">构建结果位于 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">target/xtensa-esp32s3-espidf </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">目录下:</mark></span></span></p></div><div id="https://www.notion.so/5cb519cbd08e47ebb41447595211fb57" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><pre id="https://www.notion.so/f937c1efbfd6460cba36d312876272e0" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>zj@a:~/code/esp32/myesp$ <span class="token function">ls</span> <span class="token parameter variable">-l</span> target/xtensa-esp32s3-espidf/debug/
total 11M
-rw-r--r-- <span class="token number">1</span> alizj 21K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:45 bootloader.bin <span class="token comment"># bootloader</span>
drwxr-xr-x <span class="token number">18</span> alizj <span class="token number">576</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:39 build/
drwxr-xr-x <span class="token number">178</span> alizj <span class="token number">5</span>.6K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:45 deps/
drwxr-xr-x <span class="token number">2</span> alizj <span class="token number">64</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:39 examples/
drwxr-xr-x <span class="token number">3</span> alizj <span class="token number">96</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:45 incremental/
-rwxr-xr-x <span class="token number">1</span> alizj 11M <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:45 myesp* <span class="token comment"># 二进制程序</span>
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">153</span> <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:45 myesp.d
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">3</span>.0K <span class="token number">5</span> <span class="token number">5</span> <span class="token number">14</span>:45 partition-table.bin <span class="token comment"># 分区表</span>
zj@a:~/code/esp32/myesp$ <span class="token function">file</span> target/xtensa-esp32s3-espidf/debug/myesp
target/xtensa-esp32s3-espidf/debug/myesp: ELF <span class="token number">32</span>-bit LSB executable, Tensilica Xtensa, version <span class="token number">1</span> <span class="token punctuation">(</span>SYSV<span class="token punctuation">)</span>, statically linked, with debug_info, not stripped</span></span></span></code></pre><div id="https://www.notion.so/6d224196858443c6a64ffdd7ac54dd89" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorRed">构建失败的解决办法:</mark></span></span></p></div><ol class="NumberedListWrapper"><li id="https://www.notion.so/26277d2436194c0386182abd417f8fe1" class="NumberedList" value="1"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">cargo clen 清理 target 目录;</mark></span></span></li><li id="https://www.notion.so/47b1d4fcc0a3404b89d565434c131a6f" class="NumberedList" value="2"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">手动清理 .embuild 目录;</mark></span></span></li><li id="https://www.notion.so/90e88007526940808e50fffd264c68e9" class="NumberedList" value="3"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">不能启用 socks 代理;</mark></span></span></li><li id="https://www.notion.so/1f6c9cb0c60b4c8397f20e78f8fac23e" class="NumberedList" value="4"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">不能开启 python venv;</mark></span></span></li></ol><div id="https://www.notion.so/cbdb3bbcfbb845fea025d356f85fb6c8" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></p></div><pre id="https://www.notion.so/19d66149f8c440889b9379163774e292" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>zj@a:~/code/esp32/myesp$ <span class="token function">cargo</span> clean
zj@a:~/code/esp32/myesp$ <span class="token function">rm</span> <span class="token parameter variable">-rf</span> .embuild/
zj@a:~/code/esp32/myesp$ <span class="token function">ls</span>
Cargo.lock Cargo.toml build.rs rust-toolchain.toml sdkconfig.defaults src/
zj@a:~/code/esp32/myesp$ <span class="token function">cargo</span> build
<span class="token comment"># cargo build 会安装 esp-idf,期间会安装 python venv 和按照 python 包。所以,不能使用 python 不支</span>
<span class="token comment"># 持的 socks 代理,也不能启用 python env。</span>
zj@a:~/code/esp32/$ enable_http_proxy
zj@a:~/code/esp32/$ <span class="token builtin class-name">export</span> <span class="token assign-left variable">DIR_TO_REMOVE</span><span class="token operator">=</span>/Users/alizj/.venv/bin
zj@a:~/code/esp32/$ <span class="token builtin class-name">export</span> <span class="token assign-left variable"><span class="token environment constant">PATH</span></span><span class="token operator">=</span><span class="token variable"><span class="token variable">$(</span><span class="token builtin class-name">echo</span> <span class="token environment constant">$PATH</span> <span class="token operator">|</span> <span class="token function">sed</span> <span class="token parameter variable">-e</span> <span class="token string">"s;:<span class="token variable">$DIR_TO_REMOVE</span>;;"</span> <span class="token parameter variable">-e</span> <span class="token string">"s;<span class="token variable">$DIR_TO_REMOVE</span>:;;"</span> <span class="token parameter variable">-e</span> <span class="token string">"s;<span class="token variable">$DIR_TO_REMOVE</span>;;"</span><span class="token variable">)</span></span>
<span class="token comment"># 如果是 Mac M1 笔记本,需要给 cargo build 添加环境变量 CRATE_CC_NO_DEFAULTS=1,否则会构建失败,报错:</span>
<span class="token comment"># xtensa-esp-elf-gcc: error: unrecognized command-line option '--target=xtensa-esp32s3-espidf'</span>
<span class="token comment"># 参考:https://github.com/rust-lang/cc-rs/issues/1005</span>
zj@a:~/code/esp32/$ <span class="token builtin class-name">export</span> <span class="token assign-left variable">CRATE_CC_NO_DEFAULTS</span><span class="token operator">=</span><span class="token number">1</span></span></span></span></code></pre><div id="https://www.notion.so/c0ece58ad1ea48b49766c66d8fb1dcde" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">参考:</mark></span></span></p></div><ol class="NumberedListWrapper"><li id="https://www.notion.so/8f9a6a5af25949f6a486b90bd9a6e8ba" class="NumberedList" value="1"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://docs.esp-rs.org/std-training/01_intro.html"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://docs.esp-rs.org/std-training/01_intro.html</mark></a></span></span></li><li id="https://www.notion.so/f112f5c8e0f94b219f623f78fee1798f" class="NumberedList" value="2"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/esp-rs/std-training"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://github.com/esp-rs/std-training</mark></a></span></span></li><li id="https://www.notion.so/89ae750444de4f5e8c0909ba8ec238cb" class="NumberedList" value="3"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/danclive/esp-examples/tree/main"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://github.com/danclive/esp-examples/tree/main</mark></a></span></span></li></ol><div id="https://www.notion.so/eafb9214c85345b28582674a872e1fcd" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><h2 id="https://www.notion.so/8885e11752484ec4a677b2f5adbb9a0a" class="ColorfulBlock ColorfulBlock--ColorDefault Heading Heading--2"><a class="Anchor" href="#https://www.notion.so/8885e11752484ec4a677b2f5adbb9a0a"><svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">1 为 Rust std 应用添加组件 component </mark></span><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://blog.opsnull.com/rust-embedded/esp-rs-std-app/#%E4%B8%BA-rust-std-%E5%BA%94%E7%94%A8%E6%B7%BB%E5%8A%A0%E7%BB%84%E4%BB%B6-component"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">#</mark></a></span></span></h2><div id="https://www.notion.so/c72abda1f7244294bd35218286228e83" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">使用 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">cargo build</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 构建基于 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">eps-idf-sys</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">std</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 应用时, </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">build.rs</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 构建脚本执行的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">embuild crate</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 会下载 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 库,使用 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">bindgen</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 来生成</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"> Rust</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 接口,将编译后的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">component</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 静态库链接到 Rust 可执行程序。</mark></span></span></p></div><ul class="BulletedListWrapper"><li id="https://www.notion.so/95369a641e2a46098cf3bcbe3ad7b0d2" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">Rust 习惯使用</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"> xx-sys</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 来命名其他语言</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"> xx </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">项目的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">Rust wrapper</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">,所以 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf-sys</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 是 C 项目</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"> esp-idf</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">Rust wrapper</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">。</mark></span></span><div id="https://www.notion.so/6ef2b96d06654c88b77d6c6cd462a1cf" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 内置了大量 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">component</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">,同时社区和 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">component registry </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">上还有大量其他 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">component </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">可供使用。</mark></span></span></p></div></li></ul><div id="https://www.notion.so/b9028040a13c40a585c80dd57ef22943" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">内置</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"> component</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">bindgen</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 由 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf-sys</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/esp-rs/esp-idf-sys/blob/master/src/include/esp-idf/bindings.h">bindings.h</a></code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"> </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">头文件定义。</mark></span></span></p><div class="Text__Children"><div id="https://www.notion.so/0c3ebb7e1f2d4e27a42a56b8cf8db192" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf-sys</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 默认启用了 所有内置</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"> component</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> ,并链接到 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">Rust</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 可执行程序。可以通过配置 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp_idf_components</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">, </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">$ESP_IDF_COMPONENTS </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">来指定要</mark></span></span></p></div></div></div><div id="https://www.notion.so/b7245fd14f0f41dfa3258c8aeb9fc520" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">接的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-id</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">f 内置 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">component </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">列表。</mark></span></span></p></div><div id="https://www.notion.so/cf68371046c549139029776677ec0548" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></p></div><pre id="https://www.notion.so/bf15e4c5187846208a1a87e221ae61c2" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span><span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>esp-idf/esp_common/libesp_common.a
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>esp-idf/esp_timer/libesp_timer.a
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>esp-idf/app_trace/libapp_trace.a
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>esp-idf/esp_event/libesp_event.a
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>esp-idf/nvs_flash/libnvs_flash.a
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>esp-idf/esp_phy/libesp_phy.a
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>esp-idf/vfs/libvfs.a
// <span class="token punctuation">..</span>.
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>/Users/alizj/code/esp32/std/.embuild/espressif/esp-idf/v5.2.1/components/esp_wifi/lib/esp32s3/libcore.a
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>/Users/alizj/code/esp32/std/.embuild/espressif/esp-idf/v5.2.1/components/esp_wifi/lib/esp32s3/libespnow.a
// <span class="token punctuation">..</span>.
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>esp-idf/esp_coex/libesp_coex.a
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>esp-idf/esp_wifi/libesp_wifi.a
// <span class="token punctuation">..</span>.
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>esp-idf/mbedtls/mbedtls/3rdparty/p256-m/libp256m.a
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>/Users/alizj/code/esp32/std/.embuild/espressif/esp-idf/v5.2.1/components/esp_wifi/lib/esp32s3/libcore.a
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span>
// <span class="token punctuation">..</span>.
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>-Wl,--wrap<span class="token operator">=</span>_Unwind_Backtrace
<span class="token punctuation">[</span>esp32-camera-binding <span class="token number">0.1</span>.0<span class="token punctuation">]</span> cargo:rustc-link-arg<span class="token operator">=</span>-Wl,--wrap<span class="token operator">=</span>__cxa_call_unexpected</span></span></span></code></pre><div id="https://www.notion.so/f42bebabbc6b45449907e53e03e3cfc5" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">为 esp-idf-sys 添加 外部额外的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">component</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> ,让 esp-idf-sys bindgen 它的头文件,并进行编译和链接。</mark></span></span></p></div><ul class="BulletedListWrapper"><li id="https://www.notion.so/31695b2d09c44d8b8905106a144e5143" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">bindgen 为 C 生成的 Rust 接口会放到 esp-idf-sys module 中供 Rust 程序使用。</mark></span></span></li></ul><div id="https://www.notion.so/face97a1d16d409785ec3486e2223418" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp-idf-sys crate 提供了一些影响 esp-idf bindgen、编译构建的配置参数和 .cargo/config.tom 环境变量:</mark></span></span></p></div><ul class="BulletedListWrapper"><li id="https://www.notion.so/9d9ecd030b034679bcf3c7d47181484b" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/esp-rs/esp-idf-sys/blob/master/BUILD-OPTIONS.md"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://github.com/esp-rs/esp-idf-sys/blob/master/BUILD-OPTIONS.md</mark></a></span></span></li><li id="https://www.notion.so/61d5846a39af43b2809bba63a633875b" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://docs.esp-rs.org/esp-idf-svc/esp_idf_sys/index.html"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://docs.esp-rs.org/esp-idf-svc/esp_idf_sys/index.html</mark></a></span></span></li></ul><div id="https://www.notion.so/165f853d33ac48ac9fff20b042bea8a7" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">添加 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">extral component</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 示例:</mark></span></span></p></div><div id="https://www.notion.so/bf2fc90864ff4a48aaee311c471e9248" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></p></div><pre id="https://www.notion.so/8a3cb4dcc52c42db9e134a9bcba68f87" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span><span class="token comment"># 在 workspace 的 members 列表里添加待创建的 crate package 目录名称</span>
zj@a:~/code/esp32/std$ cat Cargo<span class="token punctuation">.</span>toml
<span class="token punctuation">[</span><span class="token table class-name">workspace</span><span class="token punctuation">]</span>
<span class="token key property">resolver</span> <span class="token punctuation">=</span> <span class="token string">"2"</span>
<span class="token key property">members</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span>
<span class="token string">"myesp"</span><span class="token punctuation">,</span>
<span class="token string">"myespv2"</span><span class="token punctuation">,</span>
<span class="token string">"myespv3"</span><span class="token punctuation">,</span>
<span class="token string">"myespv4"</span><span class="token punctuation">,</span>
<span class="token string">"esp32-camera-binding"</span> <span class="token comment"># 待创建的 create package 目录名称</span>
<span class="token punctuation">]</span>
<span class="token comment">#...</span>
<span class="token comment"># 由于 workspace 的 Cargo.toml 中没有配置 [package], 即该 workspace 没有默认的 root crate, 它是一</span>
<span class="token comment"># 个virtual workspace.</span>
<span class="token comment">#</span>
<span class="token comment"># 对于 virtual workspace, 必须在 workspace 的 .cargo/config.toml 文件中, 通过环境变量</span>
<span class="token comment"># ESP_IDF_SYS_ROOT_CRATE="esp32-camera-binding" 来指定 root crate, 如 esp32-camera-binding.</span>
zj@a:~/code/esp32/std$ cat <span class="token punctuation">.</span>cargo/config<span class="token punctuation">.</span>toml
<span class="token punctuation">[</span><span class="token table class-name">env</span><span class="token punctuation">]</span>
<span class="token key property">ESP_IDF_SYS_ROOT_CRATE</span><span class="token punctuation">=</span><span class="token string">"esp32-camera-binding"</span> <span class="token comment"># 关键! 否则编译 esp32-camera-binding 时不会进行 bindgen 转换.</span>
<span class="token comment"># 创建上面定义的 esp32-camera-binding std 项目</span>
zj@a:~/code/esp32/std$ cargo generate esp-rs/esp-idf-template cargo
zj@a:~/code/esp32/std$ cd esp32-camera-binding/
<span class="token comment"># clone 要 bindgen 的 esp-idf component 项目到本地</span>
zj@a:~/code/esp32/std/esp32-camera-binding$ git clone git@github<span class="token punctuation">.</span>com:espressif/esp32-camera<span class="token punctuation">.</span>git
zj@a:~/code/esp32/std/esp32-camera-binding$ ls
Cargo<span class="token punctuation">.</span>toml bindings<span class="token punctuation">.</span>h build<span class="token punctuation">.</span>rs esp32-camera/ src/
<span class="token comment"># 创建一个 bindings.h 文件,内容为 bindgen 要转换的 component 头文件列表,</span>
<span class="token comment"># 可以查看项目目录中头文件名称。</span>
zj@a:~/code/esp32/std/esp32-camera-binding$ cat bindings<span class="token punctuation">.</span>h
<span class="token comment">#include "esp_camera.h"</span>
<span class="token comment"># 配置刚创建的 package 的 Cargo.toml 文件,添加 [[package.metadata.esp-idf-sys.extra_components]]</span>
<span class="token comment"># 这样在编译 esp-idf-sys 时,会自动使用 bindgen 将 bindings.h 中的头文件生成到 esp-idf-sys 的 module 中,</span>
<span class="token comment"># 同时也会编译该 component 为静态库,后续可以链接到 Rust 可执行程序中。</span>
zj@a:~/code/esp32/std/esp32-camera-binding$ cat Cargo<span class="token punctuation">.</span>toml
<span class="token punctuation">[</span><span class="token table class-name">package</span><span class="token punctuation">]</span>
<span class="token key property">name</span> <span class="token punctuation">=</span> <span class="token string">"esp32-camera-binding"</span>
<span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.1.0"</span>
<span class="token key property">authors</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"alizj"</span><span class="token punctuation">]</span>
<span class="token key property">edition</span> <span class="token punctuation">=</span> <span class="token string">"2021"</span>
<span class="token key property">resolver</span> <span class="token punctuation">=</span> <span class="token string">"2"</span>
<span class="token key property">rust-version</span> <span class="token punctuation">=</span> <span class="token string">"1.71"</span>
<span class="token punctuation">[</span><span class="token table class-name">profile.release</span><span class="token punctuation">]</span>
<span class="token key property">opt-level</span> <span class="token punctuation">=</span> <span class="token string">"s"</span>
<span class="token punctuation">[</span><span class="token table class-name">profile.dev</span><span class="token punctuation">]</span>
<span class="token key property">debug</span> <span class="token punctuation">=</span> <span class="token boolean">true</span>
<span class="token key property">opt-level</span> <span class="token punctuation">=</span> <span class="token string">"z"</span>
<span class="token punctuation">[</span><span class="token table class-name">features</span><span class="token punctuation">]</span>
<span class="token key property">default</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"std"</span><span class="token punctuation">,</span> <span class="token string">"embassy"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/native"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-sys/native"</span><span class="token punctuation">]</span>
<span class="token key property">pio</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/pio"</span><span class="token punctuation">]</span>
<span class="token key property">std</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"alloc"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/binstart"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/std"</span><span class="token punctuation">]</span>
<span class="token key property">alloc</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/alloc"</span><span class="token punctuation">]</span>
<span class="token key property">nightly</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/nightly"</span><span class="token punctuation">]</span>
<span class="token key property">experimental</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/experimental"</span><span class="token punctuation">]</span>
<span class="token key property">embassy</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/embassy-sync"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/critical-section"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/embassy-time-driver"</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token table class-name">dependencies</span><span class="token punctuation">]</span>
<span class="token key property">log</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.4"</span><span class="token punctuation">,</span> <span class="token key property">default-features</span> <span class="token punctuation">=</span> <span class="token boolean">false</span> <span class="token punctuation">}</span>
<span class="token key property">esp-idf-svc</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.48"</span><span class="token punctuation">,</span> <span class="token key property">default-features</span> <span class="token punctuation">=</span> <span class="token boolean">false</span> <span class="token punctuation">}</span>
<span class="token key property">esp-idf-sys</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.34.1"</span><span class="token punctuation">}</span> <span class="token comment"># 添加 esp-idf-sys 依赖</span>
<span class="token key property">esp-idf-hal</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.43.1"</span><span class="token punctuation">}</span>
<span class="token punctuation">[</span><span class="token table class-name">build-dependencies</span><span class="token punctuation">]</span>
<span class="token key property">embuild</span> <span class="token punctuation">=</span> <span class="token string">"0.31.3"</span>
<span class="token comment"># esp-idf-sys 的构建脚本 embuild 在编译 esp-idf C 时使用的配置参数.</span>
<span class="token comment">#</span>
<span class="token comment"># 通过在 crate package 的 Cargo.toml 文件, 而非 workspace 级别的 .cargo/config.toml 的环境变量来配置,</span>
<span class="token comment"># 可以更灵活和个性化.</span>
<span class="token comment">#</span>
<span class="token comment"># 下面的 package.metadata.esp-idf-sys 只能在 root crate 中配置才能生效, 而 root crate 的配置方式有两种:</span>
<span class="token comment"># 1. 在 workspace 的 Cargo.toml 中配置的 [package] 称为 root crate;</span>
<span class="token comment"># 2. 否则, 需要在 workspace 的 .cargo/config.toml 中用环境变量配置 ESP_IDF_SYS_ROOT_CRATE 配置 root crate 如 "esp32-camera-binding".</span>
<span class="token punctuation">[</span><span class="token table class-name">package.metadata.esp-idf-sys</span><span class="token punctuation">]</span>
<span class="token key property">esp_idf_tools_install_dir</span> <span class="token punctuation">=</span> <span class="token string">"workspace"</span>
<span class="token key property">esp_idf_sdkconfig</span> <span class="token punctuation">=</span> <span class="token string">"sdkconfig"</span> <span class="token comment"># 相对于 workspace 目录</span>
<span class="token key property">esp_idf_sdkconfig_defaults</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"sdkconfig.defaults"</span><span class="token punctuation">,</span> <span class="token string">"sdkconfig.defaults.esp32s3"</span><span class="token punctuation">]</span> <span class="token comment"># 相对于 workspace 目录</span>
<span class="token comment">#esp_idf_components = ["pthread"]</span>
<span class="token comment"># native builder only</span>
<span class="token key property">esp_idf_version</span> <span class="token punctuation">=</span> <span class="token string">"v5.2.1"</span>
<span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token table class-name">package.metadata.esp-idf-sys.extra_components</span><span class="token punctuation">]</span><span class="token punctuation">]</span> <span class="token comment"># 为 esp-idf-sys 添加额外的 C component</span>
<span class="token key property">component_dirs</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span> <span class="token string">"esp32-camera"</span> <span class="token punctuation">]</span> <span class="token comment"># 本地 component 目录列表</span>
<span class="token key property">bindings_header</span> <span class="token punctuation">=</span> <span class="token string">"bindings.h"</span> <span class="token comment"># bindgen 头文件,内容为 component 的头文件</span>
<span class="token key property">bindings_module</span> <span class="token punctuation">=</span> <span class="token string">"camera"</span> <span class="token comment"># bindgen 转换后的 Rust 代码所属的 esp-idf-sys module</span>
zj@a:~/code/esp32/std/esp32-camera-binding$</span></span></span></code></pre><div id="https://www.notion.so/e848c2b912ae41f4a6d87aa529407da6" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">上面是手动将 component 下载到本地,还可以添加 ESP-IDF component registry 中的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">remote component</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> ,这时 esp-idf 会自动下载到本地。</mark></span></span></p></div><div id="https://www.notion.so/fa05cc3179d64a119ab54b130a13e0ba" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></p></div><pre id="https://www.notion.so/90862e77357642668c590a2c89288bd2" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span><span class="token punctuation">[</span><span class="token table class-name">package.metadata.esp-idf-sys.extra_components.0.remote_component</span><span class="token punctuation">]</span>
<span class="token comment"># The name of the remote component. Corresponds to a key in the dependencies of</span>
<span class="token comment"># `idf_component.yml`.</span>
<span class="token key property">name</span> <span class="token punctuation">=</span> <span class="token string">"component_name"</span>
<span class="token comment"># The version of the remote component. Corresponds to the `version` field of the</span>
<span class="token comment"># `idf_component.yml`. </span>
<span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"1.2"</span>
<span class="token comment"># A git url that contains this remote component. Corresponds to the `git`</span>
<span class="token comment"># field of the `idf_component.yml`.</span>
<span class="token comment">#</span>
<span class="token comment"># This field is optional.</span>
<span class="token key property">git</span> <span class="token punctuation">=</span> <span class="token string">"https://github.com/espressif/esp32-camera.git"</span>
<span class="token comment"># A path to the component.</span>
<span class="token comment"># Corresponds to the `path` field of the `idf_component.yml`.</span>
<span class="token comment">#</span>
<span class="token comment"># Note: This should not be used for local components, use</span>
<span class="token comment"># `component_dirs` of extra components instead.</span>
<span class="token comment">#</span>
<span class="token comment"># This field is optional.</span>
<span class="token key property">path</span> <span class="token punctuation">=</span> <span class="token string">"path/to/component"</span>
<span class="token comment"># A url to a custom component registry. Corresponds to the `service_url`</span>
<span class="token comment"># field of the `idf_component.yml`.</span>
<span class="token comment">#</span>
<span class="token comment"># This field is optional.</span>
<span class="token key property">service_url</span> <span class="token punctuation">=</span> <span class="token string">"https://componentregistry.company.com"</span></span></span></span></code></pre><div id="https://www.notion.so/00f06e334c844e8ab6052a9fe6d49f4d" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">remote component 示例:</mark></span></span></p></div><div id="https://www.notion.so/822e8df960164d59a089531814229a41" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></p></div><pre id="https://www.notion.so/e91be435a46e410c9020155d8c2cfe37" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>zj@a:~/code/esp32/std/esp32-camera-binding$ cat Cargo<span class="token punctuation">.</span>toml
<span class="token punctuation">[</span><span class="token table class-name">package</span><span class="token punctuation">]</span>
<span class="token key property">name</span> <span class="token punctuation">=</span> <span class="token string">"esp32-camera-binding"</span>
<span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.1.0"</span>
<span class="token key property">authors</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"alizj"</span><span class="token punctuation">]</span>
<span class="token key property">edition</span> <span class="token punctuation">=</span> <span class="token string">"2021"</span>
<span class="token key property">resolver</span> <span class="token punctuation">=</span> <span class="token string">"2"</span>
<span class="token key property">rust-version</span> <span class="token punctuation">=</span> <span class="token string">"1.71"</span>
<span class="token punctuation">[</span><span class="token table class-name">profile.release</span><span class="token punctuation">]</span>
<span class="token key property">opt-level</span> <span class="token punctuation">=</span> <span class="token string">"s"</span>
<span class="token punctuation">[</span><span class="token table class-name">profile.dev</span><span class="token punctuation">]</span>
<span class="token key property">debug</span> <span class="token punctuation">=</span> <span class="token boolean">true</span> <span class="token comment"># Symbols are nice and they don't increase the size on Flash</span>
<span class="token key property">opt-level</span> <span class="token punctuation">=</span> <span class="token string">"z"</span>
<span class="token punctuation">[</span><span class="token table class-name">features</span><span class="token punctuation">]</span>
<span class="token key property">default</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"std"</span><span class="token punctuation">,</span> <span class="token string">"embassy"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/native"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-sys/native"</span><span class="token punctuation">]</span>
<span class="token key property">pio</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/pio"</span><span class="token punctuation">]</span>
<span class="token key property">std</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"alloc"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/binstart"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/std"</span><span class="token punctuation">]</span>
<span class="token key property">alloc</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/alloc"</span><span class="token punctuation">]</span>
<span class="token key property">nightly</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/nightly"</span><span class="token punctuation">]</span>
<span class="token key property">experimental</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/experimental"</span><span class="token punctuation">]</span>
<span class="token key property">embassy</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"esp-idf-svc/embassy-sync"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/critical-section"</span><span class="token punctuation">,</span> <span class="token string">"esp-idf-svc/embassy-time-driver"</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token table class-name">dependencies</span><span class="token punctuation">]</span>
<span class="token key property">log</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.4"</span><span class="token punctuation">,</span> <span class="token key property">default-features</span> <span class="token punctuation">=</span> <span class="token boolean">false</span> <span class="token punctuation">}</span>
<span class="token key property">esp-idf-svc</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.48"</span> <span class="token punctuation">}</span>
<span class="token key property">esp-idf-sys</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.34.1"</span><span class="token punctuation">}</span>
<span class="token key property">esp-idf-hal</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"0.43.1"</span><span class="token punctuation">}</span>
<span class="token key property">embedded-svc</span> <span class="token punctuation">=</span> <span class="token string">"0.21"</span>
<span class="token key property">anyhow</span> <span class="token punctuation">=</span> <span class="token string">"1"</span>
<span class="token key property">base64</span> <span class="token punctuation">=</span> <span class="token string">"0.13.0"</span>
<span class="token punctuation">[</span><span class="token table class-name">build-dependencies</span><span class="token punctuation">]</span>
<span class="token key property">embuild</span> <span class="token punctuation">=</span> <span class="token string">"0.31.3"</span>
<span class="token comment"># esp-idf-sys 的构建脚本 embuild 在编译 esp-idf C 时使用的配置参数.</span>
<span class="token comment">#</span>
<span class="token comment"># 通过在 crate package 的 Cargo.toml 文件, 而非 workspace 级别的 .cargo/config.toml 的环境变量来配</span>
<span class="token comment"># 置,可以更灵活和个性化.</span>
<span class="token comment">#</span>
<span class="token comment"># 下面的 package.metadata.esp-idf-sys 只能在 root crate 中配置才能生效, 而 root crate 的配置方式有两种:</span>
<span class="token comment"># 1. 在 workspace 的 Cargo.toml 中配置的 [package] 称为 root crate;</span>
<span class="token comment"># 2. 否则, 需要在 workspace 的 .cargo/config.toml 中用环境变量配置 ESP_IDF_SYS_ROOT_CRATE 配置 root crate 如 "esp32-camera-binding".</span>
<span class="token punctuation">[</span><span class="token table class-name">package.metadata.esp-idf-sys</span><span class="token punctuation">]</span>
<span class="token key property">esp_idf_tools_install_dir</span> <span class="token punctuation">=</span> <span class="token string">"workspace"</span>
<span class="token key property">esp_idf_sdkconfig</span> <span class="token punctuation">=</span> <span class="token string">"sdkconfig"</span> <span class="token comment"># 相对于 workspace 目录</span>
<span class="token key property">esp_idf_sdkconfig_defaults</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"sdkconfig.defaults"</span><span class="token punctuation">,</span> <span class="token string">"sdkconfig.defaults.esp32s3"</span><span class="token punctuation">]</span> <span class="token comment"># 相对于 workspace 目录</span>
<span class="token comment">#esp_idf_components = ["pthread"]</span>
<span class="token comment"># native builder only</span>
<span class="token key property">esp_idf_version</span> <span class="token punctuation">=</span> <span class="token string">"v5.2.1"</span>
<span class="token comment"># 对于 virtual workspace 类型, 必须在 .cargo/config.toml 中配置 ESP_IDF_SYS_ROOT_CRATE 来指定 root crate package.</span>
<span class="token comment">#esp_idf_sys_root_crate="esp32-camera-binding"</span>
<span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token table class-name">package.metadata.esp-idf-sys.extra_components</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
<span class="token key property">component_dirs</span> <span class="token punctuation">=</span> <span class="token string">"esp32-camera"</span> <span class="token comment"># 本地 component</span>
<span class="token key property">bindings_header</span> <span class="token punctuation">=</span> <span class="token string">"bindings.h"</span>
<span class="token key property">bindings_module</span> <span class="token punctuation">=</span> <span class="token string">"camera"</span>
<span class="token punctuation">[</span><span class="token punctuation">[</span><span class="token table class-name">package.metadata.esp-idf-sys.extra_components</span><span class="token punctuation">]</span><span class="token punctuation">]</span>
<span class="token key property">remote_component</span> <span class="token punctuation">=</span> <span class="token punctuation">{</span> <span class="token key property">name</span> <span class="token punctuation">=</span> <span class="token string">"espressif/button"</span><span class="token punctuation">,</span> <span class="token key property">version</span> <span class="token punctuation">=</span> <span class="token string">"3.2.0"</span><span class="token punctuation">}</span> <span class="token comment"># 远程 ESP-IDF component registry</span>
<span class="token key property">bindings_header</span> <span class="token punctuation">=</span> <span class="token string">"bindings.h"</span>
<span class="token key property">bindings_module</span> <span class="token punctuation">=</span> <span class="token string">"button"</span>
zj@a:~/code/esp32/std/esp32-camera-binding$
zj@a:~/code/esp32/std/esp32-camera-binding$ cat bindings<span class="token punctuation">.</span>h <span class="token comment"># 两个 component 的头文件</span>
<span class="token comment">#include "esp_camera.h"</span>
<span class="token comment">#include "iot_button.h"</span></span></span></span></code></pre><div id="https://www.notion.so/aa21d4bc974c4169a48d3262c122c05a" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">cargo build 会自动将 component 下载到本地,然后进行 bindgen 和链接:</mark></span></span></p></div><div id="https://www.notion.so/9dd7820a83af49639266c96dd072505d" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></p></div><pre id="https://www.notion.so/e6a5959d78a84e759f5991b6509a274b" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>zj@a:~/code/esp32/std/esp32-camera-binding$ <span class="token function">ls</span> <span class="token parameter variable">-l</span> <span class="token punctuation">..</span>/target/xtensa-esp32s3-espidf/debug/build/esp-idf-sys-7b038a52fa416f70/out
total <span class="token number">5</span>.3M
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">1</span>.4K <span class="token number">7</span> <span class="token number">24</span> <span class="token number">2006</span> CMakeLists.txt
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">5</span>.2M <span class="token number">5</span> <span class="token number">24</span> <span class="token number">12</span>:36 bindings.rs <span class="token comment"># eps-idf-sys 所有 component Rust 接口绑定</span>
drwxr-xr-x <span class="token number">36</span> alizj <span class="token number">1</span>.2K <span class="token number">5</span> <span class="token number">24</span> <span class="token number">12</span>:36 build/
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">2</span>.6K <span class="token number">5</span> <span class="token number">24</span> <span class="token number">12</span>:36 esp-idf-build.json
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">147</span> <span class="token number">5</span> <span class="token number">24</span> <span class="token number">12</span>:36 gen-sdkconfig.defaults
drwxr-xr-x <span class="token number">5</span> alizj <span class="token number">160</span> <span class="token number">5</span> <span class="token number">24</span> <span class="token number">12</span>:35 main/
drwxr-xr-x <span class="token number">4</span> alizj <span class="token number">128</span> <span class="token number">5</span> <span class="token number">24</span> <span class="token number">12</span>:35 managed_components/ <span class="token comment"># 自动下载到本地的 remote component 目录</span>
-rw-r--r-- <span class="token number">1</span> alizj 62K <span class="token number">5</span> <span class="token number">24</span> <span class="token number">12</span>:36 sdkconfig
zj@a:~/code/esp32/std/esp32-camera-binding$ <span class="token function">ls</span> <span class="token parameter variable">-l</span> <span class="token punctuation">..</span>/target/xtensa-esp32s3-espidf/debug/build/esp-idf-sys-7b038a52fa416f70/out/managed_components/
total <span class="token number">0</span>
drwxr-xr-x <span class="token number">16</span> alizj <span class="token number">512</span> <span class="token number">5</span> <span class="token number">24</span> <span class="token number">12</span>:35 espressif__button/ <span class="token comment"># button</span>
drwxr-xr-x <span class="token number">19</span> alizj <span class="token number">608</span> <span class="token number">5</span> <span class="token number">24</span> <span class="token number">12</span>:35 espressif__cmake_utilities/
zj@a:~/code/esp32/std/esp32-camera-binding$ <span class="token function">ls</span> <span class="token parameter variable">-l</span> <span class="token punctuation">..</span>/target/xtensa-esp32s3-espidf/debug/build/esp-idf-sys-7b038a52fa416f70/out/managed_components/espressif__button/
total 84K
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">2</span>.4K <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 CHANGELOG.md
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">487</span> <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 CMakeLists.txt
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">1</span>.8K <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 Kconfig
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">1</span>.7K <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 README.md
-rw-r--r-- <span class="token number">1</span> alizj 12K <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 button_adc.c
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">2</span>.6K <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 button_gpio.c
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">2</span>.0K <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 button_matrix.c
drwxr-xr-x <span class="token number">3</span> alizj <span class="token number">96</span> <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 examples/
-rw-r--r-- <span class="token number">1</span> alizj <span class="token number">440</span> <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 idf_component.yml
drwxr-xr-x <span class="token number">6</span> alizj <span class="token number">192</span> <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 include/
-rw-r--r-- <span class="token number">1</span> alizj 30K <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 iot_button.c
-rw-r--r-- <span class="token number">1</span> alizj 12K <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 license.txt
drwxr-xr-x <span class="token number">8</span> alizj <span class="token number">256</span> <span class="token number">1</span> <span class="token number">9</span> <span class="token number">16</span>:34 test_apps/
zj@a:~/code/esp32/std/esp32-camera-binding$ <span class="token function">grep</span> <span class="token parameter variable">-A</span> <span class="token number">3</span> <span class="token string">'pub mod camera'</span> <span class="token punctuation">..</span>/target/xtensa-esp32s3-espidf/debug/build/esp-idf-sys-7b038a52fa416f70/out/bindings.rs
pub mod camera <span class="token punctuation">{</span>
/* automatically generated by rust-bindgen <span class="token number">0.63</span>.0 */
<span class="token comment">#[repr(C)]</span>
zj@a:~/code/esp32/std/esp32-camera-binding$ <span class="token function">grep</span> <span class="token parameter variable">-A</span> <span class="token number">3</span> <span class="token string">'pub mod button'</span> <span class="token punctuation">..</span>/target/xtensa-esp32s3-espidf/debug/build/esp-idf-sys-7b038a52fa416f70/out/bindings.rs
pub mod button <span class="token punctuation">{</span>
/* automatically generated by rust-bindgen <span class="token number">0.63</span>.0 */
<span class="token comment">#[repr(C)]</span></span></span></span></code></pre><h2 id="https://www.notion.so/e19eea356cf04bb9b882d5018fbb16eb" class="ColorfulBlock ColorfulBlock--ColorDefault Heading Heading--2"><a class="Anchor" href="#https://www.notion.so/e19eea356cf04bb9b882d5018fbb16eb"><svg width="16" height="16" viewBox="0 0 16 16"><path fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path></svg></a><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">2 配置 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-rs</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 项目的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf-sys</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 参数 </mark></span></span></h2><div id="https://www.notion.so/7bb9e858aef841ada98f07a1a11c50ca" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">各</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"> esp-idf-sys</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 配置参数有环境变量和 metadata 两种方式(环境变量的优先级更高):</mark></span></span></p></div><ol class="NumberedListWrapper"><li id="https://www.notion.so/a38908b3b7804729a91e03bc0f6120fd" class="NumberedList" value="1"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">在 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">.cargo/config.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 中配置 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">env </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">环境变量、</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">rusts flags</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">;</mark></span></span></li><li id="https://www.notion.so/6437f709cc184277b7ac180b5cff49b2" class="NumberedList" value="2"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">在 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">Cargo.toml </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">中为 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">[package.metadata.esp-idf-sys] section </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">添加配置参数;</mark></span></span></li></ol><div id="https://www.notion.so/8bbe686a9c084948aa37dbe31256c68d" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">如果项目 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">crate package </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">位于 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">workspace </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">中,则:</mark></span></span></p></div><ol class="NumberedListWrapper"><li id="https://www.notion.so/67d7e7054ff94b73bdb34ede9cee3c8b" class="NumberedList" value="1"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">上面 .</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">cargo/config.toml </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">为 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">workspace</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 根目录下的目录和配置;</mark></span></span></li><li id="https://www.notion.so/f227fa7d1493486393b40d467149ec5d" class="NumberedList" value="2"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">[package.metadata.esp-idf-sys]</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 位于项目 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">crate package</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 的</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"> Cargo.toml </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">文件中;</mark></span></span></li><li id="https://www.notion.so/bb98f08054844bd195013da999f939f2" class="NumberedList" value="3"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">如果 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">workspace</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 没有 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">root package</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">,则称为 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">virtual workspace</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">,这时需要在 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">workspace</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">.cargo/config.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 中通过环境变量 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">ESP_IDF_SYS_ROOT_CRATE </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">来指定项目 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">crate package</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 名称,否则编译 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf-sys</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 时不会编译和</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code"> bindgen</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 额外的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">component</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">。</mark></span></span></li></ol><div id="https://www.notion.so/b76bb4650ac84f169f162c1196790773" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">通过项目 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">crate package</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">Cargo.toml [package.metadata.esp-idf-sys]</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 配置:</mark></span></span></p></div><ul class="BulletedListWrapper"><li id="https://www.notion.so/d6f65d87273142e790d5187fbaa89da9" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">必须在先在 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">workspace </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">.cargo/config.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 中配置环境变量 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">ESP_IDF_SYS_ROOT_CRATE </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">指向本 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">crates</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">,下面的配置才生效。</mark></span></span></li></ul><div id="https://www.notion.so/7f06987dda594b68b5e8a1fb63da31a2" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></p></div><pre id="https://www.notion.so/6e112a8b73e541ec92608241afc72026" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span><span class="token punctuation">[</span><span class="token table class-name">package.metadata.esp-idf-sys</span><span class="token punctuation">]</span>
<span class="token key property">esp_idf_tools_install_dir</span> <span class="token punctuation">=</span> <span class="token string">"global"</span>
<span class="token key property">esp_idf_sdkconfig</span> <span class="token punctuation">=</span> <span class="token string">"sdkconfig"</span>
<span class="token key property">esp_idf_sdkconfig_defaults</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"sdkconfig.defaults"</span><span class="token punctuation">,</span> <span class="token string">"sdkconfig.defaults.ble"</span><span class="token punctuation">]</span>
<span class="token comment"># native builder only</span>
<span class="token key property">esp_idf_version</span> <span class="token punctuation">=</span> <span class="token string">"branch:release/v4.4"</span>
<span class="token key property">esp_idf_components</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"pthread"</span><span class="token punctuation">]</span></span></span></span></code></pre><div id="https://www.notion.so/f431b35f0d6a4932b1d0eea476a83a8c" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">通过 cargo/config.toml 中的 env 配置: </mark></span><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/esp-rs/esp-idf-sys/blob/master/BUILD-OPTIONS.md"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">环境变量列表</mark></a></span></span></p></div><ol class="NumberedListWrapper"><li id="https://www.notion.so/99827039d1b941b1bd7b08083c80048d" class="NumberedList" value="1"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp_idf_sdkconfig_defaults, $ESP_IDF_SDKCONFIG_DEFAULTS: 默认为 sdkconfig.defaults;</mark></span></span></li><li id="https://www.notion.so/6325bf191d114a1493a6e343f7cd2597" class="NumberedList" value="2"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp_idf_sdkconfig, $ESP_IDF_SDKCONFIG: 默认为 sdkconfig</mark></span></span></li><li id="https://www.notion.so/082ef9e4dfed40fca94b2de56b6b66b9" class="NumberedList" value="3"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp_idf_tools_install_dir, $ESP_IDF_TOOLS_INSTALL_DIR, 可选值为:</mark></span></span><ul class="BulletedListWrapper"><li id="https://www.notion.so/a90157c2aef740b4888b4e97baa338b7" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">workspace(缺省),默认为 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">/.embuild/espressif;</mark></span></span></li><li id="https://www.notion.so/05713fb18a4e4f8ab4a436e31b92f250" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">out - the tooling will be installed or used inside esp-idf-sys’s build output directory, and will be deleted when </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">cargo clean</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> is invoked;</mark></span></span></li><li id="https://www.notion.so/ba19d647ba8e4588901273684924cadd" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">global(建议)</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> - the tooling will be installed or used in its standard directory (~/.platformio for PlatformIO, and </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">~/.espressif</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> for the native ESP-IDF toolset);</mark></span></span></li><li id="https://www.notion.so/cfd2143ba7bf451b805058d90486b239" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">custom:</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> - the tooling will be installed or used in the directory specified by </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">. If this directory is a relative location, it is assumed to be relative to the workspace directory;</mark></span></span></li></ul></li><li id="https://www.notion.so/342ad6e5736d4a3398118cc14a8e9da7" class="NumberedList" value="4"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">idf_path, $IDF_PATH (native builder only): A path to a user-provided local clone of the esp-idf, that will be used instead of the one downloaded by the build script.</mark></span></span></li><li id="https://www.notion.so/38ae61dce31d41e8849d3121d3254900" class="NumberedList" value="5"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp_idf_version, $ESP_IDF_VERSION (native builder only) : The version used for the esp-idf, can be one of the following</mark></span></span></li><li id="https://www.notion.so/7c083eb743f44bd69adbbf5bd371365e" class="NumberedList" value="6"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">mcu, $MCU: The MCU name (i.e. esp32, esp32s2, esp32s3 esp32c3, esp32c2, esp32h2, esp32c5, esp32c6, esp32p4).</mark></span></span></li><li id="https://www.notion.so/d459e6d5b34041a6bfd43b0797157044" class="NumberedList" value="7"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp_idf_components, $ESP_IDF_COMPONENTS (native builder only) : Defaults to </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">all components</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> being built.</mark></span></span><ul class="BulletedListWrapper"><li id="https://www.notion.so/2298db7865b941e3838298e72d9db003" class="BulletedList"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp-idf 的 component 列表参考 </mark></span><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/espressif/esp-idf/tree/master/components"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp-idf components 目录</mark></a></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> ;</mark></span></span></li></ul></li></ol><div id="https://www.notion.so/552bdbf1511f41b18e315ca9835b6409" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">为了加快 cargo build 速率,避免每次都重新编译构建 esp-idf,建议使用的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">.cargo/config.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 示例配置(在项目执行 cargo build 命令来进行验证):</mark></span></span></p></div><div id="https://www.notion.so/ce70ae3687324c88b2655833e0df4f69" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></p></div><pre id="https://www.notion.so/603b9edb7d644fd2b0d02558bd83a618" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span><span class="token punctuation">[</span><span class="token table class-name">build</span><span class="token punctuation">]</span>
<span class="token key property">target</span> <span class="token punctuation">=</span> <span class="token string">"xtensa-esp32s3-espidf"</span>
<span class="token comment"># 使用 sccache 来调用 rustc 编译器, 有利用缓存加快构建速度.</span>
<span class="token comment"># 先安装 sccache: cargo install sccache --locked</span>
<span class="token key property">rustc-wrapper</span> <span class="token punctuation">=</span> <span class="token string">"/opt/homebrew/bin/sccache"</span>
<span class="token punctuation">[</span><span class="token table class-name">target.xtensa-esp32s3-espidf</span><span class="token punctuation">]</span>
<span class="token key property">linker</span> <span class="token punctuation">=</span> <span class="token string">"ldproxy"</span>
<span class="token comment"># runner = "espflash --monitor" # Select this runner for espflash v1.x.x</span>
<span class="token key property">runner</span> <span class="token punctuation">=</span> <span class="token string">"espflash flash --monitor"</span> <span class="token comment"># Select this runner for espflash v2.x.x</span>
<span class="token comment"># 以下是使用 rustc 构建 esp-rs/esp-idf-sys 时传递的参数</span>
<span class="token comment"># https://github.com/esp-rs/esp-idf-sys/blob/master/BUILD-OPTIONS.md This is a flag for the libc</span>
<span class="token comment"># crate that uses 64-bits (instead of 32-bits) for time_t. This must be set for ESP-IDF 5.0 and</span>
<span class="token comment"># above and must be unset for lesser versions.</span>
<span class="token key property">rustflags</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span> <span class="token string">"--cfg"</span><span class="token punctuation">,</span> <span class="token string">"espidf_time64"</span><span class="token punctuation">]</span> <span class="token comment"># Extending time_t for ESP IDF 5: https://github.com/esp-rs/rust/issues/110</span>
<span class="token comment"># https://github.com/esp-rs/esp-idf-sys/blob/master/BUILD-OPTIONS.md</span>
<span class="token comment"># 等效于: -Zbuild-std=std,panic_abort</span>
<span class="token comment"># Required for std support. Rust does not provide std libraries for ESP32 targets since they are tier-2/-3.</span>
<span class="token punctuation">[</span><span class="token table class-name">unstable</span><span class="token punctuation">]</span>
<span class="token key property">build-std</span> <span class="token punctuation">=</span> <span class="token punctuation">[</span><span class="token string">"std"</span><span class="token punctuation">,</span> <span class="token string">"panic_abort"</span><span class="token punctuation">]</span>
<span class="token comment"># cargo 调用命令时使用的环境变量</span>
<span class="token comment"># 参考:https://github.com/esp-rs/esp-idf-sys/blob/master/BUILD-OPTIONS.md#esp-idf-configuration</span>
<span class="token punctuation">[</span><span class="token table class-name">env</span><span class="token punctuation">]</span>
<span class="token key property">MCU</span><span class="token punctuation">=</span><span class="token string">"esp32s3"</span>
<span class="token comment"># Note: this variable is not used by the pio builder (`cargo build --features pio`)</span>
<span class="token comment"># 最新 esp-idf 版本:https://github.com/espressif/esp-idf/releases</span>
<span class="token key property">ESP_IDF_VERSION</span> <span class="token punctuation">=</span> <span class="token string">"v5.2.q"</span>
<span class="token comment"># 使用全局 ~/.espressif/ 工具链,默认是 by 项目 workspace 的。</span>
<span class="token key property">ESP_IDF_TOOLS_INSTALL_DIR</span> <span class="token punctuation">=</span> <span class="token string">"global"</span></span></span></span></code></pre><div id="https://www.notion.so/2271d926bf344c15ae306f497fd89852" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">sccache </code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">统计信息:</mark></span></span></p></div><div id="https://www.notion.so/7de8966af37142c7927c24f7270cd00a" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></p></div><pre id="https://www.notion.so/ed76ab5d7fe74f579b0a4f5e4fb4ab97" class="Code Code--NoWrap"><code><span class="SemanticStringArray"><span class="SemanticString"><span>zj@a:~/code/esp32/myespv3$ sccache --show-stats
Compile requests <span class="token number">0</span>
Compile requests executed <span class="token number">0</span>
Cache hits <span class="token number">0</span>
Cache misses <span class="token number">0</span>
Cache timeouts <span class="token number">0</span>
Cache <span class="token builtin class-name">read</span> errors <span class="token number">0</span>
Forced recaches <span class="token number">0</span>
Cache <span class="token function">write</span> errors <span class="token number">0</span>
Compilation failures <span class="token number">0</span>
Cache errors <span class="token number">0</span>
Non-cacheable compilations <span class="token number">0</span>
Non-cacheable calls <span class="token number">0</span>
Non-compilation calls <span class="token number">0</span>
Unsupported compiler calls <span class="token number">0</span>
Average cache <span class="token function">write</span> <span class="token number">0.000</span> s
Average compiler <span class="token number">0.000</span> s
Average cache <span class="token builtin class-name">read</span> hit <span class="token number">0.000</span> s
Failed distributed compilations <span class="token number">0</span>
Cache location Local disk: <span class="token string">"/Users/alizj/Library/Caches/Mozilla.sccache"</span>
Use direct/preprocessor mode? <span class="token function">yes</span>
Version <span class="token punctuation">(</span>client<span class="token punctuation">)</span> <span class="token number">0.7</span>.7
Max cache size <span class="token number">10</span> GiB</span></span></span></code></pre><div id="https://www.notion.so/94523c2a94304dd99bdbc78cea3ce3e1" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">参考:</mark></span></span></p></div><ol class="NumberedListWrapper"><li id="https://www.notion.so/7a3d6c3d844f45d287f2b5ff59730d4b" class="NumberedList" value="1"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/esp-rs/std-training"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp-rs/std-trainning</mark></a></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">: Embedded Rust Trainings for Espressif</mark></span></span></li><li id="https://www.notion.so/55e48d4b02a04c54bb6f96791562ae10" class="NumberedList" value="2"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/ivmarkov/rust-esp32-std-demo%EF%BC%9A"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://github.com/ivmarkov/rust-esp32-std-demo%EF%BC%9A</mark></a></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> Rust on ESP32 STD demo app</mark></span></span></li><li id="https://www.notion.so/cce9d9cf48c4414b93768a2646cbea1c" class="NumberedList" value="3"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://apollolabsblog.hashnode.dev/series/esp32-std-embedded-rust%EF%BC%9A"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://apollolabsblog.hashnode.dev/series/esp32-std-embedded-rust%EF%BC%9A</mark></a></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 强烈推荐。</mark></span></span></li><li id="https://www.notion.so/69b93ed656114465bb7ef98e45645212" class="NumberedList" value="4"><span class="SemanticStringArray"><span class="SemanticString"><a class="SemanticString__Fragment SemanticString__Fragment--Link" href="https://github.com/apollolabsdev/ESP32C3"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">https://github.com/apollolabsdev/ESP32C3</mark></a></span></span></li></ol><div id="https://www.notion.so/fcf4b2a6a1a64816b4c538ca0aae3415" class="ColorfulBlock ColorfulBlock--ColorDefault Text"><p class="Text__Content"><span class="SemanticStringArray"></span></p></div><ul id="https://www.notion.so/4136c88ff13d487eb93ad82faebadc63" class="ColorfulBlock ColorfulBlock--ColorGray TableOfContents"><li class="TableOfContents__Item"><a href="#https://www.notion.so/ccd95b333796404b85b472ab6a46c8e8"><div style="margin-left:0px"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">对于 std 应用</mark></span></span></div></a></li><li class="TableOfContents__Item"><a href="#https://www.notion.so/cb2b2b479ff24841b42b95c834da4dd8"><div style="margin-left:0px"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">使用 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">esp-rs/esp-idf-template</mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 模板</mark></span></span></div></a></li><li class="TableOfContents__Item"><a href="#https://www.notion.so/32020fd8821a4a4d9e0852a204bbec46"><div style="margin-left:24px"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">按需修改 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">Cargo.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">:</mark></span></span></div></a></li><li class="TableOfContents__Item"><a href="#https://www.notion.so/db9b662178504b609e66c7a0737ab6f4"><div style="margin-left:24px"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">修改 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">.cargo/config.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></div></a></li><li class="TableOfContents__Item"><a href="#https://www.notion.so/9662be3579fc44bd84b1dcceace26e5a"><div style="margin-left:24px"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">按需修改 esp-idf 的配置参数文件</mark></span></span></div></a></li><li class="TableOfContents__Item"><a href="#https://www.notion.so/a58d875ced0c441fb32f5a70fbef40ce"><div style="margin-left:24px"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">按需修改 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">rust-toolchain.toml</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> </mark></span></span></div></a></li><li class="TableOfContents__Item"><a href="#https://www.notion.so/46a6fccd60a748048f18ea57639baacd"><div style="margin-left:0px"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">构建项目:</mark></span></span></div></a></li><li class="TableOfContents__Item"><a href="#https://www.notion.so/8885e11752484ec4a677b2f5adbb9a0a"><div style="margin-left:0px"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">1 为 Rust std 应用添加组件 component </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">#</mark></span></span></div></a></li><li class="TableOfContents__Item"><a href="#https://www.notion.so/e19eea356cf04bb9b882d5018fbb16eb"><div style="margin-left:0px"><span class="SemanticStringArray"><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault">2 配置 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-rs</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 项目的 </mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"><code class="SemanticString__Fragment SemanticString__Fragment--Code">esp-idf-sys</code></mark></span><span class="SemanticString"><mark class="SemanticString__Fragment SemanticString__Fragment--HighlightedColor SemanticString__Fragment--ColorDefault"> 参数 </mark></span></span></div></a></li></ul></article>
<aside class="Aside">
<a href="#content-html"><div id="up">👆</div></a>
<a href="#message-board"><div id="down">👇</div></a>
</aside>
<div id="message-board"></div>
<script src="https://utteranc.es/client.js"
repo="syx-413/syx-413.github.io"
issue-term="pathname"
theme="boxy-light"
crossorigin="anonymous"
async>
</script>
<footer class="Footer">
<div>
© 413’s Website 2020~2024
</div>
<div>
·
</div>
<div>
Powered by
<a href="https://github.com/syx-413" target="_blank" rel="noopener noreferrer"> notablog</a>.
</div>
</footer>
</body>
</html>