An example of “Hello World” with raw Rust:
#![feature(no_core,lang_items,start)]
#![no_core]
#![no_std]
#![no_main]
#[lang = "sized"]
pub trait Sized {}
#[lang = "copy"]
pub trait Copy {}
#[no_mangle]
#[start]
pub extern fn _start ()
{
loop {}
}
You can compile it I think with:
rustc +nightly --crate-type bin -C link-arg=-nostartfiles test.rs
In such book you could obviously use core and std but this is as minimal as it can get (almost) ;-)
@jarkko Even though my experience with Rustlang is minimal, I can 100% agree with this. Overall the usage of Cargo in documentation examples gives me NPM vibes even though Rustlang should appeal to those working with low-level systems (C, Cpp).
I really hope gcc-rs and the standardization process changes how these books introduce developers to Rustlang.
@jarkko I have bounced off rust several times because cargo is bloated unusable npm-rot. I see glimpses of a decent language under there, but it is basically undocumented as everything assumes you want the webdev experience.
@jarkko
Some people came to me to know how to learn programming and I told them to starts with logic, algorithmic and data structures then choose a programming language that resonates with them. I don't understand why people want to learn using to code by directly learning a language from books like the one you're describing.
What they actually end up learning is not how to program but just how to use a toolchain/framework ; this knowledge is perishable and isn't portable and leads to frustration.
@jarkko you're probably trolling but I'll bite:
Most of the time "Linux programming" implies some kind of libc because it's explicitly part of the operating system you're programming for (vs 'just the kernel', that's what the GNU+Linux meme is about). This doesn't make your program "less Rust".
If you rather talk to the kernel directly you would use the x86_64-unknown-none target. There's a blogpost I wrote in 2023 on how to do this step by step: https://vulns.xyz/2023/03/linux-executable-from-scratch-with-x86_64-unknown-none-rust/
@jarkko Spoiler: I do use cargo in this blogpost.
Turns out having a reasonable build system doesn't stop one from in-depth exploring the Linux binary/assembly interface.
Also the code works on stable Rust, no nightly necessary. ✨
@jarkko The "raw Rust" code you posted is lowkey kinda ass and you're (most likely) trying to butcher `x86_64-unknown-linux-gnu` into being libc-free (which explicitly targets glibc).
Check the output of `rustc --print cfg` vs `rustc --target x86_64-unknown-none --print cfg`.