『Rust』Rust运行环境搭建

文章目录

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

bash 复制代码
1) Quick install via the Visual Studio Community installer
   (free for individuals, academic uses, and open source).
>1

1) Proceed with selected options (default - just press enter)
>1

%CARGO_HOME%\bin添加到PATH

复制代码
%CARGO_HOME%\bin

安装后运行验证:

bash 复制代码
rustc -V
rustup -V
cargo -V
rustup show 
bash 复制代码
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\.rustup

installed 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打开

reg 复制代码
# 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

bash 复制代码
cd rust-test
cargo build
cargo run

# || rust-test.exe

VSCode编译配置

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

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

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

json 复制代码
// 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

版权声明:本文为原创,转载时须注明出处及本声明

相关推荐
神仙别闹23 分钟前
基于C#+MySQL实现(WinForm)企业设备使用信息管理系统
开发语言·mysql·c#
czhaii34 分钟前
PLC脉冲位置 单片机跟踪读取记录显示
开发语言·c#
alden_ygq1 小时前
当java进程内存使用超过jvm设置大小会发生什么?
java·开发语言·jvm
蜗牛沐雨1 小时前
Rust 中的 `PartialEq` 和 `Eq`:深入解析与应用
开发语言·后端·rust
Python私教1 小时前
Rust快速入门:从零到实战指南
开发语言·后端·rust
Mcworld8572 小时前
整数分解JAVA
java·开发语言
请你喝好果汁6412 小时前
python_竞态条件
开发语言·python
正在走向自律2 小时前
Python 数据分析与可视化:开启数据洞察之旅(5/10)
开发语言·人工智能·python·数据挖掘·数据分析
dudly2 小时前
Python 字典键 “三变一” 之谜
开发语言·python
秋野酱2 小时前
基于javaweb的SpringBoot爱游旅行平台设计和实现(源码+文档+部署讲解)
java·spring boot·后端