之前一时兴起,在Win下尝试安装,要求编译环境是vs Studio那一套,直接把我吓退。据说Linux下非常简单,今天一试确实SoEasy。
安装: curl https://sh.rustup.rs -sSf | sh
添加环境变量: source $HOME/.cargo/env
查看版本: rustc -V cargo -V
如果提示缺少cc编译器:sudo apt install build-essential
更新:rustup update
卸载: rustup self uninstall
来个标准HelloWorld
fn main() {
// Statements here are executed when the compiled binary is called.
// Print text to the console.
println!("Hello World!");
}
编译一下: rustc hello_world.rs
原编译4.1MB,通过UPX后0.995MB
用Cargo构建和运行项目:
cargo new hello_argo
cargo build
cargo run
cargo check
cargo build –release