This document will describe how to setup and configure VSCode for IDE debugging with Zig.
This document was accurate as of Zig 0.13.0
It is assumed that you already have Zig installed.
Install VSCode (https://code.visualstudio.com/docs/setup/linux)
Install the lldb debugger. This should be available via your package manager, ex. sudo apt-get install lldb on Debian/Ubuntu based systems.
- Open VSCode
- Open the Extensions page either by clicking on the left panel icon or the menu View|Extensions
- Install the Zig Language extnesion. This may ask you if you want to install the Zig Language Server. Answer 'Y'.
- Create a Zig test project (a workspace with zig init)
- Make sure that the project builds.
- Create a .vscode folder in the root folder of your project. IOW it should be a peer to src.
- Copy the following 2 files into .vscode:
launch.json
NOTE: Change first_proj in the following to the name of your workspace.
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "lldb",
"request": "launch",
"program": "${workspaceFolder}/zig-out/bin/first_proj",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"internalConsoleOptions": "openOnSessionStart",
"MIMode": "lldb",
"preLaunchTask": "build",
}
]
}
tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "zig build",
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
- Open your project in VSCode and navigate to src/main.zig
- Set a breakdpoint on one of the lines in the file.
- Now try to debug with the menu item Run|Start Debugging.