Skip to content

Instantly share code, notes, and snippets.

@mcpherrinm
Last active November 24, 2022 19:21
Show Gist options
  • Save mcpherrinm/d5bdccc44feb40e4d11f to your computer and use it in GitHub Desktop.
Save mcpherrinm/d5bdccc44feb40e4d11f to your computer and use it in GitHub Desktop.
Hello World in Rust without the runtime (libcore and libc only)
#![no_std]
extern crate core;
use core::option::{None, Some};
use core::iter::Iterator;
use core::str::StrSlice;
#[lang="stack_exhausted"]
pub extern "C" fn rust_stack_exhausted() {
unsafe { core::intrinsics::abort() }
}
#[lang="begin_unwind"] pub fn begin_unwind(){ }
#[lang="eh_personality"] pub fn eh_personality() {}
#[link(name="c")]
#[allow(ctypes)]
extern { fn putchar(_:int)->int; }
#[start]
fn start(_:int, _:**u8)->int {
for c in "Hello, World!\n".bytes() {
unsafe {putchar(c as int); }
}
0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment