Rust Bare Bones: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
No edit summary
m Bot: Replace deprecated source tag with syntaxhighlight
Line 55:
First, you must prepare your source. In general, rust tries to avoid command line flags in favour of in-source changes. As such, there is not Cargo or Rust flag to disable the standard library and add a custom panic handler. The below source takes care of that:
 
<sourcesyntaxhighlight lang="c">
#![no_std]
 
Line 67:
loop {}
}
</syntaxhighlight>
</source>
 
The above code tells the compiler to not include the Rust standard library (the core library is kept), not to mangle the _start symbol (Rust uses name mangling by default), and to use the panic() function as the panic handler. This approach by the Rust team generally keeps your rustc invocations simpler and easier to debug if anything goes wrong.
Line 73:
Another thing to keep in mind is that Rust uses stack unwinding by default, however, this is dependent on an underlying OS, which we obviously don't have (hey, you're here for a reason). To disable stack unwinding and just abort on panic (after the panic handler is called, of course), modify your Cargo.toml:
 
<sourcesyntaxhighlight lang="c">
[profile.dev]
panic = "abort"
Line 79:
[profile.release]
panic = "abort"
</syntaxhighlight>
</source>
 
Run cargo build to build your kernel, and do whatever you wish with the resulting ELF binary (look at your bootloaders instructions on how to build a bootable image).