Files
garden/KaraKeep/attachments/bcbfe09f-691f-4f9d-a343-ee531061a0c3-armv6k-nintendo-3ds-The-rustc.jpg

182 lines
40 KiB
Plaintext
Raw Permalink Normal View History

2026-04-11 22:51:19 -05:00
<div id="readability-page-1" class="page">
<div id="mdbook-help-container">
<h2>Keyboard shortcuts</h2>
<div>
<p>Press <kbd>←</kbd> or <kbd>→</kbd> to navigate between chapters</p>
<p>Press <kbd>S</kbd> or <kbd>/</kbd> to search in the book</p>
<p>Press <kbd>?</kbd> to show this help</p>
<p>Press <kbd>Esc</kbd> to hide this help</p>
</div>
</div>
<div id="mdbook-body-container">
<nav id="mdbook-sidebar" aria-label="Table of contents" aria-hidden="false">
<ol><li><span><a href="https://doc.rust-lang.org/rustc/what-is-rustc.html" tabindex="0"><strong aria-hidden="true">1.</strong> What is rustc?</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/command-line-arguments.html" tabindex="0"><strong aria-hidden="true">2.</strong> Command-line Arguments</a></span><ol><li><span><a href="https://doc.rust-lang.org/rustc/command-line-arguments/print-options.html" tabindex="0"><strong aria-hidden="true">2.1.</strong> Print Options</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/codegen-options/index.html" tabindex="0"><strong aria-hidden="true">2.2.</strong> Codegen Options</a></span></li></ol></li><li><span><a href="https://doc.rust-lang.org/rustc/jobserver.html" tabindex="0"><strong aria-hidden="true">3.</strong> Jobserver</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/lints/index.html" tabindex="0"><strong aria-hidden="true">4.</strong> Lints</a></span><ol><li><span><a href="https://doc.rust-lang.org/rustc/lints/levels.html" tabindex="0"><strong aria-hidden="true">4.1.</strong> Lint Levels</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/lints/groups.html" tabindex="0"><strong aria-hidden="true">4.2.</strong> Lint Groups</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/lints/listing/index.html" tabindex="0"><strong aria-hidden="true">4.3.</strong> Lint Listing</a></span><ol><li><span><a href="https://doc.rust-lang.org/rustc/lints/listing/allowed-by-default.html" tabindex="0"><strong aria-hidden="true">4.3.1.</strong> Allowed-by-default Lints</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/lints/listing/warn-by-default.html" tabindex="0"><strong aria-hidden="true">4.3.2.</strong> Warn-by-default Lints</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/lints/listing/deny-by-default.html" tabindex="0"><strong aria-hidden="true">4.3.3.</strong> Deny-by-default Lints</a></span></li></ol></li></ol></li><li><span><a href="https://doc.rust-lang.org/rustc/json.html" tabindex="0"><strong aria-hidden="true">5.</strong> JSON Output</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/tests/index.html" tabindex="0"><strong aria-hidden="true">6.</strong> Tests</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/targets/index.html" tabindex="0"><strong aria-hidden="true">7.</strong> Targets</a></span><ol><li><span><a href="https://doc.rust-lang.org/rustc/targets/built-in.html" tabindex="0"><strong aria-hidden="true">7.1.</strong> Built-in Targets</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/targets/custom.html" tabindex="0"><strong aria-hidden="true">7.2.</strong> Custom Targets</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/targets/known-issues.html" tabindex="0"><strong aria-hidden="true">7.3.</strong> Known Issues</a></span></li></ol></li><li><span><a href="https://doc.rust-lang.org/rustc/profile-guided-optimization.html" tabindex="0"><strong aria-hidden="true">8.</strong> Profile-guided Optimization</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/instrument-coverage.html" tabindex="0"><strong aria-hidden="true">9.</strong> Instrumentation-based Code Coverage</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/linker-plugin-lto.html" tabindex="0"><strong aria-hidden="true">10.</strong> Linker-plugin-based LTO</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/check-cfg.html" tabindex="0"><strong aria-hidden="true">11.</strong> Checking Conditional Configurations</a></span><ol><li><span><a href="https://doc.rust-lang.org/rustc/check-cfg/cargo-specifics.html" tabindex="0"><strong aria-hidden="true">11.1.</strong> Cargo Specifics</a></span></li></ol></li><li><span><a href="https://doc.rust-lang.org/rustc/remap-source-paths.html" tabindex="0"><strong aria-hidden="true">12.</strong> Remap source paths</a></span></li><li><span><a href="https://doc.rust-lang.org/rustc/exploit-mitigations.html" tabindex="0"><strong aria-hidden="true">13.</strong> Exploit Miti
</nav>
<div id="mdbook-page-wrapper">
<div id="mdbook-content" class="page">
<main>
<h2 id="armv6k-nintendo-3ds"><a href="#armv6k-nintendo-3ds"><code>armv6k-nintendo-3ds</code></a></h2>
<p><strong>Tier: 3</strong></p>
<p>The Nintendo 3DS platform, which has an Armv6k processor, and its associated
operating system (<code>horizon</code>).</p>
<p>Rust support for this target is not affiliated with Nintendo, and is not derived
from nor used with any official Nintendo SDK.</p>
<h2 id="target-maintainers"><a href="#target-maintainers">Target maintainers</a></h2>
<p>This target is maintained by members of the <a href="https://github.com/rust3ds">@rust3ds</a>
organization:</p>
<p><a href="https://github.com/Meziu">@Meziu</a>
<a href="https://github.com/AzureMarker">@AzureMarker</a>
<a href="https://github.com/ian-h-chamberlain">@ian-h-chamberlain</a></p>
<h2 id="requirements"><a href="#requirements">Requirements</a></h2>
<p>This target is cross-compiled. Dynamic linking is not supported.</p>
<p><code>#![no_std]</code> crates can be built using <code>build-std</code> to build <code>core</code> and optionally
<code>alloc</code>, and either <code>panic_abort</code> or <code>panic_unwind</code>.</p>
<p><code>std</code> is partially supported, but mostly works. Some APIs are unimplemented
and will simply return an error, such as <code>std::process</code>. An allocator is provided
by default.</p>
<p>In order to support some APIs, binaries must be linked against <code>libc</code> written
for the target, using a linker for the target. These are provided by the
devkitARM toolchain. See
<a href="#cross-compilation-toolchains-and-c-code">Cross-compilation toolchains and C code</a>
for more details.</p>
<p>Additionally, some helper crates provide implementations of some <code>libc</code> functions
use by <code>std</code> that may otherwise be missing. These, or an alternate implementation
of the relevant functions, are required to use <code>std</code>:</p>
<ul>
<li><a href="https://github.com/rust3ds/pthread-3ds"><code>pthread-3ds</code></a> provides pthread APIs for <code>std::thread</code>.</li>
<li><a href="https://github.com/rust3ds/shim-3ds"><code>shim-3ds</code></a> fulfills some other missing libc APIs (e.g. <code>getrandom</code>).</li>
</ul>
<p>Binaries built for this target should be compatible with all variants of the
3DS (and 2DS) hardware and firmware, but testing is limited and some versions may
not work correctly.</p>
<p>This target generates binaries in the ELF format.</p>
<h2 id="building-the-target"><a href="#building-the-target">Building the target</a></h2>
<p>You can build Rust with support for the target by adding it to the <code>target</code>
list in <code>bootstrap.toml</code> and providing paths to the devkitARM toolchain.</p>
<pre><code><span>[build]</span>
<span>build-stage</span> = <span>1</span>
<span>target</span> = [<span>"armv6k-nintendo-3ds"</span>]
<span>[target.armv6k-nintendo-3ds]</span>
<span>cc</span> = <span>"/opt/devkitpro/devkitARM/bin/arm-none-eabi-gcc"</span>
<span>cxx</span> = <span>"/opt/devkitpro/devkitARM/bin/arm-none-eabi-g++"</span>
<span>ar</span> = <span>"/opt/devkitpro/devkitARM/bin/arm-none-eabi-ar"</span>
<span>ranlib</span> = <span>"/opt/devkitpro/devkitARM/bin/arm-none-eabi-ranlib"</span>
<span>linker</span> = <span>"/opt/devkitpro/devkitARM/bin/arm-none-eabi-gcc"</span>
</code></pre>
<p>Also, to build <code>compiler_builtins</code> for the target, export these flags before
building the Rust toolchain:</p>
<pre><code><span>export</span> CFLAGS_armv6k_nintendo_3ds=<span>"-mfloat-abi=hard -mtune=mpcore -mtp=soft -march=armv6k"</span>
</code></pre>
<h2 id="building-rust-programs"><a href="#building-rust-programs">Building Rust programs</a></h2>
<p>Rust does not yet ship pre-compiled artifacts for this target.</p>
<p>The recommended way to build binaries is by using the
<a href="https://github.com/rust3ds/cargo-3ds">cargo-3ds</a> tool, which uses <code>build-std</code>
and provides commands that work like the usual <code>cargo run</code>, <code>cargo build</code>, etc.
The <code>cargo 3ds new</code> will automatically set up a new project with the dependencies
needed to build a simple binary.</p>
<p>You can also build Rust with the target enabled (see
<a href="#building-the-target">Building the target</a> above).</p>
<p>As mentioned in <a href="#requirements">Requirements</a>, programs that use <code>std</code> must link
against both the devkitARM toolchain and libraries providing the <code>libc</code> APIs used
in <code>std</code>. There is a general-purpose utility crate for working with nonstandard
APIs provided by the OS: <a href="https://github.com/rust3ds/ctru-rs"><code>ctru-rs</code></a>.
Add it to Cargo.toml to use it in your program:</p>
<pre><code><span>[dependencies]</span>
<span>ctru-rs</span> = { git = <span>"https://github.com/rust3ds/ctru-rs.git"</span> }
</code></pre>
<p>Depending on <code>ctru-rs</code> ensures that all the necessary symbols are available at
link time.</p>
<h2 id="testing"><a href="#testing">Testing</a></h2>
<p>Binaries built for this target can be run in an emulator (most commonly
<a href="https://citra-emu.org/">Citra</a>), or sent to a device through
the use of a tool like devkitARMs <code>3dslink</code>. They may also simply be copied
to an SD card to be inserted in the device.</p>
<p>The <code>cargo-3ds</code> tool mentioned in <a href="#building-rust-programs">Building Rust programs</a>
supports the use of <code>3dslink</code> with <code>cargo 3ds run</code>. The default Rust test runner
is not supported, but
<a href="https://doc.rust-lang.org/unstable-book/language-features/custom-test-frameworks.html">custom test frameworks</a>
can be used with <code>cargo 3ds test</code> to run unit tests on a device.</p>
<p>The Rust test suite for <code>library/std</code> is not yet supported.</p>
<h2 id="cross-compilation-toolchains-and-c-code"><a href="#cross-compilation-toolchains-and-c-code">Cross-compilation toolchains and C code</a></h2>
<p>C code can be built for this target using the
<a href="https://devkitpro.org/wiki/Getting_Started">devkitARM toolchain</a>.
This toolchain provides <code>arm-none-eabi-gcc</code> as the linker used to link Rust
programs as well.</p>
<p>The toolchain also provides a <code>libc</code> implementation, which is required by <code>std</code>
for many of its APIs, and a helper library <code>libctru</code> which is used by several
of the helper crates listed in <a href="#requirements">Requirements</a>.
This toolchain does not, however, include all of the APIs expected by <code>std</code>,
and the remaining APIs are implemented by <code>pthread-3ds</code> and <code>linker-fix-3ds</code>.</p>
</main>
<nav aria-label="Page navigation">
<a rel="prev" href="https://doc.rust-lang.org/rustc/platform-support/armv7-unknown-linux-uclibceabihf.html" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<span><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"></path></svg></span>
</a>
<a rel="next prefetch" href="https://doc.rust-lang.org/rustc/platform-support/armv7-rtems-eabihf.html" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<span><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z"></path></svg></span>
</a>
</nav>
</div>
<nav aria-label="Page navigation">
<a rel="prev" href="https://doc.rust-lang.org/rustc/platform-support/armv7-unknown-linux-uclibceabihf.html" title="Previous chapter" aria-label="Previous chapter" aria-keyshortcuts="Left">
<span><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M41.4 233.4c-12.5 12.5-12.5 32.8 0 45.3l160 160c12.5 12.5 32.8 12.5 45.3 0s12.5-32.8 0-45.3L109.3 256 246.6 118.6c12.5-12.5 12.5-32.8 0-45.3s-32.8-12.5-45.3 0l-160 160z"></path></svg></span>
</a>
<a rel="next prefetch" href="https://doc.rust-lang.org/rustc/platform-support/armv7-rtems-eabihf.html" title="Next chapter" aria-label="Next chapter" aria-keyshortcuts="Right">
<span><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512"><path d="M278.6 233.4c12.5 12.5 12.5 32.8 0 45.3l-160 160c-12.5 12.5-32.8 12.5-45.3 0s-12.5-32.8 0-45.3L210.7 256 73.4 118.6c-12.5-12.5-12.5-32.8 0-45.3s32.8-12.5 45.3 0l160 160z"></path></svg></span>
</a>
</nav>
</div>
<template id="fa-eye"><span class="fa-svg"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512"><path d="M288 32c-80.8 0-145.5 36.8-192.6 80.6C48.6 156 17.3 208 2.5 243.7c-3.3 7.9-3.3 16.7 0 24.6C17.3 304 48.6 356 95.4 399.4C142.5 443.2 207.2 480 288 480s145.5-36.8 192.6-80.6c46.8-43.5 78.1-95.4 93-131.1c3.3-7.9 3.3-16.7 0-24.6c-14.9-35.7-46.2-87.7-93-131.1C433.5 68.8 368.8 32 288 32zM432 256c0 79.5-64.5 144-144 144s-144-64.5-144-144s64.5-144 144-144s144 64.5 144 144zM288 192c0 35.3-28.7 64-64 64c-11.5 0-22.3-3-31.6-8.4c-.2 2.8-.4 5.5-.4 8.4c0 53 43 96 96 96s96-43 96-96s-43-96-96-96c-2.8 0-5.6 .1-8.4 .4c5.3 9.3 8.4 20.1 8.4 31.6z"></path></svg></span></template>
<template id="fa-eye-slash"><span class="fa-svg"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512"><path d="M38.8 5.1C28.4-3.1 13.3-1.2 5.1 9.2S-1.2 34.7 9.2 42.9l592 464c10.4 8.2 25.5 6.3 33.7-4.1s6.3-25.5-4.1-33.7L525.6 386.7c39.6-40.6 66.4-86.1 79.9-118.4c3.3-7.9 3.3-16.7 0-24.6c-14.9-35.7-46.2-87.7-93-131.1C465.5 68.8 400.8 32 320 32c-68.2 0-125 26.3-169.3 60.8L38.8 5.1zM223.1 149.5C248.6 126.2 282.7 112 320 112c79.5 0 144 64.5 144 144c0 24.9-6.3 48.3-17.4 68.7L408 294.5c5.2-11.8 8-24.8 8-38.5c0-53-43-96-96-96c-2.8 0-5.6 .1-8.4 .4c5.3 9.3 8.4 20.1 8.4 31.6c0 10.2-2.4 19.8-6.6 28.3l-90.3-70.8zm223.1 298L373 389.9c-16.4 6.5-34.3 10.1-53 10.1c-79.5 0-144-64.5-144-144c0-6.9 .5-13.6 1.4-20.2L83.1 161.5C60.3 191.2 44 220.8 34.5 243.7c-3.3 7.9-3.3 16.7 0 24.6c14.9 35.7 46.2 87.7 93 131.1C174.5 443.2 239.2 480 320 480c47.8 0 89.9-12.9 126.2-32.5z"></path></svg></span></template>
<template id="fa-copy"><span class="fa-svg"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M502.6 70.63l-61.25-61.25C435.4 3.371 427.2 0 418.7 0H255.1c-35.35 0-64 28.66-64 64l.0195 256C192 355.4 220.7 384 256 384h192c35.2 0 64-28.8 64-64V93.25C512 84.77 508.6 76.63 502.6 70.63zM464 320c0 8.836-7.164 16-16 16H255.1c-8.838 0-16-7.164-16-16L239.1 64.13c0-8.836 7.164-16 16-16h128L384 96c0 17.67 14.33 32 32 32h47.1V320zM272 448c0 8.836-7.164 16-16 16H63.1c-8.838 0-16-7.164-16-16L47.98 192.1c0-8.836 7.164-16 16-16H160V128H63.99c-35.35 0-64 28.65-64 64l.0098 256C.002 483.3 28.66 512 64 512h192c35.2 0 64-28.8 64-64v-32h-47.1L272 448z"></path></svg></span></template>
<template id="fa-play"><span class="fa-svg"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 384 512"><path d="M73 39c-14.8-9.1-33.4-9.4-48.5-.9S0 62.6 0 80V432c0 17.4 9.4 33.4 24.5 41.9s33.7 8.1 48.5-.9L361 297c14.3-8.7 23-24.2 23-41s-8.7-32.2-23-41L73 39z"></path></svg></span></template>
<template id="fa-clock-rotate-left"><span class="fa-svg"><svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512"><path d="M75 75L41 41C25.9 25.9 0 36.6 0 57.9V168c0 13.3 10.7 24 24 24H134.1c21.4 0 32.1-25.9 17-41l-30.8-30.8C155 85.5 203 64 256 64c106 0 192 86 192 192s-86 192-192 192c-40.8 0-78.6-12.7-109.7-34.4c-14.5-10.1-34.4-6.6-44.6 7.9s-6.6 34.4 7.9 44.6C151.2 495 201.7 512 256 512c141.4 0 256-114.6 256-256S397.4 0 256 0C185.3 0 121.3 28.7 75 75zm181 53c-13.3 0-24 10.7-24 24V256c0 6.4 2.5 12.5 7 17l72 72c9.4 9.4 24.6 9.4 33.9 0s9.4-24.6 0-33.9l-65-65V152c0-13.3-10.7-24-24-24z"></path></svg></span></template>
</div>
</div>