Windows:
Add to enverment vars:
CARGO_HOME:F:\.cargo
RUSTUP_HOME:F:\.rustup
Add %CARGO_HOME%\bin to PATH
Download rustup-init.exe from https://www.rust-lang.org/zh-CN/tools/install,
copy rustup-init.exe to %CARGO_HOME%\bin\rustup.exe
设置镜像源:
Rust配置镜像源
如果需要使用代理,可在 %CARGO_HOME%/config 中加入配置:
[http]
proxy = "127.0.0.1:10809"
timeout = 60
如果项目需要使用私有化部署的git源:
[net]
git-fetch-with-cli = true
Linux:
export CARGO_HOME=/opt/cargo/
export RUSTUP_HOME=/opt/rustup/
vi ~/.bashrc
Add to last line:
export CARGO_HOME=/opt/cargo/
export RUSTUP_HOME=/opt/rustup/
curl https://sh.rustup.rs -sSf | sh
chmod -R 777 /opt/cargo/
chmod -R 777 /opt/rustup/
vi ~/.bashrc
Add to last line:
. "/opt/cargo/env"
rustc -V
设置镜像源:
Rust配置镜像源
rustup toolchain install stable-x86_64-pc-windows-msvc
rustup component add rust-analysis --toolchain stable-x86_64-pc-windows-msvc
rustup component add rust-src --toolchain stable-x86_64-pc-windows-msvc
rustup component add rls --toolchain stable-x86_64-pc-windows-msvc
rustup toolchain install stable-i686-pc-windows-msvc
rustup component add rust-analysis --toolchain stable-i686-pc-windows-msvc
rustup component add rust-src --toolchain stable-i686-pc-windows-msvc
rustup component add rls --toolchain stable-i686-pc-windows-msvc
rustup toolchain install stable-x86_64-pc-windows-gnu
rustup component add rust-analysis --toolchain stable-x86_64-pc-windows-gnu
rustup component add rust-src --toolchain stable-x86_64-pc-windows-gnu
rustup component add rls --toolchain stable-x86_64-pc-windows-gnu
rustup toolchain install stable-i686-pc-windows-gnu
rustup component add rust-analysis --toolchain stable-i686-pc-windows-gnu
rustup component add rust-src --toolchain stable-i686-pc-windows-gnu
rustup component add rls --toolchain stable-i686-pc-windows-gnu
rustup show
1:Use VS Code
Install VSCodeUserSetup-x64-1.63.2.exe, run VScode, extension -> Install from VSIX:
codelldb-x86_64-windows_1.6.10.vsix https://github.com/vadimcn/vscode-lldb/releases
rust-analyzer-win32-x64_0.2.867_2021-12-20.vsix https://github.com/rust-analyzer/rust-analyzer/releases
bungcip.better-toml-0.3.2.vsix https://marketplace.visualstudio.com/items?itemName=bungcip.better-toml
vscode-language-pack-zh-hans-v1.63.3.vsix https://github.com/microsoft/vscode-loc/releases
grimmer.vscode-back-forward-button-0.1.6.vsix https://marketplace.visualstudio.com/items?itemName=grimmer.vscode-back-forward-button
Or install blow extensions online:
rust-analyzer
CodeLLDB
Better TOML
Chinese Language Pack for Visual Studio Code
Back and Forward buttons
Tips: lldb debugger better than msvc debugger and gdb
Win7可用的lldb最高版本为1.6.7(后续版本基于Python3.9,不支持win7)
运行 - 启动调试,弹出警告框,点击确定,再点击YES,CodeLLDB会自动创建launch.json
打开左侧debug tab,选择对应的运行配置,即可开始调试
注意:
如果使用msvc toolchain + VS2015与CodeLLDB有冲突,会导致报错:
Debug adapter exit code=3221225620, signal=null.
解决方法:
1.使用gnu tool chain
or
2.Rename C:\Program Files (x86)\Microsoft Visual Studio 14.0 to:
C:\Program Files (x86)\Microsoft Visual Studio 14.0_bak
如果是使用gdb和msvc debugger:
Terminal - Configure Tasks - rust: cargo build
Run - Start Debugging - C++ (Windows)
This should create and open launch.json, edit:
"preLaunchTask": "rust: cargo build",
"program": "${workspaceRoot}/target/debug/${workspaceFolderBasename}.exe",
"externalConsole": true
If use MinGW, add:"miDebuggerPath": "D:/Qt/Qt5.14.2/Tools/mingw730_64/bin/gdb.exe",
解决VsCode终端中文乱码:
打开-首选项-设置,搜索框中搜 setting.json,编辑json文件:
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": ["-NoExit", "chcp 65001"]
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": ["/K", "chcp 65001"],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
}
}
2:Use CLion
rustup toolchain install stable-x86_64-pc-windows-gnu
rustup default stable-x86_64-pc-windows-gnu
rustup show
Download CLion-2020.1.2.exe, intellij-toml-0.2.124.40-201.zip, intellij-rust-0.2.125.3191-201.zip
Install CLion and plugins
If direct launch CLion, error info will show in Setting - Languages - Rust - Standard Library:(Download via rustup),
you need open VSCode, then will display same message - "Rust Src", click install
CLion debug Rust exe only support MinGW64, install and set Settings - Build - Toolchains - MinGW - Environment: D:\Qt\Qt5.14.2\Tools\mingw730_64
You can start debugging