🦀
Tauri(Rust)をVsCode上でステップ実行でデバッグする
はじめに
Tauri上のRustをVsCodeでステップ実行できるようにする設定方法について解説します。
ちなみに自分のエディターはCursorで、こちらでも問題なく動作します。
VsCode上の設定
デバッグ設定ファイルを作成します。
.vscode/launch.json
{
// 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": [
{
"type": "lldb",
"request": "launch",
"name": "Tauri Development Debug",
"cargo": {
"args": [
"build",
"--manifest-path=./src-tauri/Cargo.toml",
"--no-default-features"
]
},
// task for the `beforeDevCommand` if used, must be configured in `.vscode/tasks.json`
"preLaunchTask": "ui:dev"
},
{
"type": "lldb",
"request": "launch",
"name": "Tauri Production Debug",
"cargo": {
"args": ["build", "--release", "--manifest-path=./src-tauri/Cargo.toml"]
},
// task for the `beforeBuildCommand` if used, must be configured in `.vscode/tasks.json`
"preLaunchTask": "ui:build"
}
]
}
以下のタスクファイルを作成します。
公式のサンプルではcommandはyarnを使っていますが、自分はpnpmを使っているので適宜しているパッケージ管理ツールに置き換えてください。
.vscode/tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "ui:dev",
"type": "shell",
// `dev` keeps running in the background
// ideally you should also configure a `problemMatcher`
// see https://code.visualstudio.com/docs/editor/tasks#_can-a-background-task-be-used-as-a-prelaunchtask-in-launchjson
"isBackground": true,
// change this to your `beforeDevCommand`:
"command": "pnpm",
"args": ["dev"]
},
{
"label": "ui:build",
"type": "shell",
// change this to your `beforeBuildCommand`:
"command": "pnpm",
"args": ["build"]
}
]
}
(参考)
拡張機能のCodeLLDBをインストールして有効化します。
CodeLLDBはRustやC++のデバッグをサポートする拡張機能です。
ここまででステップ実行する設定は完了です。
動作確認
設定がうまくいっているか確認します。
main.rsの適当な箇所にブレイクポイントを設定します。
実行とデバッグ > "Tauri Development Debug"を実行します(もしくは、fnキー + F5)
実行すると、ブレイクポイントで処理が止まるはずです。
もし、再度、処理を実行したい場合は通常のステップ実行と同様に、再起動(Shift + command + F5)で動きます。
Discussion