This shows how to create a tiny "Hello, world!" binary in Rust. On my system (macOS), the resulting binary size is 8432 bytes, which is the same as when compiling the following C program with gcc -Os -o main main.c
:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
}
The goal here is to stay as close as possible to the C "Hello, world!" program above. However it's possible to get even smaller binaries, as documented in this post.
Look into the official Rust documentation for additional information about creating Rust executables without the standard library.
$ cargo +nightly build --release
$ ./target/release/tiny-hello-rs
Hello, world!
$ wc -c ./target/release/tiny-hello-rs
8432 ./target/release/tiny-hello-rs