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
相关推荐
无限的鲜花3 小时前
反射(原创推荐)
java·开发语言
yongche_shi3 小时前
ragas官方文档中文版(五十)
开发语言·python·ai·ragas·如何评估和改进 rag 应用
一路向北he3 小时前
字节钢铁军团--“提供情境,而非控制”
java·开发语言·前端
Waay4 小时前
面试口述版:个人对 Prometheus 完整理解
运维·学习·云原生·面试·职场和发展·kubernetes·prometheus
AI行业学习5 小时前
Notepad++ 官方下载 + 完整安装 + 全套优化配置(2026最新)
开发语言·人工智能·python·前端框架·html·notepad++
大圣编程6 小时前
Python中continue语句的用法是什么?
开发语言·前端·python
upgrador6 小时前
基础知识:C++ STL构造函数的左闭右开惯例及其实现原理
开发语言·c++
一楼的猫7 小时前
AI写作合规技术方案:平台检测机制分析与规避策略
人工智能·学习·机器学习·ai写作
yoothey7 小时前
报废审批流规则引擎设计——责任链模式完整实现
linux·开发语言·bash
geovindu7 小时前
python: Functional Options Pattern
开发语言·后端·python·设计模式·惯用法模式·函数式选项模式