Win32: no_std, no_main, no libc?

It might be worth reading A freestanding Rust binary.

The minimal example from that link goes something like this. First add panic="abort" to your Cargo.toml

[package]
name = "nostd"
version = "0.1.0"
authors = ["THE AUTHOR"]
edition = "2018"

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

Then your main should look like this:

#![no_std] // don't link the Rust standard library
#![no_main] // disable all Rust-level entry points

use core::panic::PanicInfo;

#[no_mangle] // don't mangle the name of this function
pub extern "C" fn _start() -> ! {
    // this function is the entry point, since the linker looks for a function
    // named `_start` by default
    loop {}
}

/// This function is called on panic.
#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
    loop {}
}

And you'd compile it using rustc more directly.

cargo rustc -- -C link-args="/ENTRY:_start /SUBSYSTEM:console"

And run it using:

.\target\debug\nostd.exe
1 Like