当前位置: 首页 > news >正文

『Rust』Rust运行环境搭建

文章目录

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

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).
>1

1) 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\.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打开

# 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
版权声明:本文为原创,转载时须注明出处及本声明

相关文章:

  • 【08】单片机编程核心技巧:变量命名规范
  • 鸿蒙应用开发—ZDbUtil高效使用数据库
  • 线性回归中的最小二乘法:直接法与梯度下降的比较
  • Qt不同窗口类的控件信号和槽绑定
  • 数字化工厂人员定位系统方案之高危场景人员聚集预警系统架构设计(二)
  • Redis大Key问题全解析:从原理到实战的深度解决方案
  • MyBatis一对多查询方式
  • 什么是AI?AI能对我们生活产生哪些影响?
  • 基于Python的端口扫描器和目录扫描工具实现方案,结合机器学习进行指纹识别
  • Kubernetes学习笔记-IDEA开发工具本地调试
  • 离线服务器ollama新增qwen2:0.5b模型
  • 从零手工撸写个人工神经元网络(解决异或问题)Python+c++结构化
  • 江科大51单片机笔记【14】LCD1602(上)
  • 操作系统知识点27
  • 双 Token 无感刷新机制在前后端分离架构中实现
  • 【计量地理学】实验三 地理数据的基本统计分析
  • Unity使用自定义类的List在Inspector面板上显示异常(2021.3.4)
  • Appium等待机制--强制等待、隐式等待、显式等待
  • 工具(十二):Java导出MySQL数据库表结构信息到excel
  • 使用DeepSeek完成一个简单嵌入式开发
  • 民营医院建设网站/北京百度seo服务
  • 最流行的网站开发语言/网址缩短
  • 在工商局网站怎么做清算/常州网站制作维护
  • 网站开发工具可视化/关键词优化排名首页
  • 网站建设会员管理系统方案/站长统计官网
  • 用dw做音乐网站模板/seo搜索排名