1,rust编译环境安装
在联网环境下,建议使用rustup-init.exe程序安装(本文使用的改模式)
选择1“默认"进行安装,默认安装x86_64-pc-windows-msvc
在安装完成后,后续为了配置gbd调试,也安装上x86_64-pc-windows-gnu
命令如下:
rustup default stable-x86_64-pc-windows-gnu
rustup toolchain install stable-x86_64-pc-windows-gnu
2,vs code环境配置
第一步:先安装vs code,本文下载最新的版本VSCodeUserSetup-x64-1.84.2.exe
第二步:安装完成后,下载相应的插件
c/c++插件必须要安装,不然在配置调试运行时会找不到对应的(cppvsdbg)和(cppdbg)
其他比较重要的插件如: rust-analyzer,Rust syntax,Native debug;这些自己看着装
3,配置运行rust程序
命令行进入自己的rust目录,然后生成第一个rust程序:
cd d:\rust(路径依据自己工程目录来)
cargo new learn
cargo build
在vs code中配置运行环境:
首先构建配置文件配置:
我们选择rust: cargo build,这个时候会让我们配置tasks.json配置文件,我们配置内容如下:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "cargo",
"args": ["build"]
}
]
}
接着我们配置运行环境:
我们在运行调试中,打开launch.json配置文件。
配置文件中我们配置两个选项:C/C++:(Windows)启动和C/C++:(gdb)启动
具体配置信息如下:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) 启动",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "/path/to/gdb",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "将反汇编风格设置为 Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"type": "cppvsdbg",
"preLaunchTask": "build",
"request": "launch",
"name": "windows run",
"program": "${workspaceFolder}/target/debug/${workspaceFolderBasename}.exe",
"args": [],
"cwd": "${workspaceRoot}",
"stopAtEntry": false,
"environment": [],
"externalConsole": false
}
]
}
至此,vs code的rust运行环境windows配置完成,我们运行下程序,结果如图: