Commit from GitHub Actions

This commit is contained in:
Lee Lup Yuen 2024-04-16 15:55:48 +00:00
parent 5a28458b3f
commit 7231a55cc0

View file

@ -246,7 +246,10 @@ File Attributes
<p>Indeed we have a problem: Double-Float and Soft-Float wont mix! Lets fix this…</p>
<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>
<p><em>What if we ask Rust Compiler to compile for Double-Float?</em></p>
<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>
<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 \
@ -259,13 +262,12 @@ rustc \
hello_rust_main.rs \
-o hello_rust.o
</code></pre></div>
<p>TODO: Explain riscv32gc</p>
<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>
<p>Thats because <em>riscv32gc</em> isnt a <strong>Predefined Rust Target</strong></p>
<p>Thats because <strong><code>riscv32gc</code></strong> isnt a <strong>Predefined Rust Target</strong></p>
<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
@ -277,10 +279,10 @@ riscv64gc-unknown-linux-gnu
riscv64gc-unknown-none-elf
riscv64imac-unknown-none-elf
</code></pre></div>
<p>But we can create a <strong>Custom Rust Target</strong> for <em>riscv32gc</em>. Coming up next section!</p>
<p>But we can create a <strong>Custom Rust Target</strong> for <strong><code>riscv32gc</code></strong>. Coming up next section!</p>
<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>
<div class="example-wrap"><pre class="language-bash"><code>## List the Predefined Targets for GCC RISC-V
<div class="example-wrap"><pre class="language-bash"><code>## List the Predefined Targets for GCC RISC-V.
## ABI means Application Binary Interface
$ riscv64-unknown-elf-gcc --target-help
@ -293,8 +295,7 @@ Supported ABIs (for use with the -mabi= option):
<li><strong><code>d</code></strong>: <strong>Double-Precision</strong> Hardware Floating-Point</li>
</ul>
<p>Thats why we saw <strong><code>ilp32d</code></strong> earlier…</p>
<div class="example-wrap"><pre class="language-bash"><code>## GCC compiles `hello_main.c` to `hello.o`
## for RISC-V 32-bit (Double-Float)
<div class="example-wrap"><pre class="language-bash"><code>## GCC compiles for RISC-V 32-bit (Double-Float)
riscv64-unknown-elf-gcc \
-march=rv32imafdc \
-mabi=ilp32d \
@ -303,35 +304,38 @@ riscv64-unknown-elf-gcc \
<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>
<p>TODO: Pic of Custom Target for Rust</p>
<h1 id="custom-target-for-rust"><a class="doc-anchor" href="#custom-target-for-rust">§</a>3 Custom Target for Rust</h1>
<p>TODO</p>
<p>But nope its not supported! So we create a Rust Custom Target for <code>riscv32gc-unknown-none-elf</code></p>
<ul>
<li><a href="https://docs.rust-embedded.org/embedonomicon/custom-target.html">Custom Target for Rust</a></li>
</ul>
<p>Lets dump the Rust Targets <code>riscv32i</code> and <code>riscv64gc</code> to compare…</p>
<div class="example-wrap"><pre class="language-bash"><code>$ rustc \
<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>
<p>According to the <a href="https://docs.rust-embedded.org/embedonomicon/custom-target.html"><strong>Official Rust Docs</strong></a>, we dump a Predefined Rust Target: <strong><code>riscv32i</code></strong> </p>
<div class="example-wrap"><pre class="language-bash"><code>## Dump the Predefined Rust Target:
## riscv32i (32-bit RISC-V with Soft-Float)
$ rustc \
+nightly \
-Z unstable-options \
--print target-spec-json \
--target riscv32i-unknown-none-elf
{
&quot;arch&quot;: &quot;riscv32&quot;,
&quot;atomic-cas&quot;: false,
&quot;cpu&quot;: &quot;generic-rv32&quot;,
&quot;arch&quot;: &quot;riscv32&quot;,
&quot;atomic-cas&quot;: false,
&quot;cpu&quot;: &quot;generic-rv32&quot;,
&quot;data-layout&quot;: &quot;e-m:e-p:32:32-i64:64-n32-S128&quot;,
&quot;eh-frame-header&quot;: false,
&quot;eh-frame-header&quot;: false,
&quot;emit-debug-gdb-scripts&quot;: false,
&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;,
&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;,
&quot;target-pointer-width&quot;: &quot;32&quot;
}
</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)
$ rustc \
+nightly \
-Z unstable-options \
@ -339,62 +343,79 @@ $ rustc \
--target riscv64gc-unknown-none-elf
{
&quot;arch&quot;: &quot;riscv64&quot;,
&quot;code-model&quot;: &quot;medium&quot;,
&quot;cpu&quot;: &quot;generic-rv64&quot;,
&quot;arch&quot;: &quot;riscv64&quot;,
&quot;code-model&quot;: &quot;medium&quot;,
&quot;cpu&quot;: &quot;generic-rv64&quot;,
&quot;data-layout&quot;: &quot;e-m:e-p:64:64-i64:64-i128:128-n32:64-S128&quot;,
&quot;eh-frame-header&quot;: false,
&quot;eh-frame-header&quot;: false,
&quot;emit-debug-gdb-scripts&quot;: false,
&quot;features&quot;: &quot;+m,+a,+f,+d,+c&quot;,
&quot;is-builtin&quot;: true,
&quot;linker&quot;: &quot;rust-lld&quot;,
&quot;features&quot;: &quot;+m,+a,+f,+d,+c&quot;,
&quot;is-builtin&quot;: true,
&quot;linker&quot;: &quot;rust-lld&quot;,
&quot;linker-flavor&quot;: &quot;ld.lld&quot;,
&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;
],
&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; ],
&quot;target-pointer-width&quot;: &quot;64&quot;
}
</code></pre></div>
<p>Based on the above, we create our Rust Custom Target: <a href="riscv32gc-unknown-none-elf.json">riscv32gc-unknown-none-elf.json</a></p>
<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>
<div class="example-wrap"><pre class="language-json"><code>{
&quot;arch&quot;: &quot;riscv32&quot;,
&quot;cpu&quot;: &quot;generic-rv32&quot;,
&quot;arch&quot;: &quot;riscv32&quot;,
&quot;cpu&quot;: &quot;generic-rv32&quot;,
&quot;data-layout&quot;: &quot;e-m:e-p:32:32-i64:64-n32-S128&quot;,
&quot;eh-frame-header&quot;: false,
&quot;eh-frame-header&quot;: false,
&quot;emit-debug-gdb-scripts&quot;: false,
&quot;features&quot;: &quot;+m,+a,+f,+d,+c&quot;,
&quot;linker&quot;: &quot;rust-lld&quot;,
&quot;features&quot;: &quot;+m,+a,+f,+d,+c&quot;,
&quot;linker&quot;: &quot;rust-lld&quot;,
&quot;linker-flavor&quot;: &quot;ld.lld&quot;,
&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;,
&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;,
&quot;target-pointer-width&quot;: &quot;32&quot;
}
</code></pre></div>
<p>Which is based on <code>riscv32i</code> with these changes…</p>
<p>Which is <a href="TODO"><strong><code>riscv32i</code></strong></a> plus these changes…</p>
<ul>
<li>
<p>Removed <code>&quot;atomic-cas&quot;: false</code></p>
<p>Removed <strong><code>&quot;is-builtin&quot;: true</code></strong></p>
<p>TODO</p>
</li>
<li>
<p>Added <code>&quot;features&quot;: &quot;+m,+a,+f,+d,+c&quot;</code></p>
<p>Removed <strong><code>&quot;atomic-cas&quot;: false</code></strong></p>
<p>TODO</p>
</li>
<li>
<p>Removed <code>&quot;is-builtin&quot;: true</code></p>
<p>Added <strong><code>&quot;features&quot;: &quot;+m,+a,+f,+d,+c&quot;</code></strong></p>
<p>TODO</p>
</li>
<li>
<p>Added <code>&quot;llvm-abiname&quot;: &quot;ilp32d&quot;</code></p>
<p>(<code>ilp32d</code> comes from <code>make --trace</code> above)</p>
<p><a href="https://lupyuen.github.io/articles/rust#custom-rust-target-for-bl602">(More about <code>llvm-abiname</code>)</a></p>
<p>Added <strong><code>&quot;llvm-abiname&quot;: &quot;ilp32d&quot;</code></strong></p>
<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>
</li>
</ul>
<p>Once Again: This is how we splice the Two Predefined Targets to create our Custom Target <strong><code>riscv32gc</code></strong></p>
<span style="font-size:90%">
<div><table><thead><tr><th></th><th>riscv32i</th><th>riscv64gc</th><th>riscv32gc</th></tr></thead><tbody>
<tr><td><em>arch</em></td><td><strong>riscv32</strong></td><td>riscv64</td><td><strong>riscv32</strong></td></tr>
<tr><td><em>atomic-cas</em></td><td>false</td><td></td><td></td></tr>
<tr><td><em>cpu</em></td><td><strong>generic-rv32</strong></td><td>generic-rv64</td><td><strong>generic-rv32</strong></td></tr>
<tr><td><em>data-layout</em></td><td><strong>e-m:e-p:32…</strong></td><td>e-m:e-p:64…</td><td><strong>e-m:e-p:32…</strong></td></tr>
<tr><td><em>features</em></td><td></td><td><strong>+m,+a,+f,+d,+c</strong></td><td><strong>+m,+a,+f,+d,+c</strong></td></tr>
<tr><td><em>is-builtin</em></td><td>true</td><td>true</td><td></td></tr>
<tr><td><em>llvm-abiname</em></td><td></td><td>lp64d</td><td>ilp32d</td></tr>
<tr><td><em>llvm-target</em></td><td><strong>riscv32</strong></td><td>riscv64</td><td><strong>riscv32</strong></td></tr>
<tr><td><em>max-atomic-width</em></td><td></td><td>64</td><td>0</td></tr>
<tr><td><em>target-pointer-width</em></td><td><strong>32</strong></td><td>64</td><td><strong>32</strong></td></tr>
</tbody></table>
</div></span>
<p>TODO: Pic of Rust Core Library</p>
<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>
<p>TODO</p>