『Rust』Rust运行环境搭建

server/2025/3/15 13:35:07/

文章目录

  • rust编译工具rustup
  • Visual Studio + VS Code
  • 测试编译
    • 手动编译
    • VSCode编译配置
  • 参考

rustrustup_1">rust编译工具rustup

https://www.rust-lang.org/zh-CN/tools/install

换源

RUSTUP_DIST_SERVER https://rsproxy.cn
RUSTUP_UPDATE_ROOT https://rsproxy.cn

修改rustup和cargo的安装路径

RUSTUP_HOME D:\rust\.rustup
CARGO_HOME D:\rust\.cargo

运行rustup-init.exe

1) Quick install via the Visual Studio Community installer(free for individuals, academic uses, and open source).
>11) Proceed with selected options (default - just press enter)
>1

%CARGO_HOME%\bin添加到PATH

%CARGO_HOME%\bin

安装后运行验证:

rustc -V
rustup -V
cargo -V
rustup show 
C:\Users\Ho1aAs>rustc -V
rustc 1.85.0 (4d91de4e4 2025-02-17)C:\Users\Ho1aAs>rustup -V
rustup 1.28.1 (f9edccde0 2025-03-05)
info: This is the version for the rustup toolchain manager, not the rustc compiler.
info: The currently active `rustc` version is `rustc 1.85.0 (4d91de4e4 2025-02-17)`C:\Users\Ho1aAs>cargo -V
cargo 1.85.0 (d73d2caf9 2024-12-31)C:\Users\Ho1aAs>rustup show
Default host: x86_64-pc-windows-msvc
rustup home:  D:\rust\.rustupinstalled toolchains
--------------------
stable-x86_64-pc-windows-msvc (active, default)active toolchain
----------------
name: stable-x86_64-pc-windows-msvc
active because: it's the default toolchain
installed targets:x86_64-pc-windows-msvc

Visual Studio + VS Code

Visual Studio 2022 + Visual Studio Code 1.98.1

vscode安装扩展:Chinese + rust-analyzer + Native Debug + C/C++

在这里插入图片描述

(安装时可选)添加空白处右键、文件夹右键、文件右键以VSCode打开

# 1.reg
Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\*\shell\VSCode]
@="Open with Code"
"Icon"="D:\\Microsoft VS Code\\Code.exe"[HKEY_CLASSES_ROOT\*\shell\VSCode\command]
@="\"D:\\Microsoft VS Code\\Code.exe\" \"%1\""[HKEY_CLASSES_ROOT\Directory\shell\VSCode]
@="Open with Code"
"Icon"="D:\\Microsoft VS Code\\Code.exe"[HKEY_CLASSES_ROOT\Directory\shell\VSCode\command]
@="\"D:\\Microsoft VS Code\\Code.exe\" \"%V\""[HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode]
@="Open with Code"
"Icon"="D:\\Microsoft VS Code\\Code.exe"[HKEY_CLASSES_ROOT\Directory\Background\shell\VSCode\command]
@="\"D:\\Microsoft VS Code\\Code.exe\" \"%V\""

测试编译

手动编译

新建~\Desktop\rust用vscode打开,cargo新建项目:cargo new rust-test

在这里插入图片描述

cd进项目,build和run即可编译为exe

cd rust-test
cargo build
cargo run# || rust-test.exe

在这里插入图片描述

VSCode编译配置

项目路径新建.vscode,在其中新建tasks.json和launch.json

// tasks.json
{ "version":"2.0.0", "tasks":[ { "label":"build", "type":"shell", "command":"cargo", "args":["build"] } ] 
}

launch.json需要微调,主要是Console标签那个位置

// launch.json
{ "version":"0.2.0", "configurations":[ { "name":"Run Rust", "preLaunchTask":"build", "type":"cppvsdbg", "request":"launch", "program":"${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe", "args":[], "stopAtEntry":false, "cwd":"${workspaceFolder}", "environment":[], "console": "integratedTerminal",}]
}

打断点调试

在这里插入图片描述

参考

https://www.runoob.com/rust/rust-setup.html

https://www.runoob.com/rust/cargo-tutorial.html

欢迎关注我的CSDN博客 :@Ho1aAs
版权属于:Ho1aAs
本文链接:https://ho1aas.blog.csdn.net/article/details/146232471
版权声明:本文为原创,转载时须注明出处及本声明


http://www.ppmy.cn/server/175171.html

相关文章

sklearn中生成完整标签数据集、半监督数据集,多标签数据集的模拟方法

sklearn.datasets 是 scikit-learn 库中的一个模块,它提供了许多用于生成样本数据集和加载真实世界数据集的工具。以下是一些常用的函数和它们的用法: 生成有监督数据集 make_classification(n_samples100, n_features20, ..., random_stateNone) 生成一…

【大模型学习】第十九章 什么是迁移学习

目录 1. 迁移学习的起源背景 1.1 传统机器学习的问题 1.2 迁移学习的提出背景 2. 什么是迁移学习 2.1 迁移学习的定义 2.2 生活实例解释 3. 技术要点与原理 3.1 迁移学习方法分类 3.1.1 基于特征的迁移学习(Feature-based Transfer) 案例说明 代码示例 3.1.2 基于…

程序化广告行业(15/89):TD、流量供应方与流量方服务解析

程序化广告行业(15/89):TD、流量供应方与流量方服务解析 大家好!一直以来,我都对程序化广告行业充满兴趣,在深入学习的过程中积累了不少知识。今天就想把这些知识分享出来,和大家一起学习进步&…

HEC-HMS水文模型技术应用

HEC-HMS是美国陆军工程兵团水文工程中心开发的一款水文模型。HMS能够模拟各种类型的降雨事件对流域水文,河道水动力以及水利设施的影响,在世界范围内得到了广泛的应用。它有着完善的前后处理软件,能有效减轻建模的负担;能够与HEC开…

mysql select distinct 和 group by 哪个效率高

在有索引的情况下,SELECT DISTINCT和GROUP BY的效率相同;在没有索引的情况下,SELECT DISTINCT的效率高于GROUP BY‌。这是因为SELECT DISTINCT和GROUP BY都会进行分组操作,但GROUP BY可能会进行排序,触发filesort&…

使用PHP进行自动化测试:工具与策略的全面分析

使用PHP进行自动化测试:工具与策略的全面分析 引言 随着软件开发的复杂性不断增加,自动化测试已成为确保软件质量的关键环节。PHP作为一种广泛使用的服务器端脚本语言,拥有丰富的生态系统和工具支持,使其成为自动化测试的理想选…

【C++】类和对象

类的基本思想是数据抽象( d a t a a b s t r a c t i o n data\ abstraction data abstraction)和封装( e n c a p s u l a t i o n encapsulation encapsulation)。数据抽象是一种依赖于接口( i n t e r f a c e inte…

Day 64 卡玛笔记

这是基于代码随想录的每日打卡 参加科学大会(第六期模拟笔试) 题目描述 ​ 小明是一位科学家,他需要参加一场重要的国际科学大会,以展示自己的最新研究成果。 ​ 小明的起点是第一个车站,终点是最后一个车站。然…