Rust Setup
Installation
bashcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Updating Rust Version
bashrustup update
Hello World
https://rust-lang.org/learn/get-started/
bashcargo new hello # hello/ # .gitignore # Cargo.toml # src/ # main.rs
Cargo.toml
toml[package] name = "hello" version = "0.1.0" edition = "2024" [dependencies]
main.rs
rustfn main() { println!("Hello, world!"); }
Build and run
bashcargo build # Compiling hello v0.1.0 (/home/mike/Work/science/hello) # Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.68s cargo run # Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.03s # Running `target/debug/hello` # Hello, world! ./target/debug/hello # Hello, world! cargo build -r cargo build --release # Compiling hello v0.1.0 (/home/mike/Work/science/hello) # Finished `release` profile [optimized] target(s) in 0.16s cargo run -r cargo run --release # Finished `release` profile [optimized] target(s) in 0.01s # Running `target/release/hello` # Hello, world! ./target/release/hello # Hello, world! find . -name 'hello' -print0 | xargs -0 ls -lhS # 3.8M ./target/debug/hello # 439K ./target/release/hello
Generating a smaller binary
Cargo.toml
toml[package] name = "hello" version = "0.1.0" edition = "2024" [dependencies] [profile.release] opt-level = "z" # Optimize for size strip = true # Strip symbols lto = true # Link-time optimizations codegen-units = 1 # Certain optimizations only work if parallel code generation is disabled panic = "abort" # Don't generate helpful backtraces on panic!()
More here: https://github.com/johnthagen/min-sized-rust