rust学习之开发环境

工具链

安装

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
相关推荐
周末也要写八哥11 小时前
Golang语言与Rust语言的对比
开发语言·后端·golang
楼田莉子11 小时前
Linux网络:数据链路层
linux·服务器·开发语言·网络·c++·后端
念恒1230611 小时前
Python(列表入门)
python·学习
不甘先生11 小时前
Go 四层架构实战:Handler + Service + Repository + Entity(清晰、可控、可演进)
开发语言·架构·golang
skilllite作者11 小时前
Warp 终端效能与交互体验全景展示
人工智能·后端·架构·rust
Yang-Never11 小时前
Git -> Git Worktree 工作树
android·开发语言·git·android studio
riNt PTIP11 小时前
GO 快速升级Go版本
开发语言·redis·golang
xingpanvip11 小时前
星盘接口开发文档:日运语料接口指南
android·开发语言·前端·css·php·lua
AI进化营-智能译站11 小时前
ROS2 C++开发系列01:在ROS2上编写第一个C++ hello word
开发语言·c++·ai·word
我才是一卓11 小时前
2026 Python 入门教程,结合 vscode 和 miniforge/miniconda
开发语言·vscode·python