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
相关推荐
超梦dasgg1 分钟前
详细讲解:WebMvcConfigurer 接口
java·开发语言·spring
nashane4 分钟前
HarmonyOS 6学习:文件打开方式应用重复的根治方案与最佳实践
学习·华为·harmonyos
解局易否结局6 分钟前
从零上手 ops-transformer:一个有清晰路径感的学习计划
深度学习·学习·transformer
阿里嘎多学长11 分钟前
2026-05-22 GitHub 热点项目精选
开发语言·程序员·github·代码托管
JAVA社区11 分钟前
Java进阶全套教程(三)—— Spring框架核心精讲
java·开发语言·spring·面试·职场和发展·mybatis
jzlhll12324 分钟前
Kotlin 协程高级用法之 NonCancellable
android·开发语言·kotlin
结衣结衣.33 分钟前
走进机器学习:新手必看的完整入门指南
人工智能·python·学习·机器学习
我是唐青枫38 分钟前
C#.NET YARP + OpenTelemetry:网关链路追踪实战
开发语言·c#·.net
芯芯点灯40 分钟前
gd32f303烧录提示Flash Timeout. Reset the Target and try it again.;
开发语言·前端·javascript