lupyuen.org/articles/rust4.html

766 lines
42 KiB
HTML
Raw Normal View History

2024-04-12 19:18:02 +08:00
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="rustdoc">
<title>Rust Custom Target for QEMU RISC-V on Apache NuttX RTOS</title>
<!-- Begin scripts/articles/*-header.html: Article Header for Custom Markdown files processed by rustdoc, like chip8.md -->
<meta property="og:title"
content="Rust Custom Target for QEMU RISC-V on Apache NuttX RTOS"
data-rh="true">
<meta property="og:description"
content=""
data-rh="true">
<meta name="description"
content="">
<meta property="og:image"
content="https://lupyuen.github.io/images/rust4-title.jpg">
<meta property="og:type"
content="article" data-rh="true">
<link rel="canonical"
href="https://lupyuen.codeberg.page/articles/rust4.html" />
<!-- End scripts/articles/*-header.html -->
<!-- Begin scripts/rustdoc-header.html: Header for Custom Markdown files processed by rustdoc, like chip8.md -->
<link rel="alternate" type="application/rss+xml" title="RSS Feed for lupyuen" href="/rss.xml" />
<link rel="stylesheet" type="text/css" href="../normalize.css">
<link rel="stylesheet" type="text/css" href="../rustdoc.css" id="mainThemeStyle">
<link rel="stylesheet" type="text/css" href="../dark.css">
<link rel="stylesheet" type="text/css" href="../light.css" id="themeStyle">
<link rel="stylesheet" type="text/css" href="../prism.css">
<script src="../storage.js"></script><noscript>
<link rel="stylesheet" href="../noscript.css"></noscript>
<link rel="shortcut icon" href="../favicon.ico">
<style type="text/css">
#crate-search {
background-image: url("../down-arrow.svg");
}
</style>
<!-- End scripts/rustdoc-header.html -->
</head>
<body class="rustdoc">
<!--[if lte IE 8]>
<div class="warning">
This old browser is unsupported and will most likely display funky
things.
</div>
<![endif]-->
<!-- Begin scripts/rustdoc-before.html: Pre-HTML for Custom Markdown files processed by rustdoc, like chip8.md -->
<!-- Begin Theme Picker -->
<div class="theme-picker" style="left: 0"><button id="theme-picker" aria-label="Pick another theme!"><img src="../brush.svg"
width="18" alt="Pick another theme!"></button>
<div id="theme-choices"></div>
</div>
<!-- Theme Picker -->
<!-- End scripts/rustdoc-before.html -->
<h1 class="title">Rust Custom Target for QEMU RISC-V on Apache NuttX RTOS</h1>
<nav id="TOC"><ul>
2024-04-13 00:51:30 +08:00
<li><a href="#software-vs-hardware-floating-point">1 Software vs Hardware Floating-Point</a><ul></ul></li>
2024-04-15 08:44:59 +08:00
<li><a href="#rust-wont-double-float">2 Rust Wont Double-Float</a><ul></ul></li>
2024-04-13 23:25:52 +08:00
<li><a href="#custom-target-for-rust">3 Custom Target for Rust</a><ul></ul></li>
<li><a href="#build-the-rust-core-library">4 Build the Rust Core Library</a><ul></ul></li>
<li><a href="#nuttx-links-ok-with-rust">5 NuttX Links OK with Rust</a><ul></ul></li>
<li><a href="#rust-build-for-64-bit-risc-v">6 Rust Build for 64-bit RISC-V</a><ul></ul></li>
2024-04-15 07:36:02 +08:00
<li><a href="#whats-next">7 Whats Next</a><ul></ul></li>
<li><a href="#appendix-rust-compiler-options">8 Appendix: Rust Compiler Options</a><ul></ul></li></ul></nav><p>📝 <em>22 Apr 2024</em></p>
2024-04-12 19:18:02 +08:00
<p><img src="https://lupyuen.github.io/images/rust4-title.jpg" alt="Rust Apps on Apache NuttX RTOS and QEMU RISC-V" /></p>
2024-04-12 19:40:46 +08:00
<div style="text-align: center">
<p><a href="https://github.com/Swordfish90/cool-retro-term"><em>Thanks to cool-retro-term!</em></a></p>
</div>
2024-04-13 00:51:30 +08:00
<p>Last article we were compiling <a href="TODO"><strong>Rust Apps</strong></a> for <a href="TODO"><strong>Apache NuttX RTOS</strong></a> (QEMU RISC-V 32-bit). And we hit a <strong>baffling error</strong></p>
<div class="example-wrap"><pre class="language-bash"><code>$ make
riscv64-unknown-elf-ld: libapps.a
hello_rust_1.o:
can&#39;t link soft-float modules with double-float modules
</code></pre></div>
<p>Lets solve the problem! We dive inside the internals of <strong>C-to-Rust Interop</strong></p>
<ul>
<li>
<p>Rust compiles for <strong>Soft-Float</strong>, but NuttX expects <strong>Double-Float</strong></p>
<p>(Software vs Hardware Floating-Point)</p>
</li>
<li>
<p>But Rust <strong>doesnt support Double-Float</strong> (by default)</p>
</li>
<li>
<p>So we create a <strong>Rust Custom Target</strong> for Double-Float</p>
</li>
<li>
<p>Rebuild the <strong>Rust Core Library</strong> for Double-Float</p>
</li>
<li>
<p>And our Rust App <strong>builds OK with NuttX</strong>!</p>
</li>
</ul>
<p>TODO: Pic of double float vs soft float </p>
<h1 id="software-vs-hardware-floating-point"><a class="doc-anchor" href="#software-vs-hardware-floating-point">§</a>1 Software vs Hardware Floating-Point</h1>
2024-04-16 03:21:05 +08:00
<p><em>Whats causing our NuttX Build to fail?</em></p>
2024-04-16 03:01:04 +08:00
<div class="example-wrap"><pre class="language-bash"><code>$ make
riscv64-unknown-elf-ld: libapps.a
hello_rust_1.o:
can&#39;t link soft-float modules with double-float modules
</code></pre></div>
<p><strong>GCC Linker</strong> failed because it couldnt link the NuttX Binaries with the Rust Binaries. Heres why…</p>
2024-04-16 03:21:05 +08:00
<p>NuttX Build calls <strong>GCC Compiler</strong> to compile our C Modules…</p>
2024-04-12 19:40:46 +08:00
<div class="example-wrap"><pre class="language-bash"><code>$ make --trace
...
2024-04-16 03:01:04 +08:00
## GCC compiles `hello_main.c` to `hello.o`
## for RISC-V 32-bit (Double-Float)
2024-04-12 19:40:46 +08:00
riscv64-unknown-elf-gcc \
2024-04-16 23:00:41 +08:00
-march=rv32imafdc \
-mabi=ilp32d \
2024-04-12 19:40:46 +08:00
-c \
-fno-common \
-Wall \
-Wstrict-prototypes \
-Wshadow \
-Wundef \
-Wno-attributes \
-Wno-unknown-pragmas \
-Wno-psabi \
-Os \
-fno-strict-aliasing \
-fomit-frame-pointer \
-ffunction-sections \
-fdata-sections \
-g \
-isystem nuttx/include \
-D__NuttX__ \
-DNDEBUG \
-pipe \
-I &quot;apps/include&quot; \
-Dmain=hello_main \
hello_main.c \
2024-04-16 03:21:05 +08:00
-o hello_main.c...apps.examples.hello.o
2024-04-15 10:45:47 +08:00
</code></pre></div>
2024-04-16 03:21:05 +08:00
<p>Then NuttX Build calls <strong>Rust Compiler</strong> to compile our Rust App…</p>
2024-04-16 03:01:04 +08:00
<div class="example-wrap"><pre class="language-bash"><code>$ make --trace
...
## Rust Compiler compiles `hello_rust_main.rs` to `hello_rust.o`
## for RISC-V 32-bit (Soft-Float)
2024-04-15 10:45:47 +08:00
rustc \
2024-04-16 23:00:41 +08:00
--target riscv32i-unknown-none-elf \
2024-04-15 10:45:47 +08:00
--edition 2021 \
--emit obj \
-g \
-C panic=abort \
-O \
hello_rust_main.rs \
-o hello_rust_main.rs...apps.examples.hello_rust.o
</code></pre></div>
2024-04-16 03:21:05 +08:00
<p><em>Is there a problem?</em></p>
2024-04-15 10:45:47 +08:00
<p>Watch closely as we compare <strong>GCC Compiler</strong> with <strong>Rust Compiler</strong></p>
2024-04-15 11:32:01 +08:00
<span style="font-size:90%">
2024-04-15 10:45:47 +08:00
<div><table><thead><tr><th>GCC Compiler</th><th>Rust Compiler</th></tr></thead><tbody>
2024-04-15 10:58:04 +08:00
<tr><td><em>riscv64-unknown-elf-gcc</em> <br>      <em>hello_main.c</em></td><td><em>rustc</em> <br>      <em>hello_rust_main.rs</em></td></tr>
<tr><td><em>-march</em> <br>     <strong>rv32imafdc</strong></td><td><em>target</em> <br>    <strong>riscv32i-unknown-none-elf</strong></td></tr>
<tr><td><em>-mabi</em> <br>     <strong>ilp32d</strong></td><td></td></tr>
2024-04-15 10:45:47 +08:00
</tbody></table>
2024-04-15 11:32:01 +08:00
</div></span>
<p><em>Hmmm something different about the Floats…</em></p>
<p>Yep GCC supports (Double-Precision) <strong>Hardware Floating-Point</strong></p>
<p>Rust Compiler only supports <strong>Software Floating-Point</strong>!</p>
<span style="font-size:90%">
<div><table><thead><tr><th>GCC Compiler</th><th>Rust Compiler</th></tr></thead><tbody>
<tr><td><strong>rv32imafdc</strong></td><td><strong>riscv32i</strong></td></tr>
<tr><td>- <strong>I</strong>: Integer</td><td>- <strong>I</strong>: Integer</td></tr>
<tr><td>- <strong>F</strong>: Single Hard-Float</td><td><em>(Soft-Float)</em></td></tr>
<tr><td>- <strong>D</strong>: Double Hard-Float</td><td><em>(Soft-Float)</em></td></tr>
</tbody></table>
</div></span>
2024-04-15 11:53:07 +08:00
<p>And thats why GCC Linker wont link the binaries!</p>
2024-04-16 16:51:10 +08:00
<p><img src="https://lupyuen.github.io/images/rust4-flow2.jpg" alt="Double-Float vs Soft-Float: GCC Linker wont link the binaries" /></p>
2024-04-15 11:32:01 +08:00
<p>To verify, we dump the <strong>ELF Headers</strong> for GCC and Rust Compiler Outputs…</p>
<div class="example-wrap"><pre class="language-bash"><code>## ELF Header for GCC Output:
## Double-Precision Hardware Floating-Point
2024-04-15 10:45:47 +08:00
$ riscv64-unknown-elf-readelf \
--file-header --arch-specific \
../apps/examples/hello/*hello.o
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2&#39;s complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: RISC-V
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 3776 (bytes into file)
Flags: 0x5, RVC, double-float ABI
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 26
Section header string table index: 25
Attribute Section: riscv
File Attributes
Tag_RISCV_stack_align: 16-bytes
Tag_RISCV_arch: &quot;rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0&quot;
2024-04-16 23:00:41 +08:00
## ELF Header for Rust Compiler Output:
2024-04-15 11:32:01 +08:00
## Software Floating-Point
2024-04-15 10:45:47 +08:00
$ riscv64-unknown-elf-readelf \
--file-header --arch-specific \
../apps/examples/hello_rust/*hello_rust.o
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2&#39;s complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: RISC-V
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 10240 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 1
Attribute Section: riscv
File Attributes
Tag_RISCV_stack_align: 16-bytes
Tag_RISCV_arch: &quot;rv32i2p1&quot;
</code></pre></div>
2024-04-16 23:00:41 +08:00
<p>Indeed we have a problem: Double-Float and Soft-Float wont mix! Lets fix this…</p>
2024-04-15 08:44:59 +08:00
<p>TODO: Pic of Rust Wont Double-Float</p>
<h1 id="rust-wont-double-float"><a class="doc-anchor" href="#rust-wont-double-float">§</a>2 Rust Wont Double-Float</h1>
2024-04-16 23:55:48 +08:00
<p><em>What if we ask Rust Compiler to compile for Double-Float: RV32IMAFDC?</em></p>
<p><a href="https://www.qemu.org/docs/master/system/riscv/virt.html"><strong>QEMU RISC-V</strong></a> offically supports <a href="https://www.qemu.org/docs/master/system/riscv/virt.html"><strong><code>riscv32gc</code></strong></a>.</p>
<p><a href="https://en.wikipedia.org/wiki/RISC-V#ISA_base_and_extensions">(“<strong><code>gc</code></strong>” in “<strong><code>riscv32gc</code></strong>” denotes <strong>IMAFDC</strong>)</a></p>
<p>We could do this…</p>
2024-04-16 23:00:41 +08:00
<div class="example-wrap"><pre class="language-bash"><code>## Compile `hello_rust_main.rs` to `hello_rust.o`
## for Double-Precision Hardware Floating-Point
rustc \
--target riscv32gc-unknown-none-elf \
--edition 2021 \
--emit obj \
-g \
-C panic=abort \
-O \
hello_rust_main.rs \
-o hello_rust.o
</code></pre></div>
<p>Nope sorry it wont work…</p>
<div class="example-wrap"><pre class="language-bash"><code>Error loading target specification:
Could not find specification for target &quot;riscv32gc-unknown-none-elf&quot;.
Run `rustc --print target-list` for a list of built-in targets
</code></pre></div>
2024-04-16 23:55:48 +08:00
<p>Thats because <strong><code>riscv32gc</code></strong> isnt a <strong>Predefined Rust Target</strong></p>
2024-04-16 23:00:41 +08:00
<div class="example-wrap"><pre class="language-bash"><code>## List the Predefined Rust Targets for RISC-V.
## Nope no riscv32gc!
$ rustup target list | grep riscv
2024-04-12 19:40:46 +08:00
riscv32i-unknown-none-elf
riscv32imac-unknown-none-elf
riscv32imc-unknown-none-elf
riscv64gc-unknown-linux-gnu
riscv64gc-unknown-none-elf
riscv64imac-unknown-none-elf
</code></pre></div>
2024-04-16 23:55:48 +08:00
<p>But we can create a <strong>Custom Rust Target</strong> for <strong><code>riscv32gc</code></strong>. Coming up next section!</p>
2024-04-16 23:00:41 +08:00
<p><em>Wont GCC Compiler have the same problem with Double-Float?</em></p>
<p>When we list the <strong>Predefined GCC Targets</strong></p>
2024-04-16 23:55:48 +08:00
<div class="example-wrap"><pre class="language-bash"><code>## List the Predefined Targets for GCC RISC-V.
2024-04-16 23:00:41 +08:00
## ABI means Application Binary Interface
$ riscv64-unknown-elf-gcc --target-help
Supported ABIs (for use with the -mabi= option):
ilp32 ilp32d ilp32e ilp32f lp64 lp64d lp64f
</code></pre></div>
<p>We see that <strong>GCC supports Double-Float</strong>: <strong><code>ilp32d</code></strong></p>
2024-04-12 19:40:46 +08:00
<ul>
2024-04-16 23:00:41 +08:00
<li><strong><code>ilp32</code></strong>: <strong>32-bit</strong> Int, Long and Pointer</li>
<li><strong><code>d</code></strong>: <strong>Double-Precision</strong> Hardware Floating-Point</li>
2024-04-12 19:40:46 +08:00
</ul>
2024-04-16 23:00:41 +08:00
<p>Thats why we saw <strong><code>ilp32d</code></strong> earlier…</p>
2024-04-16 23:55:48 +08:00
<div class="example-wrap"><pre class="language-bash"><code>## GCC compiles for RISC-V 32-bit (Double-Float)
2024-04-16 23:00:41 +08:00
riscv64-unknown-elf-gcc \
-march=rv32imafdc \
-mabi=ilp32d \
...
2024-04-15 07:36:02 +08:00
</code></pre></div>
2024-04-16 23:00:41 +08:00
<p><a href="https://gcc.gnu.org/onlinedocs/gcc/RISC-V-Options.html#index-mabi-5">(More about <strong>Application Binary Interfaces</strong>)</a></p>
2024-04-15 11:53:07 +08:00
<p>TODO: Pic of Custom Target for Rust</p>
2024-04-15 07:36:02 +08:00
<h1 id="custom-target-for-rust"><a class="doc-anchor" href="#custom-target-for-rust">§</a>3 Custom Target for Rust</h1>
2024-04-16 23:55:48 +08:00
<p><em>To compile Rust for Double-Float, we need a Custom Target: riscv32gc</em></p>
<p><em>How to create the Custom Target?</em></p>
2024-04-17 08:49:53 +08:00
<p>According to the <a href="https://docs.rust-embedded.org/embedonomicon/custom-target.html"><strong>Official Rust Docs</strong></a>, we shall…</p>
<ul>
<li>
<p>Copy from a <strong>Predefined Rust Target</strong></p>
<p>(Like <strong><code>riscv32i</code></strong>)</p>
</li>
<li>
<p>Tweak it to fit our <strong>Custom Rust Target</strong></p>
<p>(Which becomes <strong><code>riscv32gc</code></strong>)</p>
</li>
</ul>
<p>This is how we dump a Predefined Rust Target: <strong><code>riscv32i</code></strong> </p>
2024-04-16 23:55:48 +08:00
<div class="example-wrap"><pre class="language-bash"><code>## Dump the Predefined Rust Target:
## riscv32i (32-bit RISC-V with Soft-Float)
$ rustc \
2024-04-12 19:40:46 +08:00
+nightly \
-Z unstable-options \
--print target-spec-json \
--target riscv32i-unknown-none-elf
{
2024-04-16 23:55:48 +08:00
&quot;arch&quot;: &quot;riscv32&quot;,
&quot;atomic-cas&quot;: false,
&quot;cpu&quot;: &quot;generic-rv32&quot;,
2024-04-12 19:40:46 +08:00
&quot;data-layout&quot;: &quot;e-m:e-p:32:32-i64:64-n32-S128&quot;,
2024-04-16 23:55:48 +08:00
&quot;eh-frame-header&quot;: false,
2024-04-12 19:40:46 +08:00
&quot;emit-debug-gdb-scripts&quot;: false,
2024-04-16 23:55:48 +08:00
&quot;is-builtin&quot;: true,
&quot;linker&quot;: &quot;rust-lld&quot;,
&quot;linker-flavor&quot;: &quot;ld.lld&quot;,
&quot;llvm-target&quot;: &quot;riscv32&quot;,
&quot;max-atomic-width&quot;: 0,
&quot;panic-strategy&quot;: &quot;abort&quot;,
&quot;relocation-model&quot;: &quot;static&quot;,
2024-04-12 19:40:46 +08:00
&quot;target-pointer-width&quot;: &quot;32&quot;
}
2024-04-16 23:55:48 +08:00
</code></pre></div>
<p>Thats the Rust Definition of <strong><code>riscv32i</code></strong>: 32-bit RISC-V with Soft-Float.</p>
<p>We do the same for <strong><code>riscv64gc</code></strong>: 64-bit RISC-V with Double-Float…</p>
<div class="example-wrap"><pre class="language-bash"><code>## Dump the Predefined Rust Target:
## riscv64gc (64-bit RISC-V with Hard-Float)
2024-04-12 19:40:46 +08:00
$ rustc \
+nightly \
-Z unstable-options \
--print target-spec-json \
--target riscv64gc-unknown-none-elf
{
2024-04-16 23:55:48 +08:00
&quot;arch&quot;: &quot;riscv64&quot;,
&quot;code-model&quot;: &quot;medium&quot;,
&quot;cpu&quot;: &quot;generic-rv64&quot;,
2024-04-12 19:40:46 +08:00
&quot;data-layout&quot;: &quot;e-m:e-p:64:64-i64:64-i128:128-n32:64-S128&quot;,
2024-04-16 23:55:48 +08:00
&quot;eh-frame-header&quot;: false,
2024-04-12 19:40:46 +08:00
&quot;emit-debug-gdb-scripts&quot;: false,
2024-04-16 23:55:48 +08:00
&quot;features&quot;: &quot;+m,+a,+f,+d,+c&quot;,
&quot;is-builtin&quot;: true,
&quot;linker&quot;: &quot;rust-lld&quot;,
2024-04-12 19:40:46 +08:00
&quot;linker-flavor&quot;: &quot;ld.lld&quot;,
2024-04-16 23:55:48 +08:00
&quot;llvm-abiname&quot;: &quot;lp64d&quot;,
&quot;llvm-target&quot;: &quot;riscv64&quot;,
&quot;max-atomic-width&quot;: 64,
&quot;panic-strategy&quot;: &quot;abort&quot;,
&quot;relocation-model&quot;: &quot;static&quot;,
&quot;supported-sanitizers&quot;: [ &quot;kernel-address&quot; ],
2024-04-12 19:40:46 +08:00
&quot;target-pointer-width&quot;: &quot;64&quot;
}
</code></pre></div>
2024-04-16 23:55:48 +08:00
<p><em>We need to mash the Two Targets into a New Target?</em></p>
<p>Exactly! Based on the above, we create our <strong>Rust Custom Target</strong>: <a href="https://github.com/lupyuen/nuttx-rust-app/blob/main/riscv32gc-unknown-none-elf.json"><em>riscv32gc-unknown-none-elf.json</em></a></p>
2024-04-12 19:40:46 +08:00
<div class="example-wrap"><pre class="language-json"><code>{
2024-04-16 23:55:48 +08:00
&quot;arch&quot;: &quot;riscv32&quot;,
&quot;cpu&quot;: &quot;generic-rv32&quot;,
2024-04-12 19:40:46 +08:00
&quot;data-layout&quot;: &quot;e-m:e-p:32:32-i64:64-n32-S128&quot;,
2024-04-16 23:55:48 +08:00
&quot;eh-frame-header&quot;: false,
2024-04-12 19:40:46 +08:00
&quot;emit-debug-gdb-scripts&quot;: false,
2024-04-16 23:55:48 +08:00
&quot;features&quot;: &quot;+m,+a,+f,+d,+c&quot;,
&quot;linker&quot;: &quot;rust-lld&quot;,
2024-04-12 19:40:46 +08:00
&quot;linker-flavor&quot;: &quot;ld.lld&quot;,
2024-04-16 23:55:48 +08:00
&quot;llvm-abiname&quot;: &quot;ilp32d&quot;,
&quot;llvm-target&quot;: &quot;riscv32&quot;,
&quot;max-atomic-width&quot;: 0,
&quot;panic-strategy&quot;: &quot;abort&quot;,
&quot;relocation-model&quot;: &quot;static&quot;,
2024-04-12 19:40:46 +08:00
&quot;target-pointer-width&quot;: &quot;32&quot;
}
</code></pre></div>
2024-04-16 23:55:48 +08:00
<p>Which is <a href="TODO"><strong><code>riscv32i</code></strong></a> plus these changes…</p>
2024-04-12 19:40:46 +08:00
<ul>
<li>
2024-04-17 13:08:40 +08:00
<p>Remove <em>“is-builtin”: true</em></p>
2024-04-16 23:55:48 +08:00
<p>TODO</p>
2024-04-12 19:40:46 +08:00
</li>
<li>
2024-04-17 13:08:40 +08:00
<p>Remove <em>“atomic-cas”: false</em></p>
2024-04-16 23:55:48 +08:00
<p>TODO</p>
2024-04-12 19:40:46 +08:00
</li>
<li>
2024-04-17 13:08:40 +08:00
<p>Add <em>“features”: “+m,+a,+f,+d,+c”</em></p>
2024-04-16 23:55:48 +08:00
<p>TODO</p>
2024-04-12 19:40:46 +08:00
</li>
<li>
2024-04-17 13:08:40 +08:00
<p>Add <em>“llvm-abiname”: “ilp32d”</em></p>
2024-04-16 23:55:48 +08:00
<p>(<strong><code>ilp32d</code></strong> comes from <strong><code>make --trace</code></strong> above)</p>
<p><a href="https://lupyuen.github.io/articles/rust#custom-rust-target-for-bl602">(More about <strong><code>llvm-abiname</code></strong>)</a></p>
2024-04-12 19:40:46 +08:00
</li>
</ul>
2024-04-17 13:08:40 +08:00
<p>Once Again: Heres how we splice the Two Predefined Targets to create our Custom Target <strong><code>riscv32gc</code></strong></p>
2024-04-17 10:28:26 +08:00
<span style="font-size:80%">
2024-04-17 08:49:53 +08:00
<div><table><thead><tr><th></th><th style="text-align: center"><a href="TODO">riscv32i</a></th><th style="text-align: center"><a href="TODO">riscv64gc</a></th><th style="text-align: center"><a href="TODO">riscv32gc</a></th></tr></thead><tbody>
<tr><td><em>arch</em></td><td style="text-align: center"><strong>riscv32</strong></td><td style="text-align: center">riscv64</td><td style="text-align: center"><strong>riscv32</strong></td></tr>
<tr><td><em>atomic-cas</em></td><td style="text-align: center">false</td><td style="text-align: center"></td><td style="text-align: center"></td></tr>
<tr><td><em>cpu</em></td><td style="text-align: center"><strong>generic-rv32</strong></td><td style="text-align: center">generic-rv64</td><td style="text-align: center"><strong>generic-rv32</strong></td></tr>
<tr><td><em>data-layout</em></td><td style="text-align: center"><strong>e-m:e-p:32…</strong></td><td style="text-align: center">e-m:e-p:64…</td><td style="text-align: center"><strong>e-m:e-p:32…</strong></td></tr>
<tr><td><em>features</em></td><td style="text-align: center"></td><td style="text-align: center"><strong>+m,+a,+f,+d,+c</strong></td><td style="text-align: center"><strong>+m,+a,+f,+d,+c</strong></td></tr>
<tr><td><em>is-builtin</em></td><td style="text-align: center">true</td><td style="text-align: center">true</td><td style="text-align: center"></td></tr>
<tr><td><em>llvm-abiname</em></td><td style="text-align: center"></td><td style="text-align: center">lp64d</td><td style="text-align: center">ilp32d</td></tr>
<tr><td><em>llvm-target</em></td><td style="text-align: center"><strong>riscv32</strong></td><td style="text-align: center">riscv64</td><td style="text-align: center"><strong>riscv32</strong></td></tr>
<tr><td><em>max-atomic-width</em></td><td style="text-align: center"></td><td style="text-align: center">64</td><td style="text-align: center">0</td></tr>
<tr><td><em>target-pointer-width</em></td><td style="text-align: center"><strong>32</strong></td><td style="text-align: center">64</td><td style="text-align: center"><strong>32</strong></td></tr>
2024-04-16 23:55:48 +08:00
</tbody></table>
</div></span>
2024-04-15 11:53:07 +08:00
<p>TODO: Pic of Rust Core Library</p>
2024-04-15 07:36:02 +08:00
<h1 id="build-the-rust-core-library"><a class="doc-anchor" href="#build-the-rust-core-library">§</a>4 Build the Rust Core Library</h1>
2024-04-17 08:49:53 +08:00
<p><em>Were ready to rebuild with Double-Float?</em></p>
2024-04-17 13:08:40 +08:00
<p>Not quite, were not done with the <strong>System Library</strong>!</p>
<div class="example-wrap"><pre class="language-bash"><code>$ rustc \
--target riscv32gc-unknown-none-elf.json \
--edition 2021 \
--emit obj \
-g \
-C panic=abort \
-O \
hello_rust_main.rs \
-o hello_rust.o
error[E0463]: can&#39;t find crate for `core`
</code></pre></div>
<p>Why? Remember…</p>
2024-04-17 08:49:53 +08:00
<ul>
<li>
<p><strong>GCC Compiler</strong> supports Double-Float…</p>
<p>Because its bundled with <strong>C Standard Library</strong> for Double-Float, thus…</p>
</li>
<li>
<p><strong>Rust Compiler</strong> will support Double-Float…</p>
<p>Only when it has the <a href="TODO"><strong>Rust Core Library</strong></a> for Double-Float!</p>
</li>
</ul>
2024-04-17 10:28:26 +08:00
<p><em>And the Rust Core Library comes from?</em></p>
<p>We call Rust Compiler to build the <strong>Rust Core Library</strong> for Double-Float <strong><code>riscv32gc</code></strong></p>
2024-04-17 13:08:40 +08:00
<div class="example-wrap"><pre class="language-bash"><code>## Download our Custom Target for `riscv32gc`
rm -r riscv32gc-unknown-none-elf.json
wget https://raw.githubusercontent.com/lupyuen/nuttx-rust-app/main/riscv32gc-unknown-none-elf.json
2024-04-17 10:28:26 +08:00
## Verify our Custom Target, make sure it&#39;s OK
2024-04-12 19:40:46 +08:00
rustc \
--print cfg \
--target riscv32gc-unknown-none-elf.json
2024-04-17 13:08:40 +08:00
## Create a Rust App. If it exists, erase the binaries.
2024-04-12 19:40:46 +08:00
## Ignore the error: `app already exists`
cargo new app
pushd app
cargo clean
2024-04-17 10:28:26 +08:00
## Build the Rust Core Library for `riscv32gc`
2024-04-17 13:08:40 +08:00
## Include the `alloc` library, which will support Heap Memory in future.
2024-04-12 19:40:46 +08:00
## Ignore the error: `can&#39;t find crate for std`
cargo build \
-Zbuild-std=core,alloc \
--target ../riscv32gc-unknown-none-elf.json
popd
</code></pre></div>
2024-04-17 13:08:40 +08:00
<p><strong>Rust Core Library</strong> for Double-Float <strong><code>riscv32gc</code></strong> is done!</p>
<div class="example-wrap"><pre class="language-bash"><code>## Show the Rust Core Library for `riscv32gc`
$ ls app/target/riscv32gc-unknown-none-elf/debug/deps
alloc-254848389e7e2c53.d
app-cf88b81a5fca23b3.d
compiler_builtins-d5922d64507adf16.d
core-ec2ec78e26b8c830.d
liballoc-254848389e7e2c53.rlib
liballoc-254848389e7e2c53.rmeta
libcompiler_builtins-d5922d64507adf16.rlib
libcompiler_builtins-d5922d64507adf16.rmeta
libcore-ec2ec78e26b8c830.rlib
libcore-ec2ec78e26b8c830.rmeta
librustc_std_workspace_core-3cc5bcc9f701a6e7.rlib
librustc_std_workspace_core-3cc5bcc9f701a6e7.rmeta
rustc_std_workspace_core-3cc5bcc9f701a6e7.d
</code></pre></div>
<p>Now were ready to <strong>rebuild our Rust App</strong> with the Custom Target (linked to our Rust Core Library)…</p>
2024-04-12 19:40:46 +08:00
<div class="example-wrap"><pre class="language-bash"><code>## Compile our Rust App.
2024-04-17 13:08:40 +08:00
## We changed the Target to `riscv32gc-unknown-none-elf.json`
## TODO: Change `../apps` to the NuttX Apps Folder
2024-04-12 19:40:46 +08:00
rustc \
2024-04-16 23:00:41 +08:00
--target riscv32gc-unknown-none-elf.json \
2024-04-12 19:40:46 +08:00
--edition 2021 \
--emit obj \
-g \
-C panic=abort \
-O \
../apps/examples/hello_rust/hello_rust_main.rs \
-o ../apps/examples/hello_rust/*hello_rust.o \
\
-C incremental=app/target/riscv32gc-unknown-none-elf/debug/incremental \
-L dependency=app/target/riscv32gc-unknown-none-elf/debug/deps \
-L dependency=app/target/debug/deps \
--extern noprelude:alloc=`ls app/target/riscv32gc-unknown-none-elf/debug/deps/liballoc-*.rlib` \
--extern noprelude:compiler_builtins=`ls app/target/riscv32gc-unknown-none-elf/debug/deps/libcompiler_builtins-*.rlib` \
--extern noprelude:core=`ls app/target/riscv32gc-unknown-none-elf/debug/deps/libcore-*.rlib` \
-Z unstable-options
2024-04-17 13:08:40 +08:00
</code></pre></div>
2024-04-17 13:28:53 +08:00
<p>(Well talk about the loooong options)</p>
<p><em>Are we Double-Floating yet?</em></p>
<p>Yep we have a <strong>Yummy Double-Float</strong> with 2 scoops of ice cream!</p>
<div class="example-wrap"><pre class="language-bash"><code>## Dump the ELF Header of our Compiled Rust App
2024-04-17 13:08:40 +08:00
## TODO: Change `../apps` to the NuttX Apps Folder
2024-04-17 13:28:53 +08:00
$ riscv64-unknown-elf-readelf \
2024-04-15 10:45:47 +08:00
--file-header --arch-specific \
2024-04-12 19:40:46 +08:00
../apps/examples/hello_rust/*hello_rust.o
2024-04-17 13:28:53 +08:00
## We have Double-Float `riscv32gc` yay!
Flags: 0x5, RVC, double-float ABI
2024-04-17 13:08:40 +08:00
</code></pre></div>
2024-04-17 13:28:53 +08:00
<p><em>How did we get the rustc options?</em></p>
<p>TODO: <code>cargo build</code> will call <code>rustc</code> with a whole bunch of options.</p>
2024-04-17 13:08:40 +08:00
<p>We ran <code>cargo build -v</code> to dump the <code>rustc</code> options that were used to compile a Rust App with our Custom Rust Core Library for <code>riscv32gc</code></p>
<ul>
<li>TODO</li>
</ul>
<p><img src="https://lupyuen.github.io/images/rust4-flow.jpg" alt="NuttX Links OK with Rust" /></p>
<h1 id="nuttx-links-ok-with-rust"><a class="doc-anchor" href="#nuttx-links-ok-with-rust">§</a>5 NuttX Links OK with Rust</h1>
2024-04-17 13:28:53 +08:00
<p><em>Is our NuttX Build hunky dory now?</em></p>
2024-04-17 13:08:40 +08:00
<p>TODO</p>
<div class="example-wrap"><pre class="language-bash"><code>## NuttX should link and execute correctly now.
## TODO: Change `../apps` to the NuttX Apps Folder
2024-04-12 19:40:46 +08:00
cp \
../apps/examples/hello_rust/*hello_rust.o \
../apps/examples/hello_rust/*hello_rust_1.o
2024-04-17 13:08:40 +08:00
## TODO: Change `../nuttx` to the NuttX Kernel Folder
2024-04-12 19:40:46 +08:00
pushd ../nuttx
make
2024-04-17 13:08:40 +08:00
popd
</code></pre></div>
<p>TODO</p>
<div class="example-wrap"><pre class="language-bash"><code>## Boot NuttX in QEMU RISC-V (32-bit)
## TODO: Change `../nuttx` to the NuttX Kernel Folder
pushd ../nuttx
2024-04-12 19:40:46 +08:00
qemu-system-riscv32 \
-semihosting \
-M virt,aclint=on \
-cpu rv32 \
-smp 8 \
-bios none \
-kernel nuttx \
-nographic
popd
</code></pre></div>
<p>And it works!</p>
<p><em>Our Rust App links OK! Has the ELF Header changed?</em></p>
<p>Yep the ELF Header has changed from Soft-Float to Double-Float…</p>
<div class="example-wrap"><pre class="language-bash"><code>## Before Custom Target
$ riscv64-unknown-elf-readelf \
2024-04-15 10:45:47 +08:00
--file-header --arch-specific \
2024-04-12 19:40:46 +08:00
../apps/examples/hello_rust/*hello_rust_1.o
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2&#39;s complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: RISC-V
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 10240 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 1
Attribute Section: riscv
File Attributes
Tag_RISCV_stack_align: 16-bytes
Tag_RISCV_arch: &quot;rv32i2p1&quot;
## After Custom Target
$ riscv64-unknown-elf-readelf \
2024-04-15 10:45:47 +08:00
--file-header --arch-specific \
2024-04-12 19:40:46 +08:00
../apps/examples/hello_rust/*hello_rust.o
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2&#39;s complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: RISC-V
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 10352 (bytes into file)
Flags: 0x5, RVC, double-float ABI
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 29
Section header string table index: 1
Attribute Section: riscv
File Attributes
Tag_RISCV_stack_align: 16-bytes
Tag_RISCV_arch: &quot;rv32i2p1_m2p0_a2p1_f2p2_d2p2_c2p0_zicsr2p0&quot;
## Which looks similar to other C Binaries
$ riscv64-unknown-elf-readelf \
2024-04-15 10:45:47 +08:00
--file-header --arch-specific \
2024-04-12 19:40:46 +08:00
../apps/examples/hello/*hello.o
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2&#39;s complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: REL (Relocatable file)
Machine: RISC-V
Version: 0x1
Entry point address: 0x0
Start of program headers: 0 (bytes into file)
Start of section headers: 3776 (bytes into file)
Flags: 0x5, RVC, double-float ABI
Size of this header: 52 (bytes)
Size of program headers: 0 (bytes)
Number of program headers: 0
Size of section headers: 40 (bytes)
Number of section headers: 26
Section header string table index: 25
Attribute Section: riscv
File Attributes
Tag_RISCV_stack_align: 16-bytes
Tag_RISCV_arch: &quot;rv32i2p0_m2p0_a2p0_f2p0_d2p0_c2p0&quot;
</code></pre></div>
2024-04-15 07:36:02 +08:00
<p>How would Linux Kernel handle these uncommon targets?</p>
<p>This Rust Compiler Issue might be relevant…</p>
<ul>
<li><a href="https://github.com/rust-lang/rust/issues/65024">Allow building for hard-float targets in RISC-V</a></li>
</ul>
<h1 id="rust-build-for-64-bit-risc-v"><a class="doc-anchor" href="#rust-build-for-64-bit-risc-v">§</a>6 Rust Build for 64-bit RISC-V</h1>
<p>TODO</p>
<p><strong>Exercise for the Reader:</strong> Last article we TODO</p>
<div class="example-wrap"><pre class="language-bash"><code>$ tools/configure.sh rv-virt:nsh64
$ make menuconfig
## TODO: Enable &quot;Hello Rust Example&quot;
$ make
RUSTC: hello_rust_main.rs error: Error loading target specification:
Could not find specification for target &quot;riscv64i-unknown-none-elf&quot;.
Run `rustc --print target-list` for a list of built-in targets
make[2]: *** [nuttx/apps/Application.mk:275: hello_rust.o] Error 1
make[1]: *** [Makefile:51: nuttx/apps/examples/hello_rust_all] Error 2
make: *** [tools/LibTargets.mk:232: nuttx/apps/libapps.a] Error 2
</code></pre></div>
<p>Which says that <em>riscv64i-unknown-none-elf</em> isnt a valid Rust Target.</p>
<p>(Should be <em>riscv64gc-unknown-none-elf</em> instead)</p>
<p>Fix the build?
Custom Target?
(10 points)</p>
<h1 id="whats-next"><a class="doc-anchor" href="#whats-next">§</a>7 Whats Next</h1>
<p>TODO</p>
<p>Many Thanks to my <a href="https://github.com/sponsors/lupyuen"><strong>GitHub Sponsors</strong></a> (and the awesome NuttX Community) for supporting my work! This article wouldnt have been possible without your support.</p>
<ul>
<li>
<p><a href="https://github.com/sponsors/lupyuen"><strong>Sponsor me a coffee</strong></a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/nuttx-ox64"><strong>My Current Project: “Apache NuttX RTOS for Ox64 BL808”</strong></a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/nuttx-star64"><strong>My Other Project: “NuttX for Star64 JH7110”</strong></a></p>
</li>
<li>
<p><a href="https://github.com/lupyuen/pinephone-nuttx"><strong>Older Project: “NuttX for PinePhone”</strong></a></p>
</li>
<li>
<p><a href="https://lupyuen.github.io"><strong>Check out my articles</strong></a></p>
</li>
<li>
<p><a href="https://lupyuen.github.io/rss.xml"><strong>RSS Feed</strong></a></p>
</li>
</ul>
<p><em>Got a question, comment or suggestion? Create an Issue or submit a Pull Request here…</em></p>
<p><a href="https://github.com/lupyuen/lupyuen.github.io/blob/master/src/rust4.md"><strong>lupyuen.github.io/src/rust4.md</strong></a></p>
<h1 id="appendix-rust-compiler-options"><a class="doc-anchor" href="#appendix-rust-compiler-options">§</a>8 Appendix: Rust Compiler Options</h1>
<p>TODO</p>
2024-04-12 19:40:46 +08:00
<p><em>How did we figure out the rustc options?</em></p>
<p><code>cargo build</code> will call <code>rustc</code> with a whole bunch of options.</p>
<p>We ran <code>cargo build -v</code> to dump the <code>rustc</code> options that were used to compile a Rust App with our Custom Rust Core Library for <code>riscv32gc</code></p>
<div class="example-wrap"><pre class="language-bash"><code>$ cargo build -v \
-Zbuild-std=core,alloc \
--target ../riscv32gc-unknown-none-elf.json
Compiling compiler_builtins v0.1.101
Compiling core v0.0.0 ($HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core)
Running `$HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/rustc --crate-name build_script_build --edition=2018 $HOME/.cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.101/build.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=94 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C split-debuginfo=unpacked --cfg &#39;feature=&quot;compiler-builtins&quot;&#39; --cfg &#39;feature=&quot;core&quot;&#39; --cfg &#39;feature=&quot;default&quot;&#39; --cfg &#39;feature=&quot;rustc-dep-of-std&quot;&#39; -C metadata=9bd0bac7535b33a8 -C extra-filename=-9bd0bac7535b33a8 --out-dir $HOME/riscv/nuttx-rust-app/app/target/debug/build/compiler_builtins-9bd0bac7535b33a8 -Z force-unstable-if-unmarked -L dependency=$HOME/riscv/nuttx-rust-app/app/target/debug/deps --cap-lints allow`
Running `$HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/rustc --crate-name core --edition=2021 $HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/core/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=94 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=d271c6ebb87f9b41 -C extra-filename=-d271c6ebb87f9b41 --out-dir $HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps --target $HOME/riscv/nuttx-rust-app/riscv32gc-unknown-none-elf.json -Z force-unstable-if-unmarked -L dependency=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps -L dependency=$HOME/riscv/nuttx-rust-app/app/target/debug/deps --cap-lints allow`
Running `$HOME/riscv/nuttx-rust-app/app/target/debug/build/compiler_builtins-9bd0bac7535b33a8/build-script-build`
Compiling rustc-std-workspace-core v1.99.0 ($HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-core)
Running `$HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/rustc --crate-name rustc_std_workspace_core --edition=2021 $HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/rustc-std-workspace-core/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=94 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=52e0df2b2cc19b6e -C extra-filename=-52e0df2b2cc19b6e --out-dir $HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps --target $HOME/riscv/nuttx-rust-app/riscv32gc-unknown-none-elf.json -Z force-unstable-if-unmarked -L dependency=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps -L dependency=$HOME/riscv/nuttx-rust-app/app/target/debug/deps --extern core=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps/libcore-d271c6ebb87f9b41.rmeta --cap-lints allow`
Running `$HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/rustc --crate-name compiler_builtins --edition=2018 $HOME/.cargo/registry/src/index.crates.io-6f17d22bba15001f/compiler_builtins-0.1.101/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=94 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg &#39;feature=&quot;compiler-builtins&quot;&#39; --cfg &#39;feature=&quot;core&quot;&#39; --cfg &#39;feature=&quot;default&quot;&#39; --cfg &#39;feature=&quot;rustc-dep-of-std&quot;&#39; -C metadata=cd0d33c2bd30ca51 -C extra-filename=-cd0d33c2bd30ca51 --out-dir $HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps --target $HOME/riscv/nuttx-rust-app/riscv32gc-unknown-none-elf.json -Z force-unstable-if-unmarked -L dependency=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps -L dependency=$HOME/riscv/nuttx-rust-app/app/target/debug/deps --extern core=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps/librustc_std_workspace_core-52e0df2b2cc19b6e.rmeta --cap-lints allow --cfg &#39;feature=&quot;unstable&quot;&#39; --cfg &#39;feature=&quot;mem&quot;&#39;`
Compiling alloc v0.0.0 ($HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc)
Running `$HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/rustc --crate-name alloc --edition=2021 $HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/lib/rustlib/src/rust/library/alloc/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=94 --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 -C metadata=5d7bc2e4f3c29e08 -C extra-filename=-5d7bc2e4f3c29e08 --out-dir $HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps --target $HOME/riscv/nuttx-rust-app/riscv32gc-unknown-none-elf.json -Z force-unstable-if-unmarked -L dependency=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps -L dependency=$HOME/riscv/nuttx-rust-app/app/target/debug/deps --extern compiler_builtins=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps/libcompiler_builtins-cd0d33c2bd30ca51.rmeta --extern core=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps/libcore-d271c6ebb87f9b41.rmeta --cap-lints allow`
Compiling app v0.1.0 ($HOME/riscv/nuttx-rust-app/app)
Running `$HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/rustc --crate-name app --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=94 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=1ff442e6481e1397 -C extra-filename=-1ff442e6481e1397 --out-dir $HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps --target $HOME/riscv/nuttx-rust-app/riscv32gc-unknown-none-elf.json -C incremental=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/incremental -L dependency=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps -L dependency=$HOME/riscv/nuttx-rust-app/app/target/debug/deps --extern &#39;noprelude:alloc=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps/liballoc-5d7bc2e4f3c29e08.rlib&#39; --extern &#39;noprelude:compiler_builtins=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps/libcompiler_builtins-cd0d33c2bd30ca51.rlib&#39; --extern &#39;noprelude:core=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps/libcore-d271c6ebb87f9b41.rlib&#39; -Z unstable-options`
error[E0463]: can&#39;t find crate for `std`
|
= note: the `riscv32gc-unknown-none-elf` target may not support the standard library
= note: `std` is required by `app` because it does not declare `#![no_std]`
= help: consider building the standard library from source with `cargo build -Zbuild-std`
error: cannot find macro `println` in this scope
--&gt; src/main.rs:2:5
|
2 | println!(&quot;Hello, world!&quot;);
| ^^^^^^^
error: `#[panic_handler]` function required, but not found
For more information about this error, try `rustc --explain E0463`.
error: could not compile `app` (bin &quot;app&quot;) due to 3 previous errors
Caused by:
process didn&#39;t exit successfully: `$HOME/.rustup/toolchains/nightly-x86_64-apple-darwin/bin/rustc --crate-name app --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=94 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 -C metadata=1ff442e6481e1397 -C extra-filename=-1ff442e6481e1397 --out-dir $HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps --target $HOME/riscv/nuttx-rust-app/riscv32gc-unknown-none-elf.json -C incremental=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/incremental -L dependency=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps -L dependency=$HOME/riscv/nuttx-rust-app/app/target/debug/deps --extern &#39;noprelude:alloc=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps/liballoc-5d7bc2e4f3c29e08.rlib&#39; --extern &#39;noprelude:compiler_builtins=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps/libcompiler_builtins-cd0d33c2bd30ca51.rlib&#39; --extern &#39;noprelude:core=$HOME/riscv/nuttx-rust-app/app/target/riscv32gc-unknown-none-elf/debug/deps/libcore-d271c6ebb87f9b41.rlib&#39; -Z unstable-options` (exit status: 1)
</code></pre></div>
2024-04-12 19:18:02 +08:00
<!-- Begin scripts/rustdoc-after.html: Post-HTML for Custom Markdown files processed by rustdoc, like chip8.md -->
<!-- Begin Theme Picker and Prism Theme -->
<script src="../theme.js"></script>
<script src="../prism.js"></script>
<!-- Theme Picker and Prism Theme -->
<!-- End scripts/rustdoc-after.html -->
</body>
</html>