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
相关推荐
代码or搬砖15 分钟前
Java集合-Set讲解
java·开发语言
艾上编程16 分钟前
第三章——爬虫工具场景之Python爬虫实战:学术文献摘要爬取,助力科研高效进行
开发语言·爬虫·python
d111111111d18 分钟前
在STM32函数指针是什么,怎么使用还有典型应用场景。
笔记·stm32·单片机·嵌入式硬件·学习·算法
明洞日记23 分钟前
【数据结构手册008】STL容器完全参考指南
开发语言·数据结构·c++
jllllyuz1 小时前
matlab使用B样条进行曲线曲面拟合
开发语言·matlab
ku_code_ku2 小时前
python bert_score使用本地模型的方法
开发语言·python·bert
嗷嗷哦润橘_2 小时前
AI Agent学习:MetaGPT之我的工作
人工智能·学习·flask
小马哥编程2 小时前
【软考架构】滑动窗口限流算法的原理是什么?
java·开发语言·架构
云栖梦泽2 小时前
鸿蒙数据持久化实战:构建本地存储与云同步系统
开发语言·鸿蒙系统
知识分享小能手2 小时前
CentOS Stream 9入门学习教程,从入门到精通,Linux日志分析工具及应用 —语法详解与实战案例(17)
linux·学习·centos