rust 开发调试环境搭建vscode

linux

rust install

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

vscode install

https://code.visualstudio.com/download

安装插件

rust-analyzer

这个插件比rust要更好用一些
https://rust-analyzer.github.io/

CodeLLDB

https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb

windows

安装c/c++ 编译工具

如果不安装,后面在编译时,会报错说”link.exe”无法找到

https://visualstudio.microsoft.com/downloads/#other

All Downloads ->Build Tools for Visual Studio 2019->download 下载安装包

运行安装包打开的visual studio 安装工具中选择 c++ 生成工具完成安装

rust install

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

vscode install

https://code.visualstudio.com/download

安装插件

rust-analyzer

首先从源码安装rust-analyzer

$ rustup component add rust-src

# clone the repo
$ git clone https://github.com/rust-analyzer/rust-analyzer && cd rust-analyzer

# install both the language server and VS Code extension
$ cargo xtask install

或者下载二进制文件后在vscode中配置下路径
{ “rust-analyzer.server.path”: “~/.local/bin/rust-analyzer-linux” }

这个插件比rust要更好用一些
https://rust-analyzer.github.io/

C/C++

https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools

Configure VS Code

debug

Click Debug -> Add Configuration

If you’re on Windows then select C++ (Windows)

If you’re on Mac or Linux then select LLDB: Custom Launch

This should create and open launch.json. You’ll have to manually change the executable name under “program”.

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceRoot}/target/debug/foo.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "externalConsole": true
        },
        {
            "name": "(OSX) Launch",
            "type": "lldb",
            "request": "launch",
            "program": "${workspaceRoot}/target/debug/foo",
            "args": [],
            "cwd": "${workspaceRoot}",
        }
    ]
}

breakpoint

默认rust的文件无法打断点,需要使能下面的配置

File -> Preferences -> Settings 设置 “debug.showInlineBreakpointCandidates”: true

参考

https://www.forrestthewoods.com/blog/how-to-debug-rust-with-visual-studio-code/
https://code.visualstudio.com/docs/cpp/config-msvc
https://skyao.io/learning-rust/installation/windows.html
https://rust-analyzer.github.io/manual.html#installation

你可能感兴趣的:(rust)