前言
由于最近開發(fā)上使用了Bazel來構(gòu)建,而且是用vscode進(jìn)行遠(yuǎn)程后臺(tái)開發(fā),使用Remote Development插件,以前大多都是CLion開發(fā)C++,對(duì)vscode還是不太熟悉,這里簡單記錄下vscode的相關(guān)配置
vscode 編譯流程
在工程目錄下有個(gè).vscode 文件夾,里面是所有 vscode 的配置文件,編譯運(yùn)行配置也在這里,涉及的配置文件有 launch.json和 tasks.json,不存在的話就自己創(chuàng)建即可
大致執(zhí)行流程是這樣的:
- vscode 會(huì)先遍歷 launch.json,找到configurations,也就是入口啟動(dòng)配置
- 在configurations里會(huì)先找preLaunchTask,也就是啟動(dòng)前的任務(wù)
- 拿到configurations.preLaunchTask去 tasks.json 里找對(duì)應(yīng)的具體任務(wù)
- tasks.json 里有個(gè)tasks列表,里面是多個(gè) task任務(wù),task名字是 label 字段,也就是和configurations.preLaunchTask對(duì)應(yīng)
- 找到 task 后先執(zhí)行configurations.preLaunchTask,然后執(zhí)行configurations.program
具體配置
搞清楚大致流程后,就可以參照樣例寫自己的配置文件了
我這里是測(cè)試邏輯,編譯后的執(zhí)行文件在${workspaceFolder}/bazel-bin/server/TestServer,可以根據(jù)自己實(shí)際情況修改
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": [
{
"name": "Debug",
"preLaunchTask": "BuildDebug",
"type": "cppdbg",
"MIMode": "gdb",
"request": "launch",
"program": "${workspaceFolder}/bazel-bin/server/TestServer",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
}
]
}
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "BuildDebug",
"type": "shell",
"command": "echo ${workspaceFolder} && bazel build //server:TestServer -c dbg",
"options": {
"cwd": "${workspaceFolder}"
},
"group": {
"kind": "build",
"isDefault": true
}
}
]
}