工具链
安装
shell
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
确认
shell
ethan@G5000:~$ rustc --version
rustc 1.89.0 (29483883e 2025-08-04)
创建工程
创建
shell
cargo new demo
上述,demo为工程名称。
调试
shell
cargo run
静态编译
目前计划使用rust编写一些小工具。考虑使用静态编译,已方便使用。
配置工程
添加文件.cargo/config.toml
shell
[target.x86_64-unknown-linux-musl]
linker = "x86_64-linux-musl-gcc"
安装依赖
shell
sudo apt-get install musl-tools
rustup target add x86_64-unknown-linux-musl
cargo build --release --target x86_64-unknown-linux-musl
确认
shell
ethan@G5000:~/demo$ ldd ./target/x86_64-unknown-linux-musl/release/demo
statically linked
docker
shell
# 使用 muslrust 镜像
docker run --rm -it \
-v "$(pwd)":/app \
-w /app \
clux/muslrust:stable \
cargo build --release
交叉编译
shell
rustup target add x86_64-pc-windows-gnu
cargo build --release --target x86_64-pc-windows-gnu